]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
PCI: Add for_each_pci_bridge() helper
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Fri, 20 Oct 2017 20:38:54 +0000 (15:38 -0500)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 7 Nov 2017 00:48:58 +0000 (18:48 -0600)
The following pattern is often used:

  list_for_each_entry(dev, &bus->devices, bus_list) {
    if (pci_is_bridge(dev)) {
      ...
    }
  }

Add a for_each_pci_bridge() helper to make that code easier to write and
read by reducing indentation level.  It also saves one or few lines of code
in each occurrence.

Convert PCI core parts here at the same time.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
[bhelgaas: fold in http://lkml.kernel.org/r/20171013165352.25550-1-andriy.shevchenko@linux.intel.com]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/hotplug/acpiphp_glue.c
drivers/pci/hotplug/cpci_hotplug_pci.c
drivers/pci/hotplug/pciehp_pci.c
drivers/pci/hotplug/shpchp_pci.c
drivers/pci/probe.c
drivers/pci/setup-bus.c
drivers/pcmcia/cardbus.c
include/linux/pci.h

index 5ed2dcaa8e27c0ebe0729c3f543a58261c86a651..5db6f1839dada041d5affbfedef46312360488e3 100644 (file)
@@ -462,18 +462,15 @@ static void enable_slot(struct acpiphp_slot *slot)
        acpiphp_rescan_slot(slot);
        max = acpiphp_max_busnr(bus);
        for (pass = 0; pass < 2; pass++) {
-               list_for_each_entry(dev, &bus->devices, bus_list) {
+               for_each_pci_bridge(dev, bus) {
                        if (PCI_SLOT(dev->devfn) != slot->device)
                                continue;
 
-                       if (pci_is_bridge(dev)) {
-                               max = pci_scan_bridge(bus, dev, max, pass);
-                               if (pass && dev->subordinate) {
-                                       check_hotplug_bridge(slot, dev);
-                                       pcibios_resource_survey_bus(dev->subordinate);
-                                       __pci_bus_size_bridges(dev->subordinate,
-                                                              &add_list);
-                               }
+                       max = pci_scan_bridge(bus, dev, max, pass);
+                       if (pass && dev->subordinate) {
+                               check_hotplug_bridge(slot, dev);
+                               pcibios_resource_survey_bus(dev->subordinate);
+                               __pci_bus_size_bridges(dev->subordinate, &add_list);
                        }
                }
        }
index 80c80017197daa8d2b128faf063b48d93eb05da0..f616358fa9382cc49eb7b515ebc5c29d224a2e8c 100644 (file)
@@ -286,14 +286,11 @@ int cpci_configure_slot(struct slot *slot)
        }
        parent = slot->dev->bus;
 
-       list_for_each_entry(dev, &parent->devices, bus_list) {
-               if (PCI_SLOT(dev->devfn) != PCI_SLOT(slot->devfn))
-                       continue;
-               if (pci_is_bridge(dev))
+       for_each_pci_bridge(dev, parent) {
+               if (PCI_SLOT(dev->devfn) == PCI_SLOT(slot->devfn))
                        pci_hp_add_bridge(dev);
        }
 
-
        pci_assign_unassigned_bridge_resources(parent->self);
 
        pci_bus_add_devices(parent);
index 19f30a9f461d50b3ec12847b67ed2eea251f16f5..c3af027ee1a688aa903291ac8629b82fe71a70ef 100644 (file)
@@ -60,9 +60,8 @@ int pciehp_configure_device(struct slot *p_slot)
                goto out;
        }
 
-       list_for_each_entry(dev, &parent->devices, bus_list)
-               if (pci_is_bridge(dev))
-                       pci_hp_add_bridge(dev);
+       for_each_pci_bridge(dev, parent)
+               pci_hp_add_bridge(dev);
 
        pci_assign_unassigned_bridge_resources(bridge);
        pcie_bus_configure_settings(parent);
index f8cd3a27e3515e630639e86a8e58478517f5ec2a..ea63db58b4b136271ae1bed32ec5c668ccb40d69 100644 (file)
@@ -61,10 +61,8 @@ int shpchp_configure_device(struct slot *p_slot)
                goto out;
        }
 
-       list_for_each_entry(dev, &parent->devices, bus_list) {
-               if (PCI_SLOT(dev->devfn) != p_slot->device)
-                       continue;
-               if (pci_is_bridge(dev))
+       for_each_pci_bridge(dev, parent) {
+               if (PCI_SLOT(dev->devfn) == p_slot->device)
                        pci_hp_add_bridge(dev);
        }
 
index ff94b69738a87a8ec5b77e57624e1412c7ab4916..cdc2f83c11c5a0855a27bb0e7d44ca28d52626bc 100644 (file)
@@ -2421,10 +2421,8 @@ unsigned int pci_scan_child_bus(struct pci_bus *bus)
        }
 
        for (pass = 0; pass < 2; pass++)
-               list_for_each_entry(dev, &bus->devices, bus_list) {
-                       if (pci_is_bridge(dev))
-                               max = pci_scan_bridge(bus, dev, max, pass);
-               }
+               for_each_pci_bridge(dev, bus)
+                       max = pci_scan_bridge(bus, dev, max, pass);
 
        /*
         * Make sure a hotplug bridge has at least the minimum requested
index 958da7db90331c44315f95ab90553c586d918c46..7ca03407404cbed17ce89af1d804cc7d67cb9d80 100644 (file)
@@ -1921,10 +1921,9 @@ void pci_assign_unassigned_bus_resources(struct pci_bus *bus)
                                        want additional resources */
 
        down_read(&pci_bus_sem);
-       list_for_each_entry(dev, &bus->devices, bus_list)
-               if (pci_is_bridge(dev) && pci_has_subordinate(dev))
-                               __pci_bus_size_bridges(dev->subordinate,
-                                                        &add_list);
+       for_each_pci_bridge(dev, bus)
+               if (pci_has_subordinate(dev))
+                       __pci_bus_size_bridges(dev->subordinate, &add_list);
        up_read(&pci_bus_sem);
        __pci_bus_assign_resources(bus, &add_list, NULL);
        BUG_ON(!list_empty(&add_list));
index 4fe4cc4ae19a297a0d0553e48e613cd50bc6e891..5c0170597037e4e98a6e61b6bc06b91fc0c15145 100644 (file)
@@ -77,9 +77,8 @@ int __ref cb_alloc(struct pcmcia_socket *s)
 
        max = bus->busn_res.start;
        for (pass = 0; pass < 2; pass++)
-               list_for_each_entry(dev, &bus->devices, bus_list)
-                       if (pci_is_bridge(dev))
-                               max = pci_scan_bridge(bus, dev, max, pass);
+               for_each_pci_bridge(dev, bus)
+                       max = pci_scan_bridge(bus, dev, max, pass);
 
        /*
         * Size all resources below the CardBus controller.
index f4f8ee5a7362e982c0084d619c8ed1996a38f770..3dbe947b415244969a73328370a6b2c0bb43173a 100644 (file)
@@ -596,6 +596,10 @@ static inline bool pci_is_bridge(struct pci_dev *dev)
                dev->hdr_type == PCI_HEADER_TYPE_CARDBUS;
 }
 
+#define for_each_pci_bridge(dev, bus)                          \
+       list_for_each_entry(dev, &bus->devices, bus_list)       \
+               if (!pci_is_bridge(dev)) {} else
+
 static inline struct pci_dev *pci_upstream_bridge(struct pci_dev *dev)
 {
        dev = pci_physfn(dev);