diff mbox series

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

Message ID 20190124142957.15040-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. 24, 2019, 2:29 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>

---

 drivers/core/uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Simon Glass Jan. 24, 2019, 8:18 p.m. UTC | #1
Hi Marcel,

On Fri, 25 Jan 2019 at 03:30, 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.

The fix sees OK to me. I assume that 'make qcheck' still passes.

But can you please update dm_test_uclass_devices_find() to test this behaviour?

>
> Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
>
> ---
>
>  drivers/core/uclass.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> 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);
>
> --
> 2.20.1
>

Regards,
Simon
Marcel Ziswiler Jan. 25, 2019, 11:23 a.m. UTC | #2
Hi Simon

On Fri, 2019-01-25 at 09:18 +1300, Simon Glass wrote:
> Hi Marcel,
> 
> On Fri, 25 Jan 2019 at 03:30, 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.
> 
> The fix sees OK to me. I assume that 'make qcheck' still passes.

Yes, certainly.

This means it did not check for this so far.

> But can you please update dm_test_uclass_devices_find() to test this
> behaviour?

OK, will do so for v2.

> > Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
> > 
> > ---
> > 
> >  drivers/core/uclass.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > 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);
> > 
> > --
> > 2.20.1
> > 
> 
> Regards,
> Simon

Cheers

Marcel
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);