Skip to contentSkip to conversation

PCI/PME: replace usage of found with dedicated list iterator variable

PATCH New Jakob Koschel 1 participant 1 message Mar 24, 2022 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI/PME: replace usage of found with dedicated list iterator variable

To move the list iterator variable into the list_for_each_entry_*() macro in the future it should be avoided to use the list iterator variable after the loop body.

To *never* use the list iterator variable after the loop it was concluded to use a separate iterator variable instead of a found boolean [1].

This removes the need to use a found variable and simply checking if the variable was set, can determine if the break/goto was hit.

---
 drivers/pci/pcie/pme.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/pci/pcie/pme.c +7 -7
index ef8ce436ead9..dc8cbf8987ba 100644
@@ -130,7 +130,7 @@ static void pcie_pme_handle_request(struct pci_dev *port, u16 req_id)
 {
 	u8 busnr = req_id >> 8, devfn = req_id & 0xff;
 	struct pci_bus *bus;
-	struct pci_dev *dev;
+	struct pci_dev *dev = NULL, *iter;
 	bool found = false;
 
 	/* First, check if the PME is from the root port itself. */
@@ -169,17 +169,17 @@ static void pcie_pme_handle_request(struct pci_dev *port, u16 req_id)
 
 	/* Finally, try to find the PME source on the bus. */
 	down_read(&pci_bus_sem);
-	list_for_each_entry(dev, &bus->devices, bus_list) {
-		pci_dev_get(dev);
-		if (dev->devfn == devfn) {
-			found = true;
+	list_for_each_entry(iter, &bus->devices, bus_list) {
+		pci_dev_get(iter);
+		if (iter->devfn == devfn) {
+			dev = iter;
 			break;
 		}
-		pci_dev_put(dev);
+		pci_dev_put(iter);
 	}
 	up_read(&pci_bus_sem);
 
-	if (found) {
+	if (dev) {
 		/* The device is there, but we have to check its PME status. */
 		found = pci_check_pme_status(dev);
 		if (found) {

base-commit: f443e374ae131c168a065ea1748feac6b2e76613

Signature · 1 line
2.25.1