PCI: Simplify size1 assignment logic
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Mon, 16 Dec 2024 17:56:10 +0000 (19:56 +0200)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 18 Feb 2025 21:40:52 +0000 (15:40 -0600)
In pbus_size_io() and pbus_size_mem(), a complex ?: operation is performed
to set size1.  Decompose this so it's easier to read.

In the case of pbus_size_mem(), simply initializing size1 to zero ensures
the size1 checks work as expected.

Link: https://lore.kernel.org/r/20241216175632.4175-4-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 326badd4192a020deb576d4042279b7e4a17ded2..fd78606526ec1f556640365932871ec0ecb4b618 100644 (file)
@@ -927,9 +927,14 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
 
        size0 = calculate_iosize(size, min_size, size1, 0, 0,
                        resource_size(b_res), min_align);
-       size1 = (!realloc_head || (realloc_head && !add_size && !children_add_size)) ? size0 :
-               calculate_iosize(size, min_size, size1, add_size, children_add_size,
-                       resource_size(b_res), min_align);
+
+       size1 = size0;
+       if (realloc_head && (add_size > 0 || children_add_size > 0)) {
+               size1 = calculate_iosize(size, min_size, size1, add_size,
+                                        children_add_size, resource_size(b_res),
+                                        min_align);
+       }
+
        if (!size0 && !size1) {
                if (bus->self && (b_res->start || b_res->end))
                        pci_info(bus->self, "disabling bridge window %pR to %pR (unused)\n",
@@ -1058,7 +1063,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
                         struct list_head *realloc_head)
 {
        struct pci_dev *dev;
-       resource_size_t min_align, win_align, align, size, size0, size1;
+       resource_size_t min_align, win_align, align, size, size0, size1 = 0;
        resource_size_t aligns[24]; /* Alignments from 1MB to 8TB */
        int order, max_order;
        struct resource *b_res = find_bus_resource_of_type(bus,
@@ -1153,9 +1158,11 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
                         b_res, &bus->busn_res);
        }
 
-       size1 = (!realloc_head || (realloc_head && !add_size && !children_add_size)) ? size0 :
-               calculate_memsize(size, min_size, add_size, children_add_size,
-                               resource_size(b_res), add_align);
+       if (realloc_head && (add_size > 0 || children_add_size > 0)) {
+               size1 = calculate_memsize(size, min_size, add_size, children_add_size,
+                                         resource_size(b_res), add_align);
+       }
+
        if (!size0 && !size1) {
                if (bus->self && (b_res->start || b_res->end))
                        pci_info(bus->self, "disabling bridge window %pR to %pR (unused)\n",