Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

PCI: Push realloc check into pbus_size_mem()

pbus_size_mem() and calculate_memsize() input both min_size and add_size.
They are given the same value if realloc_head is NULL and min_size is 0
otherwise. Both are used in calculate_memsize() to enforce a lower bound to
the size.

The interface between __pci_bus_size_bridges() and the forementioned
functions can be simplied by pushing the realloc check into
pbus_size_mem().

There are only two possible cases:

1) when calculating size0, add_size parameter given to
calculate_memsize() is always 0 which implies only min_size
matters.

2) when calculating size1, realloc_head is not NULL which implies
min_size=0 so only add_size matters.

Drop min_size parameter from pbus_size_mem() and check realloc_head when
calling calculate_memsize(). Drop add_size from calculate_memsize() and use
only min_size within max() to enforce the lower bound.

calculate_iosize() is a bit more complicated than calculate_memsize() and
is therefore left as is, but pbus_size_io() can still input only min_size
similar to pbus_size_mem().

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-7-ilpo.jarvinen@linux.intel.com

authored by

Ilpo Järvinen and committed by
Bjorn Helgaas
d0c72d6e f909e3ee

+12 -22
+12 -22
drivers/pci/setup-bus.c
··· 1069 1069 1070 1070 static resource_size_t calculate_memsize(resource_size_t size, 1071 1071 resource_size_t min_size, 1072 - resource_size_t add_size, 1073 1072 resource_size_t children_add_size, 1074 1073 resource_size_t align) 1075 1074 { 1076 - if (size < min_size) 1077 - size = min_size; 1078 - 1079 - size = max(size, add_size) + children_add_size; 1075 + size = max(size, min_size) + children_add_size; 1080 1076 return ALIGN(size, align); 1081 1077 } 1082 1078 ··· 1111 1115 * pbus_size_io() - Size the I/O window of a given bus 1112 1116 * 1113 1117 * @bus: The bus 1114 - * @min_size: The minimum I/O window that must be allocated 1115 - * @add_size: Additional optional I/O window 1118 + * @add_size: Additional I/O window 1116 1119 * @realloc_head: Track the additional I/O window on this list 1117 1120 * 1118 1121 * Sizing the I/O windows of the PCI-PCI bridge is trivial, since these ··· 1119 1124 * devices are limited to 256 bytes. We must be careful with the ISA 1120 1125 * aliasing though. 1121 1126 */ 1122 - static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size, 1123 - resource_size_t add_size, 1127 + static void pbus_size_io(struct pci_bus *bus, resource_size_t add_size, 1124 1128 struct list_head *realloc_head) 1125 1129 { 1126 1130 struct pci_dev *dev; ··· 1164 1170 } 1165 1171 } 1166 1172 1167 - size0 = calculate_iosize(size, min_size, size1, 0, 0, 1173 + size0 = calculate_iosize(size, realloc_head ? 0 : add_size, size1, 0, 0, 1168 1174 resource_size(b_res), min_align); 1169 1175 1170 1176 if (size0) ··· 1172 1178 1173 1179 size1 = size0; 1174 1180 if (realloc_head && (add_size > 0 || children_add_size > 0)) { 1175 - size1 = calculate_iosize(size, min_size, size1, add_size, 1181 + size1 = calculate_iosize(size, 0, size1, add_size, 1176 1182 children_add_size, resource_size(b_res), 1177 1183 min_align); 1178 1184 } ··· 1263 1269 * 1264 1270 * @bus: The bus 1265 1271 * @type: The type of bridge resource 1266 - * @min_size: The minimum memory window that must be allocated 1267 - * @add_size: Additional optional memory window 1272 + * @add_size: Additional memory window 1268 1273 * @realloc_head: Track the additional memory window on this list 1269 1274 * 1270 1275 * Calculate the size of the bus resource for @type and minimal alignment ··· 1276 1283 * supplied. 1277 1284 */ 1278 1285 static void pbus_size_mem(struct pci_bus *bus, unsigned long type, 1279 - resource_size_t min_size, 1280 1286 resource_size_t add_size, 1281 1287 struct list_head *realloc_head) 1282 1288 { ··· 1355 1363 win_align = window_alignment(bus, b_res->flags); 1356 1364 min_align = calculate_head_align(aligns, max_order); 1357 1365 min_align = max(min_align, win_align); 1358 - size0 = calculate_memsize(size, min_size, 0, 0, win_align); 1366 + size0 = calculate_memsize(size, realloc_head ? 0 : add_size, 1367 + 0, win_align); 1359 1368 1360 1369 if (size0) { 1361 1370 resource_set_range(b_res, min_align, size0); ··· 1365 1372 1366 1373 if (realloc_head && (add_size > 0 || children_add_size > 0)) { 1367 1374 add_align = max(min_align, add_align); 1368 - size1 = calculate_memsize(size, min_size, add_size, children_add_size, 1375 + size1 = calculate_memsize(size, add_size, children_add_size, 1369 1376 win_align); 1370 1377 } 1371 1378 ··· 1543 1550 } 1544 1551 fallthrough; 1545 1552 default: 1546 - pbus_size_io(bus, realloc_head ? 0 : additional_io_size, 1547 - additional_io_size, realloc_head); 1553 + pbus_size_io(bus, additional_io_size, realloc_head); 1548 1554 1549 1555 if (pref && (pref->flags & IORESOURCE_PREFETCH)) { 1550 1556 pbus_size_mem(bus, 1551 1557 IORESOURCE_MEM | IORESOURCE_PREFETCH | 1552 1558 (pref->flags & IORESOURCE_MEM_64), 1553 - realloc_head ? 0 : additional_mmio_pref_size, 1554 1559 additional_mmio_pref_size, realloc_head); 1555 1560 } 1556 1561 1557 - pbus_size_mem(bus, IORESOURCE_MEM, 1558 - realloc_head ? 0 : additional_mmio_size, 1559 - additional_mmio_size, realloc_head); 1562 + pbus_size_mem(bus, IORESOURCE_MEM, additional_mmio_size, 1563 + realloc_head); 1560 1564 break; 1561 1565 } 1562 1566 }