Skip to content

Commit af6e3de

Browse files
ij-intelbjorn-helgaas
authored andcommitted
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 <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Link: https://lore.kernel.org/linux-pci/[email protected] Link: https://lore.kernel.org/r/[email protected]
1 parent 1c8a0ed commit af6e3de

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
@@ -2298,8 +2298,8 @@ void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus)
22982298

22992299
/* Depth last, allocate resources and update the hardware. */
23002300
__pci_bus_assign_resources(bus, add_list, &fail_head);
2301-
if (add_list)
2302-
BUG_ON(!list_empty(add_list));
2301+
if (WARN_ON_ONCE(add_list && !list_empty(add_list)))
2302+
free_list(add_list);
23032303
tried_times++;
23042304

23052305
/* Any device complain? */
@@ -2361,7 +2361,8 @@ void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
23612361
pci_bridge_distribute_available_resources(bridge, &add_list);
23622362

23632363
__pci_bridge_assign_resources(bridge, &add_list, &fail_head);
2364-
BUG_ON(!list_empty(&add_list));
2364+
if (WARN_ON_ONCE(!list_empty(&add_list)))
2365+
free_list(&add_list);
23652366
tried_times++;
23662367

23672368
if (list_empty(&fail_head))
@@ -2437,7 +2438,8 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
24372438

24382439
__pci_bus_size_bridges(bridge->subordinate, &added);
24392440
__pci_bridge_assign_resources(bridge, &added, &failed);
2440-
BUG_ON(!list_empty(&added));
2441+
if (WARN_ON_ONCE(!list_empty(&added)))
2442+
free_list(&added);
24412443

24422444
if (!list_empty(&failed)) {
24432445
ret = -ENOSPC;
@@ -2493,6 +2495,7 @@ void pci_assign_unassigned_bus_resources(struct pci_bus *bus)
24932495
__pci_bus_size_bridges(dev->subordinate, &add_list);
24942496
up_read(&pci_bus_sem);
24952497
__pci_bus_assign_resources(bus, &add_list, NULL);
2496-
BUG_ON(!list_empty(&add_list));
2498+
if (WARN_ON_ONCE(!list_empty(&add_list)))
2499+
free_list(&add_list);
24972500
}
24982501
EXPORT_SYMBOL_GPL(pci_assign_unassigned_bus_resources);

0 commit comments

Comments
 (0)