]> git.kernelconcepts.de Git - karo-tx-uboot.git/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)
committerLothar Waßmann <LW@KARO-electronics.de>
Thu, 10 Sep 2015 06:00:51 +0000 (08:00 +0200)
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--) {