diff mbox

[U-Boot,v2,1/3] usb: usb_new_device return codes consistency

Message ID 1427624899-9537-1-git-send-email-contact@paulk.fr
State Superseded
Delegated to: Marek Vasut
Headers show

Commit Message

Paul Kocialkowski March 29, 2015, 10:28 a.m. UTC
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
---
 common/usb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Łukasz Majewski March 30, 2015, 8:06 a.m. UTC | #1
Hi Paul,

> Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
> ---
>  common/usb.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/common/usb.c b/common/usb.c
> index 32e15cd..ea5b406 100644
> --- a/common/usb.c
> +++ b/common/usb.c
> @@ -915,7 +915,7 @@ int usb_new_device(struct usb_device *dev)
>  	if (err < 8) {
>  		printf("\n      USB device not responding, " \
>  		       "giving up (status=%lX)\n", dev->status);
> -		return 1;
> +		return -1;

If you are going to provide consistency with error codes, then I think
that it would be beneficial to return -Exxx codes (like -EINVAL, etc).

>  	}
>  	memcpy(&dev->descriptor, tmpbuf, 8);
>  #else
> @@ -952,7 +952,7 @@ int usb_new_device(struct usb_device *dev)
>  	err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, 64);
>  	if (err < 0) {
>  		debug("usb_new_device: usb_get_descriptor()
> failed\n");
> -		return 1;
> +		return -1;
>  	}
>  
>  	dev->descriptor.bMaxPacketSize0 = desc->bMaxPacketSize0;
> @@ -968,7 +968,7 @@ int usb_new_device(struct usb_device *dev)
>  		err = hub_port_reset(dev->parent, dev->portnr - 1,
> &portstatus); if (err < 0) {
>  			printf("\n     Couldn't reset port %i\n",
> dev->portnr);
> -			return 1;
> +			return -1;
>  		}
>  	} else {
>  		usb_reset_root_port();
> @@ -1014,7 +1014,7 @@ int usb_new_device(struct usb_device *dev)
>  		else
>  			printf("USB device descriptor short read " \
>  				"(expected %i, got %i)\n", tmp, err);
> -		return 1;
> +		return -1;
>  	}
>  	memcpy(&dev->descriptor, tmpbuf, sizeof(dev->descriptor));
>  	/* correct le values */
Paul Kocialkowski March 30, 2015, 1:36 p.m. UTC | #2
Le lundi 30 mars 2015 à 10:06 +0200, Lukasz Majewski a écrit :
> Hi Paul,
> 
> > Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
> > ---
> >  common/usb.c | 8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/common/usb.c b/common/usb.c
> > index 32e15cd..ea5b406 100644
> > --- a/common/usb.c
> > +++ b/common/usb.c
> > @@ -915,7 +915,7 @@ int usb_new_device(struct usb_device *dev)
> >  	if (err < 8) {
> >  		printf("\n      USB device not responding, " \
> >  		       "giving up (status=%lX)\n", dev->status);
> > -		return 1;
> > +		return -1;
> 
> If you are going to provide consistency with error codes, then I think
> that it would be beneficial to return -Exxx codes (like -EINVAL, etc).

That makes sense, I'll give it a try soon (I'm not sure I'll get all the
appropriate error codes right at first try though).

> >  	}
> >  	memcpy(&dev->descriptor, tmpbuf, 8);
> >  #else
> > @@ -952,7 +952,7 @@ int usb_new_device(struct usb_device *dev)
> >  	err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, 64);
> >  	if (err < 0) {
> >  		debug("usb_new_device: usb_get_descriptor()
> > failed\n");
> > -		return 1;
> > +		return -1;
> >  	}
> >  
> >  	dev->descriptor.bMaxPacketSize0 = desc->bMaxPacketSize0;
> > @@ -968,7 +968,7 @@ int usb_new_device(struct usb_device *dev)
> >  		err = hub_port_reset(dev->parent, dev->portnr - 1,
> > &portstatus); if (err < 0) {
> >  			printf("\n     Couldn't reset port %i\n",
> > dev->portnr);
> > -			return 1;
> > +			return -1;
> >  		}
> >  	} else {
> >  		usb_reset_root_port();
> > @@ -1014,7 +1014,7 @@ int usb_new_device(struct usb_device *dev)
> >  		else
> >  			printf("USB device descriptor short read " \
> >  				"(expected %i, got %i)\n", tmp, err);
> > -		return 1;
> > +		return -1;
> >  	}
> >  	memcpy(&dev->descriptor, tmpbuf, sizeof(dev->descriptor));
> >  	/* correct le values */
> 
> 
>
Marek Vasut April 2, 2015, 5:12 p.m. UTC | #3
On Monday, March 30, 2015 at 03:36:29 PM, Paul Kocialkowski wrote:
> Le lundi 30 mars 2015 à 10:06 +0200, Lukasz Majewski a écrit :
> > Hi Paul,
> > 
> > > Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
> > > ---
> > > 
> > >  common/usb.c | 8 ++++----
> > >  1 file changed, 4 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/common/usb.c b/common/usb.c
> > > index 32e15cd..ea5b406 100644
> > > --- a/common/usb.c
> > > +++ b/common/usb.c
> > > @@ -915,7 +915,7 @@ int usb_new_device(struct usb_device *dev)
> > > 
> > >  	if (err < 8) {
> > >  	
> > >  		printf("\n      USB device not responding, " \
> > >  		
> > >  		       "giving up (status=%lX)\n", dev->status);
> > > 
> > > -		return 1;
> > > +		return -1;
> > 
> > If you are going to provide consistency with error codes, then I think
> > that it would be beneficial to return -Exxx codes (like -EINVAL, etc).
> 
> That makes sense, I'll give it a try soon (I'm not sure I'll get all the
> appropriate error codes right at first try though).

I agree, using proper errno is a step in the right direction. Thanks!

Best regards,
Marek Vasut
diff mbox

Patch

diff --git a/common/usb.c b/common/usb.c
index 32e15cd..ea5b406 100644
--- a/common/usb.c
+++ b/common/usb.c
@@ -915,7 +915,7 @@  int usb_new_device(struct usb_device *dev)
 	if (err < 8) {
 		printf("\n      USB device not responding, " \
 		       "giving up (status=%lX)\n", dev->status);
-		return 1;
+		return -1;
 	}
 	memcpy(&dev->descriptor, tmpbuf, 8);
 #else
@@ -952,7 +952,7 @@  int usb_new_device(struct usb_device *dev)
 	err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, 64);
 	if (err < 0) {
 		debug("usb_new_device: usb_get_descriptor() failed\n");
-		return 1;
+		return -1;
 	}
 
 	dev->descriptor.bMaxPacketSize0 = desc->bMaxPacketSize0;
@@ -968,7 +968,7 @@  int usb_new_device(struct usb_device *dev)
 		err = hub_port_reset(dev->parent, dev->portnr - 1, &portstatus);
 		if (err < 0) {
 			printf("\n     Couldn't reset port %i\n", dev->portnr);
-			return 1;
+			return -1;
 		}
 	} else {
 		usb_reset_root_port();
@@ -1014,7 +1014,7 @@  int usb_new_device(struct usb_device *dev)
 		else
 			printf("USB device descriptor short read " \
 				"(expected %i, got %i)\n", tmp, err);
-		return 1;
+		return -1;
 	}
 	memcpy(&dev->descriptor, tmpbuf, sizeof(dev->descriptor));
 	/* correct le values */