]> git.sur5r.net Git - u-boot/commitdiff
dm: core: Check for empty list in uclass_find_device()
authorSimon Glass <sjg@chromium.org>
Fri, 31 Jul 2015 15:31:19 +0000 (09:31 -0600)
committerSimon Glass <sjg@chromium.org>
Wed, 5 Aug 2015 14:42:40 +0000 (08:42 -0600)
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>
drivers/core/uclass.c

index aba98801fd4505b269f3aecf6ac454c3f21bff86..ffe69956d591c058e3a4410f5a1bbee71a63eec0 100644 (file)
@@ -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--) {