From: Simon Glass Date: Fri, 31 Jul 2015 15:31:19 +0000 (-0600) Subject: dm: core: Check for empty list in uclass_find_device() X-Git-Url: http://git.dujemihanovic.xyz/?a=commitdiff_plain;h=2fda14ae6aa36798b59ab0591a2009ead206159b;p=u-boot.git 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 Reviewed-by: Bin Meng --- diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index aba98801fd..ffe69956d5 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -153,6 +153,8 @@ int uclass_find_device(enum uclass_id id, int index, struct udevice **devp) 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--) {