All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] can: kvaser_usb: fix usb endpoints detection
@ 2013-10-27 21:07 Olivier Sobrie
  2013-10-27 23:29 ` Marc Kleine-Budde
  2013-10-28  9:25 ` Marc Kleine-Budde
  0 siblings, 2 replies; 7+ messages in thread
From: Olivier Sobrie @ 2013-10-27 21:07 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: Wolfgang Grandegger, linux-can, Olivier Sobrie

Some devices, like the Kvaser Memorator Professional, have several
bulk in endpoints. Only the first one found should be used by the
driver. The same holds for the bulk out endpoint.

Signed-off-by: Olivier Sobrie <olivier@sobrie.be>
---
 drivers/net/can/usb/kvaser_usb.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c
index 3b95465..bdbf5bf 100644
--- a/drivers/net/can/usb/kvaser_usb.c
+++ b/drivers/net/can/usb/kvaser_usb.c
@@ -1554,13 +1554,14 @@ static void kvaser_usb_get_endpoints(const struct usb_interface *intf,
 
 	iface_desc = &intf->altsetting[0];
 
-	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
+	for (i = 0; (i < iface_desc->desc.bNumEndpoints) && (!*in || !*out);
+	     ++i) {
 		endpoint = &iface_desc->endpoint[i].desc;
 
-		if (usb_endpoint_is_bulk_in(endpoint))
+		if (!*in && usb_endpoint_is_bulk_in(endpoint))
 			*in = endpoint;
 
-		if (usb_endpoint_is_bulk_out(endpoint))
+		if (!*out && usb_endpoint_is_bulk_out(endpoint))
 			*out = endpoint;
 	}
 }
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] can: kvaser_usb: fix usb endpoints detection
  2013-10-27 21:07 [PATCH] can: kvaser_usb: fix usb endpoints detection Olivier Sobrie
@ 2013-10-27 23:29 ` Marc Kleine-Budde
  2013-10-28  8:29   ` Marc Kleine-Budde
  2013-10-28 12:06   ` Olivier Sobrie
  2013-10-28  9:25 ` Marc Kleine-Budde
  1 sibling, 2 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2013-10-27 23:29 UTC (permalink / raw)
  To: Olivier Sobrie; +Cc: Wolfgang Grandegger, linux-can

[-- Attachment #1: Type: text/plain, Size: 1814 bytes --]

On 10/27/2013 10:07 PM, Olivier Sobrie wrote:
> Some devices, like the Kvaser Memorator Professional, have several
> bulk in endpoints. Only the first one found should be used by the
> driver. The same holds for the bulk out endpoint.

Can you give reference where this information comes from? e.g.
documentation or another driver?

> Signed-off-by: Olivier Sobrie <olivier@sobrie.be>
> ---
>  drivers/net/can/usb/kvaser_usb.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c
> index 3b95465..bdbf5bf 100644
> --- a/drivers/net/can/usb/kvaser_usb.c
> +++ b/drivers/net/can/usb/kvaser_usb.c
> @@ -1554,13 +1554,14 @@ static void kvaser_usb_get_endpoints(const struct usb_interface *intf,
>  
>  	iface_desc = &intf->altsetting[0];
>  
> -	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
> +	for (i = 0; (i < iface_desc->desc.bNumEndpoints) && (!*in || !*out);
> +	     ++i) {
>  		endpoint = &iface_desc->endpoint[i].desc;
>  
> -		if (usb_endpoint_is_bulk_in(endpoint))
> +		if (!*in && usb_endpoint_is_bulk_in(endpoint))
>  			*in = endpoint;
>  
> -		if (usb_endpoint_is_bulk_out(endpoint))
> +		if (!*out && usb_endpoint_is_bulk_out(endpoint))
>  			*out = endpoint;

I personally would add a break or return here, together with a short
comment:

	/* only use first endpoint for in and out */
	if (*in && *out)
		return;

>  	}
>  }
> 

Thanks for taking care of the driver,
Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] can: kvaser_usb: fix usb endpoints detection
  2013-10-27 23:29 ` Marc Kleine-Budde
@ 2013-10-28  8:29   ` Marc Kleine-Budde
  2013-10-28 12:06   ` Olivier Sobrie
  1 sibling, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2013-10-28  8:29 UTC (permalink / raw)
  To: Olivier Sobrie; +Cc: Wolfgang Grandegger, linux-can

[-- Attachment #1: Type: text/plain, Size: 1922 bytes --]

On 10/28/2013 12:29 AM, Marc Kleine-Budde wrote:
> On 10/27/2013 10:07 PM, Olivier Sobrie wrote:
>> Some devices, like the Kvaser Memorator Professional, have several
>> bulk in endpoints. Only the first one found should be used by the
>> driver. The same holds for the bulk out endpoint.
> 
> Can you give reference where this information comes from? e.g.
> documentation or another driver?
> 
>> Signed-off-by: Olivier Sobrie <olivier@sobrie.be>
>> ---
>>  drivers/net/can/usb/kvaser_usb.c | 7 ++++---
>>  1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c
>> index 3b95465..bdbf5bf 100644
>> --- a/drivers/net/can/usb/kvaser_usb.c
>> +++ b/drivers/net/can/usb/kvaser_usb.c
>> @@ -1554,13 +1554,14 @@ static void kvaser_usb_get_endpoints(const struct usb_interface *intf,
>>  
>>  	iface_desc = &intf->altsetting[0];
>>  
>> -	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
>> +	for (i = 0; (i < iface_desc->desc.bNumEndpoints) && (!*in || !*out);
>> +	     ++i) {
>>  		endpoint = &iface_desc->endpoint[i].desc;
>>  
>> -		if (usb_endpoint_is_bulk_in(endpoint))
>> +		if (!*in && usb_endpoint_is_bulk_in(endpoint))
>>  			*in = endpoint;
>>  
>> -		if (usb_endpoint_is_bulk_out(endpoint))
>> +		if (!*out && usb_endpoint_is_bulk_out(endpoint))
>>  			*out = endpoint;
> 
> I personally would add a break or return here, together with a short
> comment:
> 
> 	/* only use first endpoint for in and out */
> 	if (*in && *out)
> 		return;

With this break or return you can keep the for-loop as it is.

Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] can: kvaser_usb: fix usb endpoints detection
  2013-10-27 21:07 [PATCH] can: kvaser_usb: fix usb endpoints detection Olivier Sobrie
  2013-10-27 23:29 ` Marc Kleine-Budde
@ 2013-10-28  9:25 ` Marc Kleine-Budde
  2013-10-28 12:08   ` Olivier Sobrie
  1 sibling, 1 reply; 7+ messages in thread
From: Marc Kleine-Budde @ 2013-10-28  9:25 UTC (permalink / raw)
  To: Olivier Sobrie; +Cc: Wolfgang Grandegger, linux-can

[-- Attachment #1: Type: text/plain, Size: 620 bytes --]

On 10/27/2013 10:07 PM, Olivier Sobrie wrote:
> Some devices, like the Kvaser Memorator Professional, have several
> bulk in endpoints. Only the first one found should be used by the
> driver. The same holds for the bulk out endpoint.

Is this a critical fix? Does the hardware work without this patch?
Should I add stable on Cc?

Marc
-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] can: kvaser_usb: fix usb endpoints detection
  2013-10-27 23:29 ` Marc Kleine-Budde
  2013-10-28  8:29   ` Marc Kleine-Budde
@ 2013-10-28 12:06   ` Olivier Sobrie
  2013-10-28 12:26     ` Marc Kleine-Budde
  1 sibling, 1 reply; 7+ messages in thread
From: Olivier Sobrie @ 2013-10-28 12:06 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: Wolfgang Grandegger, linux-can

On Mon, Oct 28, 2013 at 12:29:31AM +0100, Marc Kleine-Budde wrote:
> On 10/27/2013 10:07 PM, Olivier Sobrie wrote:
> > Some devices, like the Kvaser Memorator Professional, have several
> > bulk in endpoints. Only the first one found should be used by the
> > driver. The same holds for the bulk out endpoint.
> 
> Can you give reference where this information comes from? e.g.
> documentation or another driver?

Someone using a Kvaser Memorator contacted me and said that its device was
not working. I found out that the usb endpoint used was not correct and I
saw in the Kvaser official driver (leaf) that the detection was made
similarly to what is done in the patch below.
So the reference is the "leaf" driver of Kvaser.

> 
> > Signed-off-by: Olivier Sobrie <olivier@sobrie.be>
> > ---
> >  drivers/net/can/usb/kvaser_usb.c | 7 ++++---
> >  1 file changed, 4 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c
> > index 3b95465..bdbf5bf 100644
> > --- a/drivers/net/can/usb/kvaser_usb.c
> > +++ b/drivers/net/can/usb/kvaser_usb.c
> > @@ -1554,13 +1554,14 @@ static void kvaser_usb_get_endpoints(const struct usb_interface *intf,
> >  
> >  	iface_desc = &intf->altsetting[0];
> >  
> > -	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
> > +	for (i = 0; (i < iface_desc->desc.bNumEndpoints) && (!*in || !*out);
> > +	     ++i) {
> >  		endpoint = &iface_desc->endpoint[i].desc;
> >  
> > -		if (usb_endpoint_is_bulk_in(endpoint))
> > +		if (!*in && usb_endpoint_is_bulk_in(endpoint))
> >  			*in = endpoint;
> >  
> > -		if (usb_endpoint_is_bulk_out(endpoint))
> > +		if (!*out && usb_endpoint_is_bulk_out(endpoint))
> >  			*out = endpoint;
> 
> I personally would add a break or return here, together with a short
> comment:
> 
> 	/* only use first endpoint for in and out */
> 	if (*in && *out)
> 		return;
> 
> >  	}
> >  }
> > 

Fine for me. We can even maybe add a return code to the function and check
this return code intead of checking again (!dev->bulk_in || !dev->bulk_out).
By the way, the current return code (-ENOMEM) is maybe not appropriate in
case the endpoints are not found.

Thank you,

-- 
Olivier

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] can: kvaser_usb: fix usb endpoints detection
  2013-10-28  9:25 ` Marc Kleine-Budde
@ 2013-10-28 12:08   ` Olivier Sobrie
  0 siblings, 0 replies; 7+ messages in thread
From: Olivier Sobrie @ 2013-10-28 12:08 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: Wolfgang Grandegger, linux-can

On Mon, Oct 28, 2013 at 10:25:42AM +0100, Marc Kleine-Budde wrote:
> On 10/27/2013 10:07 PM, Olivier Sobrie wrote:
> > Some devices, like the Kvaser Memorator Professional, have several
> > bulk in endpoints. Only the first one found should be used by the
> > driver. The same holds for the bulk out endpoint.
> 
> Is this a critical fix? Does the hardware work without this patch?
> Should I add stable on Cc?

Yes it is critical for all devices like Kvaser Memorator Pro.
Without this patch these devices don't work.
So yes, you can add stable in cc.

Kr,

-- 
Olivier

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] can: kvaser_usb: fix usb endpoints detection
  2013-10-28 12:06   ` Olivier Sobrie
@ 2013-10-28 12:26     ` Marc Kleine-Budde
  0 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2013-10-28 12:26 UTC (permalink / raw)
  To: Olivier Sobrie; +Cc: Wolfgang Grandegger, linux-can

[-- Attachment #1: Type: text/plain, Size: 2631 bytes --]

On 10/28/2013 01:06 PM, Olivier Sobrie wrote:
> On Mon, Oct 28, 2013 at 12:29:31AM +0100, Marc Kleine-Budde wrote:
>> On 10/27/2013 10:07 PM, Olivier Sobrie wrote:
>>> Some devices, like the Kvaser Memorator Professional, have several
>>> bulk in endpoints. Only the first one found should be used by the
>>> driver. The same holds for the bulk out endpoint.
>>
>> Can you give reference where this information comes from? e.g.
>> documentation or another driver?
> 
> Someone using a Kvaser Memorator contacted me and said that its device was
> not working. I found out that the usb endpoint used was not correct and I
> saw in the Kvaser official driver (leaf) that the detection was made
> similarly to what is done in the patch below.
> So the reference is the "leaf" driver of Kvaser.
> 
>>
>>> Signed-off-by: Olivier Sobrie <olivier@sobrie.be>
>>> ---
>>>  drivers/net/can/usb/kvaser_usb.c | 7 ++++---
>>>  1 file changed, 4 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c
>>> index 3b95465..bdbf5bf 100644
>>> --- a/drivers/net/can/usb/kvaser_usb.c
>>> +++ b/drivers/net/can/usb/kvaser_usb.c
>>> @@ -1554,13 +1554,14 @@ static void kvaser_usb_get_endpoints(const struct usb_interface *intf,
>>>  
>>>  	iface_desc = &intf->altsetting[0];
>>>  
>>> -	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
>>> +	for (i = 0; (i < iface_desc->desc.bNumEndpoints) && (!*in || !*out);
>>> +	     ++i) {
>>>  		endpoint = &iface_desc->endpoint[i].desc;
>>>  
>>> -		if (usb_endpoint_is_bulk_in(endpoint))
>>> +		if (!*in && usb_endpoint_is_bulk_in(endpoint))
>>>  			*in = endpoint;
>>>  
>>> -		if (usb_endpoint_is_bulk_out(endpoint))
>>> +		if (!*out && usb_endpoint_is_bulk_out(endpoint))
>>>  			*out = endpoint;
>>
>> I personally would add a break or return here, together with a short
>> comment:
>>
>> 	/* only use first endpoint for in and out */
>> 	if (*in && *out)
>> 		return;
>>
>>>  	}
>>>  }
>>>
> 
> Fine for me. We can even maybe add a return code to the function and check
> this return code intead of checking again (!dev->bulk_in || !dev->bulk_out).
> By the way, the current return code (-ENOMEM) is maybe not appropriate in
> case the endpoints are not found.

Good idea, have a look at v3.

Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-10-28 12:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-27 21:07 [PATCH] can: kvaser_usb: fix usb endpoints detection Olivier Sobrie
2013-10-27 23:29 ` Marc Kleine-Budde
2013-10-28  8:29   ` Marc Kleine-Budde
2013-10-28 12:06   ` Olivier Sobrie
2013-10-28 12:26     ` Marc Kleine-Budde
2013-10-28  9:25 ` Marc Kleine-Budde
2013-10-28 12:08   ` Olivier Sobrie

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.