PCI: Use PCI_SRIOV_NUM_BARS in loops instead of PCI_IOV_RESOURCE_END
authorDenis Efremov <efremov@linux.com>
Tue, 6 Aug 2019 14:07:15 +0000 (17:07 +0300)
committerBjorn Helgaas <bhelgaas@google.com>
Thu, 8 Aug 2019 20:12:12 +0000 (15:12 -0500)
Writing loop conditions as "i < NUM" is a common C idiom; using "i <= END"
is unusual and thus prone to errors.  Change loops to use the former.

Link: https://lore.kernel.org/r/20190806140715.19847-1-efremov@linux.com
Signed-off-by: Denis Efremov <efremov@linux.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
drivers/pci/iov.c
drivers/pci/setup-bus.c

index 525fd3f272b3c1f35dbd1f0c2d380a734cca2e37..9b48818ced0178cd37c4e728e5034a5fa9ef3a63 100644 (file)
@@ -557,8 +557,8 @@ static void sriov_restore_state(struct pci_dev *dev)
        ctrl |= iov->ctrl & PCI_SRIOV_CTRL_ARI;
        pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, ctrl);
 
-       for (i = PCI_IOV_RESOURCES; i <= PCI_IOV_RESOURCE_END; i++)
-               pci_update_resource(dev, i);
+       for (i = 0; i < PCI_SRIOV_NUM_BARS; i++)
+               pci_update_resource(dev, i + PCI_IOV_RESOURCES);
 
        pci_write_config_dword(dev, iov->pos + PCI_SRIOV_SYS_PGSIZE, iov->pgsz);
        pci_iov_set_numvfs(dev, iov->num_VFs);
index 79b1fa6519be7bc831d53a8c1e2c7c597fbb76e1..e7dbe21705ba5b0f9c906287656bd2c03f4ece5d 100644 (file)
@@ -1662,8 +1662,8 @@ static int iov_resources_unassigned(struct pci_dev *dev, void *data)
        int i;
        bool *unassigned = data;
 
-       for (i = PCI_IOV_RESOURCES; i <= PCI_IOV_RESOURCE_END; i++) {
-               struct resource *r = &dev->resource[i];
+       for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
+               struct resource *r = &dev->resource[i + PCI_IOV_RESOURCES];
                struct pci_bus_region region;
 
                /* Not assigned or rejected by kernel? */