All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] can: kvaser_usb: fix usb endpoints detection
@ 2013-10-28 12:24 Marc Kleine-Budde
  2013-10-28 13:29 ` Olivier Sobrie
  0 siblings, 1 reply; 5+ messages in thread
From: Marc Kleine-Budde @ 2013-10-28 12:24 UTC (permalink / raw)
  To: linux-can; +Cc: Olivier Sobrie, Marc Kleine-Budde

From: Olivier Sobrie <olivier@sobrie.be>

Some devices, like the Kvaser Memorator Professional, have several bulk in
endpoints. Only the first one found must be used by the driver. The same holds
for the bulk out endpoint. The official Kvaser driver (leaf) was used as
reference.

Signed-off-by: Olivier Sobrie <olivier@sobrie.be>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---

changes since v2:
- let kvaser_usb_get_endpoints() return 0 on success, -ENODEV otherwise

changes since v1:
- use explizid return in loop if both in and out endpoints are found.

 drivers/net/can/usb/kvaser_usb.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c
index 3b95465..4b2d5ed 100644
--- a/drivers/net/can/usb/kvaser_usb.c
+++ b/drivers/net/can/usb/kvaser_usb.c
@@ -1544,9 +1544,9 @@ static int kvaser_usb_init_one(struct usb_interface *intf,
 	return 0;
 }
 
-static void kvaser_usb_get_endpoints(const struct usb_interface *intf,
-				     struct usb_endpoint_descriptor **in,
-				     struct usb_endpoint_descriptor **out)
+static int kvaser_usb_get_endpoints(const struct usb_interface *intf,
+				    struct usb_endpoint_descriptor **in,
+				    struct usb_endpoint_descriptor **out)
 {
 	const struct usb_host_interface *iface_desc;
 	struct usb_endpoint_descriptor *endpoint;
@@ -1557,12 +1557,18 @@ static void kvaser_usb_get_endpoints(const struct usb_interface *intf,
 	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++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;
+
+		/* use first bulk endpoint for in and out */
+		if (*in && *out)
+			return 0;
 	}
+
+	return -ENODEV;
 }
 
 static int kvaser_usb_probe(struct usb_interface *intf,
@@ -1576,8 +1582,8 @@ static int kvaser_usb_probe(struct usb_interface *intf,
 	if (!dev)
 		return -ENOMEM;
 
-	kvaser_usb_get_endpoints(intf, &dev->bulk_in, &dev->bulk_out);
-	if (!dev->bulk_in || !dev->bulk_out) {
+	err = kvaser_usb_get_endpoints(intf, &dev->bulk_in, &dev->bulk_out);
+	if (err) {
 		dev_err(&intf->dev, "Cannot get usb endpoint(s)");
 		return err;
 	}
-- 
1.8.4.rc3


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

* Re: [PATCH v3] can: kvaser_usb: fix usb endpoints detection
  2013-10-28 12:24 [PATCH v3] can: kvaser_usb: fix usb endpoints detection Marc Kleine-Budde
@ 2013-10-28 13:29 ` Olivier Sobrie
  2013-10-30 18:43   ` Oliver Hartkopp
  0 siblings, 1 reply; 5+ messages in thread
From: Olivier Sobrie @ 2013-10-28 13:29 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: linux-can

On Mon, Oct 28, 2013 at 01:24:41PM +0100, Marc Kleine-Budde wrote:
> From: Olivier Sobrie <olivier@sobrie.be>
> 
> Some devices, like the Kvaser Memorator Professional, have several bulk in
> endpoints. Only the first one found must be used by the driver. The same holds
> for the bulk out endpoint. The official Kvaser driver (leaf) was used as
> reference.
> 
> Signed-off-by: Olivier Sobrie <olivier@sobrie.be>
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> ---
> 
> changes since v2:
> - let kvaser_usb_get_endpoints() return 0 on success, -ENODEV otherwise

Perfect !
Thank you,

> 
> changes since v1:
> - use explizid return in loop if both in and out endpoints are found.
> 
>  drivers/net/can/usb/kvaser_usb.c | 20 +++++++++++++-------
>  1 file changed, 13 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c
> index 3b95465..4b2d5ed 100644
> --- a/drivers/net/can/usb/kvaser_usb.c
> +++ b/drivers/net/can/usb/kvaser_usb.c
> @@ -1544,9 +1544,9 @@ static int kvaser_usb_init_one(struct usb_interface *intf,
>  	return 0;
>  }
>  
> -static void kvaser_usb_get_endpoints(const struct usb_interface *intf,
> -				     struct usb_endpoint_descriptor **in,
> -				     struct usb_endpoint_descriptor **out)
> +static int kvaser_usb_get_endpoints(const struct usb_interface *intf,
> +				    struct usb_endpoint_descriptor **in,
> +				    struct usb_endpoint_descriptor **out)
>  {
>  	const struct usb_host_interface *iface_desc;
>  	struct usb_endpoint_descriptor *endpoint;
> @@ -1557,12 +1557,18 @@ static void kvaser_usb_get_endpoints(const struct usb_interface *intf,
>  	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++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;
> +
> +		/* use first bulk endpoint for in and out */
> +		if (*in && *out)
> +			return 0;
>  	}
> +
> +	return -ENODEV;
>  }
>  
>  static int kvaser_usb_probe(struct usb_interface *intf,
> @@ -1576,8 +1582,8 @@ static int kvaser_usb_probe(struct usb_interface *intf,
>  	if (!dev)
>  		return -ENOMEM;
>  
> -	kvaser_usb_get_endpoints(intf, &dev->bulk_in, &dev->bulk_out);
> -	if (!dev->bulk_in || !dev->bulk_out) {
> +	err = kvaser_usb_get_endpoints(intf, &dev->bulk_in, &dev->bulk_out);
> +	if (err) {
>  		dev_err(&intf->dev, "Cannot get usb endpoint(s)");
>  		return err;
>  	}
> -- 
> 1.8.4.rc3
> 

-- 
Olivier

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

* Re: [PATCH v3] can: kvaser_usb: fix usb endpoints detection
  2013-10-28 13:29 ` Olivier Sobrie
@ 2013-10-30 18:43   ` Oliver Hartkopp
  2013-10-30 19:09     ` Marc Kleine-Budde
  2013-10-31 20:06     ` Marc Kleine-Budde
  0 siblings, 2 replies; 5+ messages in thread
From: Oliver Hartkopp @ 2013-10-30 18:43 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: linux-can

Hello Marc,

do you plan to add my BCM documentation patch from October 19th when you push
this fix to Dave?

Regards,
Oliver


On 28.10.2013 14:29, Olivier Sobrie wrote:
> On Mon, Oct 28, 2013 at 01:24:41PM +0100, Marc Kleine-Budde wrote:
>> From: Olivier Sobrie <olivier@sobrie.be>
>>
>> Some devices, like the Kvaser Memorator Professional, have several bulk in
>> endpoints. Only the first one found must be used by the driver. The same holds
>> for the bulk out endpoint. The official Kvaser driver (leaf) was used as
>> reference.
>>
>> Signed-off-by: Olivier Sobrie <olivier@sobrie.be>
>> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
>> ---
>>
>> changes since v2:
>> - let kvaser_usb_get_endpoints() return 0 on success, -ENODEV otherwise
> 
> Perfect !
> Thank you,


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

* Re: [PATCH v3] can: kvaser_usb: fix usb endpoints detection
  2013-10-30 18:43   ` Oliver Hartkopp
@ 2013-10-30 19:09     ` Marc Kleine-Budde
  2013-10-31 20:06     ` Marc Kleine-Budde
  1 sibling, 0 replies; 5+ messages in thread
From: Marc Kleine-Budde @ 2013-10-30 19:09 UTC (permalink / raw)
  To: Oliver Hartkopp; +Cc: linux-can

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

On 10/30/2013 07:43 PM, Oliver Hartkopp wrote:
> Hello Marc,
> 
> do you plan to add my BCM documentation patch from October 19th when you push
> this fix to Dave?

Yes, Documentation update into net-next, the kvaser fix into net.

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] 5+ messages in thread

* Re: [PATCH v3] can: kvaser_usb: fix usb endpoints detection
  2013-10-30 18:43   ` Oliver Hartkopp
  2013-10-30 19:09     ` Marc Kleine-Budde
@ 2013-10-31 20:06     ` Marc Kleine-Budde
  1 sibling, 0 replies; 5+ messages in thread
From: Marc Kleine-Budde @ 2013-10-31 20:06 UTC (permalink / raw)
  To: Oliver Hartkopp; +Cc: linux-can

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

On 10/30/2013 07:43 PM, Oliver Hartkopp wrote:
> do you plan to add my BCM documentation patch from October 19th when you push
> this fix to Dave?

Yes, done.

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] 5+ messages in thread

end of thread, other threads:[~2013-10-31 20:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-28 12:24 [PATCH v3] can: kvaser_usb: fix usb endpoints detection Marc Kleine-Budde
2013-10-28 13:29 ` Olivier Sobrie
2013-10-30 18:43   ` Oliver Hartkopp
2013-10-30 19:09     ` Marc Kleine-Budde
2013-10-31 20:06     ` Marc Kleine-Budde

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.