]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
PCI: Fetch dev_res to local var in __assign_resources_sorted()
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Fri, 19 Dec 2025 17:40:22 +0000 (19:40 +0200)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 27 Jan 2026 22:36:51 +0000 (16:36 -0600)
__assign_resources_sorted() calls get_res_add_size() and
get_res_add_align(), each walking through the realloc_head list to
relocate the corresponding pci_dev_resource entry.

Fetch the pci_dev_resource entry into a local variable to avoid double
walk.

In addition, reverse logic to reduce indentation level.

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Link: https://patch.msgid.link/20251219174036.16738-10-ilpo.jarvinen@linux.intel.com
drivers/pci/setup-bus.c

index 09cc225bf107edcd19618901acf8b2f0c6e2bff4..41417084ddf844566abffe6217fb0c3dc40ecda6 100644 (file)
@@ -596,11 +596,11 @@ static void __assign_resources_sorted(struct list_head *head,
        LIST_HEAD(local_fail_head);
        LIST_HEAD(dummy_head);
        struct pci_dev_resource *save_res;
-       struct pci_dev_resource *dev_res, *tmp_res, *dev_res2;
+       struct pci_dev_resource *dev_res, *tmp_res, *dev_res2, *addsize_res;
        struct resource *res;
        struct pci_dev *dev;
        unsigned long fail_type;
-       resource_size_t add_align, align;
+       resource_size_t align;
 
        if (!realloc_head)
                realloc_head = &dummy_head;
@@ -621,8 +621,11 @@ static void __assign_resources_sorted(struct list_head *head,
        list_for_each_entry_safe(dev_res, tmp_res, head, list) {
                res = dev_res->res;
 
-               res->end += get_res_add_size(realloc_head, res);
+               addsize_res = res_to_dev_res(realloc_head, res);
+               if (!addsize_res)
+                       continue;
 
+               res->end += addsize_res->add_size;
                /*
                 * There are two kinds of additional resources in the list:
                 * 1. bridge resource  -- IORESOURCE_STARTALIGN
@@ -632,8 +635,8 @@ static void __assign_resources_sorted(struct list_head *head,
                if (!(res->flags & IORESOURCE_STARTALIGN))
                        continue;
 
-               add_align = get_res_add_align(realloc_head, res);
-
+               if (addsize_res->min_align <= res->start)
+                       continue;
                /*
                 * The "head" list is sorted by alignment so resources with
                 * bigger alignment will be assigned first.  After we
@@ -641,17 +644,15 @@ static void __assign_resources_sorted(struct list_head *head,
                 * need to reorder the list by alignment to make it
                 * consistent.
                 */
-               if (add_align > res->start) {
-                       resource_set_range(res, add_align, resource_size(res));
-
-                       list_for_each_entry(dev_res2, head, list) {
-                               align = pci_resource_alignment(dev_res2->dev,
-                                                              dev_res2->res);
-                               if (add_align > align) {
-                                       list_move_tail(&dev_res->list,
-                                                      &dev_res2->list);
-                                       break;
-                               }
+               resource_set_range(res, addsize_res->min_align,
+                                  resource_size(res));
+
+               list_for_each_entry(dev_res2, head, list) {
+                       align = pci_resource_alignment(dev_res2->dev,
+                                                      dev_res2->res);
+                       if (addsize_res->min_align > align) {
+                               list_move_tail(&dev_res->list, &dev_res2->list);
+                               break;
                        }
                }