]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: device: fail uclass_find_first_device() if list_empty
authorMarcel Ziswiler <marcel.ziswiler@toradex.com>
Fri, 1 Feb 2019 15:01:07 +0000 (16:01 +0100)
committerTom Rini <trini@konsulko.com>
Sat, 9 Feb 2019 12:51:00 +0000 (07:51 -0500)
While uclass_find_device() fails with -ENODEV in case of list_empty
strangely uclass_find_first_device() returns 0.

Fix uclass_find_first_device() to also fail with -ENODEV instead.

Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/core/uclass.c
test/dm/core.c

index a622f079410c73059a2e4e4d28af1cac4c6f7523..fc3157de39c16ab5b7f5f584ef7e349410443739 100644 (file)
@@ -225,7 +225,7 @@ int uclass_find_first_device(enum uclass_id id, struct udevice **devp)
        if (ret)
                return ret;
        if (list_empty(&uc->dev_head))
-               return 0;
+               return -ENODEV;
 
        *devp = list_first_entry(&uc->dev_head, struct udevice, uclass_node);
 
index 260f6494a2ecc606335bc2d60c481259a3b275f5..edd55b05d6e293ebe9856b0e7da3d894a778fe79 100644 (file)
@@ -749,6 +749,10 @@ static int dm_test_uclass_devices_find(struct unit_test_state *uts)
                ut_assert(dev);
        }
 
+       ret = uclass_find_first_device(UCLASS_TEST_DUMMY, &dev);
+       ut_assert(ret == -ENODEV);
+       ut_assert(!dev);
+
        return 0;
 }
 DM_TEST(dm_test_uclass_devices_find, DM_TESTF_SCAN_PDATA);