PCI: Refactor pdev_sort_resources() & __dev_sort_resources()
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Mon, 16 Dec 2024 17:56:20 +0000 (19:56 +0200)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 18 Feb 2025 21:40:53 +0000 (15:40 -0600)
Reduce level of call nesting by calling pdev_sort_resources() directly
and by moving the tests done inside __dev_sort_resources() into
pdev_resources_assignable() helper.

Link: https://lore.kernel.org/r/20241216175632.4175-14-ilpo.jarvinen@linux.intel.com
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Tested-by: Xiaochun Lee <lixc17@lenovo.com>
drivers/pci/setup-bus.c

index 8fda0354e54387221819ed5bd7a63ca41c320c03..21ed6084abc91507cbfb71234b17e5ae5861f591 100644 (file)
@@ -127,12 +127,33 @@ static resource_size_t get_res_add_align(struct list_head *head,
        return dev_res ? dev_res->min_align : 0;
 }
 
+static bool pdev_resources_assignable(struct pci_dev *dev)
+{
+       u16 class = dev->class >> 8, command;
+
+       /* Don't touch classless devices or host bridges or IOAPICs */
+       if (class == PCI_CLASS_NOT_DEFINED || class == PCI_CLASS_BRIDGE_HOST)
+               return false;
+
+       /* Don't touch IOAPIC devices already enabled by firmware */
+       if (class == PCI_CLASS_SYSTEM_PIC) {
+               pci_read_config_word(dev, PCI_COMMAND, &command);
+               if (command & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY))
+                       return false;
+       }
+
+       return true;
+}
+
 /* Sort resources by alignment */
 static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head)
 {
        struct resource *r;
        int i;
 
+       if (!pdev_resources_assignable(dev))
+               return;
+
        pci_dev_for_each_resource(dev, r, i) {
                const char *r_name = pci_resource_name(dev, i);
                struct pci_dev_resource *dev_res, *tmp;
@@ -176,25 +197,6 @@ static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head)
        }
 }
 
-static void __dev_sort_resources(struct pci_dev *dev, struct list_head *head)
-{
-       u16 class = dev->class >> 8;
-
-       /* Don't touch classless devices or host bridges or IOAPICs */
-       if (class == PCI_CLASS_NOT_DEFINED || class == PCI_CLASS_BRIDGE_HOST)
-               return;
-
-       /* Don't touch IOAPIC devices already enabled by firmware */
-       if (class == PCI_CLASS_SYSTEM_PIC) {
-               u16 command;
-               pci_read_config_word(dev, PCI_COMMAND, &command);
-               if (command & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY))
-                       return;
-       }
-
-       pdev_sort_resources(dev, head);
-}
-
 static inline void reset_resource(struct resource *res)
 {
        res->start = 0;
@@ -498,7 +500,7 @@ static void pdev_assign_resources_sorted(struct pci_dev *dev,
 {
        LIST_HEAD(head);
 
-       __dev_sort_resources(dev, &head);
+       pdev_sort_resources(dev, &head);
        __assign_resources_sorted(&head, add_head, fail_head);
 
 }
@@ -511,7 +513,7 @@ static void pbus_assign_resources_sorted(const struct pci_bus *bus,
        LIST_HEAD(head);
 
        list_for_each_entry(dev, &bus->devices, bus_list)
-               __dev_sort_resources(dev, &head);
+               pdev_sort_resources(dev, &head);
 
        __assign_resources_sorted(&head, realloc_head, fail_head);
 }