Skip to content

Commit c00f632

Browse files
ij-intelgregkh
authored andcommitted
PCI: Simplify size1 assignment logic
[ Upstream commit a55bf64 ] 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> Stable-dep-of: 67f9085 ("PCI: Allow relaxed bridge window tail sizing for optional resources") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 6a9bed7 commit c00f632

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

drivers/pci/setup-bus.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -927,9 +927,14 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
927927

928928
size0 = calculate_iosize(size, min_size, size1, 0, 0,
929929
resource_size(b_res), min_align);
930-
size1 = (!realloc_head || (realloc_head && !add_size && !children_add_size)) ? size0 :
931-
calculate_iosize(size, min_size, size1, add_size, children_add_size,
932-
resource_size(b_res), min_align);
930+
931+
size1 = size0;
932+
if (realloc_head && (add_size > 0 || children_add_size > 0)) {
933+
size1 = calculate_iosize(size, min_size, size1, add_size,
934+
children_add_size, resource_size(b_res),
935+
min_align);
936+
}
937+
933938
if (!size0 && !size1) {
934939
if (bus->self && (b_res->start || b_res->end))
935940
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,
10581063
struct list_head *realloc_head)
10591064
{
10601065
struct pci_dev *dev;
1061-
resource_size_t min_align, win_align, align, size, size0, size1;
1066+
resource_size_t min_align, win_align, align, size, size0, size1 = 0;
10621067
resource_size_t aligns[24]; /* Alignments from 1MB to 8TB */
10631068
int order, max_order;
10641069
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,
11531158
b_res, &bus->busn_res);
11541159
}
11551160

1156-
size1 = (!realloc_head || (realloc_head && !add_size && !children_add_size)) ? size0 :
1157-
calculate_memsize(size, min_size, add_size, children_add_size,
1158-
resource_size(b_res), add_align);
1161+
if (realloc_head && (add_size > 0 || children_add_size > 0)) {
1162+
size1 = calculate_memsize(size, min_size, add_size, children_add_size,
1163+
resource_size(b_res), add_align);
1164+
}
1165+
11591166
if (!size0 && !size1) {
11601167
if (bus->self && (b_res->start || b_res->end))
11611168
pci_info(bus->self, "disabling bridge window %pR to %pR (unused)\n",

0 commit comments

Comments
 (0)