diff mbox series

[U-Boot,v2,1/2] dm: device: fail uclass_find_first_device() if list_empty

Message ID 20190125124049.15227-2-marcel@ziswiler.com
State Superseded
Delegated to: Tom Rini
Headers show
Series While converting SATA on Apalis iMX6 to use driver model I noticed it | expand

Commit Message

Marcel Ziswiler Jan. 25, 2019, 12:40 p.m. UTC
From: Marcel Ziswiler <marcel.ziswiler@toradex.com>

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>

---

Changes in v2:
- Update dm_test_uclass_devices_find() to test this behaviour as
  suggested by Simon.

 drivers/core/uclass.c | 2 +-
 test/dm/core.c        | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

Comments

Simon Glass Jan. 31, 2019, 10:04 a.m. UTC | #1
On Fri, 25 Jan 2019 at 05:40, Marcel Ziswiler <marcel@ziswiler.com> wrote:
>
> From: Marcel Ziswiler <marcel.ziswiler@toradex.com>
>
> 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>
>
> ---
>
> Changes in v2:
> - Update dm_test_uclass_devices_find() to test this behaviour as
>   suggested by Simon.
>
>  drivers/core/uclass.c | 2 +-
>  test/dm/core.c        | 4 ++++
>  2 files changed, 5 insertions(+), 1 deletion(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox series

Patch

diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index a622f07941..fc3157de39 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -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);
 
diff --git a/test/dm/core.c b/test/dm/core.c
index 260f6494a2..edd55b05d6 100644
--- a/test/dm/core.c
+++ b/test/dm/core.c
@@ -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);