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>
ret = uclass_get(id, &uc);
if (ret)
return ret;
ret = uclass_get(id, &uc);
if (ret)
return ret;
+ if (list_empty(&uc->dev_head))
+ return -ENODEV;
list_for_each_entry(dev, &uc->dev_head, uclass_node) {
if (!index--) {
list_for_each_entry(dev, &uc->dev_head, uclass_node) {
if (!index--) {