mirror of
https://xff.cz/git/u-boot/
synced 2025-09-01 00:32:04 +02:00
pci: Avoid a crash in device_is_on_pci_bus()
This function cannot currently be called on the root node. Add a check for this as well as a test. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Wolfgang Wallner <wolfgang.wallner@br-automation.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
This commit is contained in:
@@ -764,7 +764,7 @@ int dev_enable_by_path(const char *path);
|
|||||||
*/
|
*/
|
||||||
static inline bool device_is_on_pci_bus(const struct udevice *dev)
|
static inline bool device_is_on_pci_bus(const struct udevice *dev)
|
||||||
{
|
{
|
||||||
return device_get_uclass_id(dev->parent) == UCLASS_PCI;
|
return dev->parent && device_get_uclass_id(dev->parent) == UCLASS_PCI;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -339,3 +339,17 @@ static int dm_test_pci_addr_live(struct unit_test_state *uts)
|
|||||||
}
|
}
|
||||||
DM_TEST(dm_test_pci_addr_live, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT |
|
DM_TEST(dm_test_pci_addr_live, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT |
|
||||||
DM_TESTF_LIVE_TREE);
|
DM_TESTF_LIVE_TREE);
|
||||||
|
|
||||||
|
/* Test device_is_on_pci_bus() */
|
||||||
|
static int dm_test_pci_on_bus(struct unit_test_state *uts)
|
||||||
|
{
|
||||||
|
struct udevice *dev;
|
||||||
|
|
||||||
|
ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x1f, 0), &dev));
|
||||||
|
ut_asserteq(true, device_is_on_pci_bus(dev));
|
||||||
|
ut_asserteq(false, device_is_on_pci_bus(dev_get_parent(dev)));
|
||||||
|
ut_asserteq(true, device_is_on_pci_bus(dev));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
DM_TEST(dm_test_pci_on_bus, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
|
||||||
|
Reference in New Issue
Block a user