Skip to content

Commit a154f14

Browse files
cyyselfbjorn-helgaas
authored andcommitted
PCI: Fix regression in pci_bus_distribute_available_resources()
The refactoring in 4292a1e ("PCI: Refactor distributing available memory to use loops") switched pci_bus_distribute_available_resources() to operate on an array of bridge windows. That accidentally looked up bus resources via pci_bus_resource_n() and then passed those pointers to helper routines that expect the resource to belong to the device. As soon as we execute that code, pci_resource_num() warned because the resource wasn't in the bridge's resource array. This happens on my AMD Strix Halo machine with Thunderbolt device; the error message is shown below: WARNING: CPU: 6 PID: 272 at drivers/pci/pci.h:471 pci_bus_distribute_available_resources+0x6ad/0x6d0 CPU: 6 UID: 0 PID: 272 Comm: irq/33-pciehp Not tainted 6.17.0+ #1 PREEMPT(voluntary) Hardware name: PELADN YO Series/YO1, BIOS 1.04 05/15/2025 RIP: 0010:pci_bus_distribute_available_resources+0x6ad/0x6d0 Call Trace: pci_bus_distribute_available_resources+0x590/0x6d0 pci_bridge_distribute_available_resources+0x62/0xb0 pci_assign_unassigned_bridge_resources+0x65/0x1b0 pciehp_configure_device+0x92/0x160 pciehp_handle_presence_or_link_change+0x1b5/0x350 pciehp_ist+0x147/0x1c0 Fix the regression by always fetching the resource directly from the bridge with pci_resource_n(bridge, PCI_BRIDGE_RESOURCES + i). This restores the original behaviour while keeping the refactored structure. Then we can successfully assign resources to the Thunderbolt device. Fixes: 4292a1e ("PCI: Refactor distributing available memory to use loops") Reported-by: Kenneth R. Crudup <kenny@panix.com> Closes: https://lore.kernel.org/r/dd551b81-9e81-480b-aab3-7cf8b8bbc1d0@panix.com Signed-off-by: Yangyu Chen <cyy@cyyself.name> [bhelgaas: trim timestamps, etc from commit log] Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Tested-By: Kenneth R. Crudup <kenny@panix.com> Link: https://lore.kernel.org/r/F833CC81-7C60-48FC-A31C-B9999DCC6FA2@icloud.com Link: https://patch.msgid.link/tencent_8C54420E1B0FF8D804C1B4651DF970716309@qq.com
1 parent 2f2c725 commit a154f14

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/pci/setup-bus.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,7 +2085,8 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus,
20852085
int i;
20862086

20872087
for (i = 0; i < PCI_P2P_BRIDGE_RESOURCE_NUM; i++) {
2088-
struct resource *res = pci_bus_resource_n(bus, i);
2088+
struct resource *res =
2089+
pci_resource_n(bridge, PCI_BRIDGE_RESOURCES + i);
20892090

20902091
available[i] = available_in[i];
20912092

@@ -2158,7 +2159,7 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus,
21582159
continue;
21592160

21602161
for (i = 0; i < PCI_P2P_BRIDGE_RESOURCE_NUM; i++) {
2161-
res = pci_bus_resource_n(bus, i);
2162+
res = pci_resource_n(dev, PCI_BRIDGE_RESOURCES + i);
21622163

21632164
/*
21642165
* Make sure the split resource space is properly

0 commit comments

Comments
 (0)