mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-19 05:31:32 +00:00
dm: core: Check for empty list in uclass_find_device()
This function needs to check the list has entries before traversing it. Fix this bug. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
This commit is contained in:
parent
3834f41720
commit
2fda14ae6a
1 changed files with 2 additions and 0 deletions
|
@ -153,6 +153,8 @@ int uclass_find_device(enum uclass_id id, int index, struct udevice **devp)
|
||||||
ret = uclass_get(id, &uc);
|
ret = uclass_get(id, &uc);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
if (list_empty(&uc->dev_head))
|
||||||
|
return -ENODEV;
|
||||||
|
|
||||||
list_for_each_entry(dev, &uc->dev_head, uclass_node) {
|
list_for_each_entry(dev, &uc->dev_head, uclass_node) {
|
||||||
if (!index--) {
|
if (!index--) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue