Skip to content

Commit afe8e65

Browse files
author
Myron Stowe
committed
PCI: WARN (not BUG()) when we fail to assign optional resources
JIRA: https://issues.redhat.com/browse/RHEL-107597 Upstream Status: af6e3de commit af6e3de Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Date: Mon May 12 00:52:23 2025 +0300 PCI: WARN (not BUG()) when we fail to assign optional resources Resource fitting/assignment code checks if there's a remainder in add_list (aka. realloc_head in the inner functions) using BUG_ON(). This problem typically results in a mere PCI device resource assignment failure which does not warrant using BUG_ON(). The machine could well come up usable even if this condition occurs because the realloc_head relates to resources which are optional anyway. Change BUG_ON() to WARN_ON_ONCE() and free the list if it's not empty. [bhelgaas: subject] Reported-by: Tudor Ambarus <tudor.ambarus@linaro.org> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Link: https://lore.kernel.org/linux-pci/5f103643-5e1c-43c6-b8fe-9617d3b5447c@linaro.org Link: https://lore.kernel.org/r/20250511215223.7131-1-ilpo.jarvinen@linux.intel.com Signed-off-by: Myron Stowe <mstowe@redhat.com>
1 parent aa762ff commit afe8e65

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

drivers/pci/setup-bus.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,8 +2302,8 @@ void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus)
23022302

23032303
/* Depth last, allocate resources and update the hardware. */
23042304
__pci_bus_assign_resources(bus, add_list, &fail_head);
2305-
if (add_list)
2306-
BUG_ON(!list_empty(add_list));
2305+
if (WARN_ON_ONCE(add_list && !list_empty(add_list)))
2306+
free_list(add_list);
23072307
tried_times++;
23082308

23092309
/* Any device complain? */
@@ -2365,7 +2365,8 @@ void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
23652365
pci_bridge_distribute_available_resources(bridge, &add_list);
23662366

23672367
__pci_bridge_assign_resources(bridge, &add_list, &fail_head);
2368-
BUG_ON(!list_empty(&add_list));
2368+
if (WARN_ON_ONCE(!list_empty(&add_list)))
2369+
free_list(&add_list);
23692370
tried_times++;
23702371

23712372
if (list_empty(&fail_head))
@@ -2441,7 +2442,8 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
24412442

24422443
__pci_bus_size_bridges(bridge->subordinate, &added);
24432444
__pci_bridge_assign_resources(bridge, &added, &failed);
2444-
BUG_ON(!list_empty(&added));
2445+
if (WARN_ON_ONCE(!list_empty(&added)))
2446+
free_list(&added);
24452447

24462448
if (!list_empty(&failed)) {
24472449
ret = -ENOSPC;
@@ -2497,6 +2499,7 @@ void pci_assign_unassigned_bus_resources(struct pci_bus *bus)
24972499
__pci_bus_size_bridges(dev->subordinate, &add_list);
24982500
up_read(&pci_bus_sem);
24992501
__pci_bus_assign_resources(bus, &add_list, NULL);
2500-
BUG_ON(!list_empty(&add_list));
2502+
if (WARN_ON_ONCE(!list_empty(&add_list)))
2503+
free_list(&add_list);
25012504
}
25022505
EXPORT_SYMBOL_GPL(pci_assign_unassigned_bus_resources);

0 commit comments

Comments
 (0)