Skip to contentSkip to conversation

PCI: use PCI_SRIOV_NUM_BARS in loops instead of PCI_IOV_RESOURCE_END

PATCH In review Denis Efremov 3 participants 3 messages Aug 6, 2019 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: use PCI_SRIOV_NUM_BARS in loops instead of PCI_IOV_RESOURCE_END

It's a general pattern to write loops with 'i < PCI_SRIOV_NUM_BARS' condition. This patch fixes remaining loops which violates this implicit agreement.

---
 drivers/pci/iov.c       | 4 ++--
 drivers/pci/setup-bus.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/pci/iov.c +2 -2
index 525fd3f272b3..9b48818ced01 100644
@@ -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);
drivers/pci/setup-bus.c +2 -2
index 79b1fa6519be..e7dbe21705ba 100644
@@ -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? */
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Denis Efremov

It's a general pattern to write loops with 'i < PCI_SRIOV_NUM_BARS' condition. This patch fixes remaining loops which violates this implicit agreement.

Looks good to me.

Quoted 37 lines
---
  drivers/pci/iov.c       | 4 ++--
  drivers/pci/setup-bus.c | 4 ++--
  2 files changed, 4 insertions(+), 4 deletions(-)
drivers/pci/iov.c +2 -2
index 525fd3f272b3..9b48818ced01 100644
@@ -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);
drivers/pci/setup-bus.c +2 -2
index 79b1fa6519be..e7dbe21705ba 100644
@@ -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? */
Signature · 2 lines
Sathyanarayanan Kuppuswamy
Linux kernel developer
#2 lore raw
In reply to Denis Efremov
Quoted 5 lines · Denis Efremov

It's a general pattern to write loops with 'i < PCI_SRIOV_NUM_BARS' condition. This patch fixes remaining loops which violates this implicit agreement.

Applied with Kuppuswamy's reviewed-by to pci/misc for v5.4, thanks!

Quoted 38 lines
---
 drivers/pci/iov.c       | 4 ++--
 drivers/pci/setup-bus.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/pci/iov.c +2 -2
index 525fd3f272b3..9b48818ced01 100644
@@ -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);
drivers/pci/setup-bus.c +2 -2
index 79b1fa6519be..e7dbe21705ba 100644
@@ -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? */
Signature · 1 line
2.21.0