All of lore.kernel.org
 help / color / mirror / Atom feed
From: Olivier Sobrie <olivier@sobrie.be>
To: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: linux-can@vger.kernel.org
Subject: Re: [PATCH v3] can: kvaser_usb: fix usb endpoints detection
Date: Mon, 28 Oct 2013 14:29:59 +0100	[thread overview]
Message-ID: <20131028132959.GA19808@hposo> (raw)
In-Reply-To: <1382963081-11012-1-git-send-email-mkl@pengutronix.de>

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

  reply	other threads:[~2013-10-28 13:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-28 12:24 [PATCH v3] can: kvaser_usb: fix usb endpoints detection Marc Kleine-Budde
2013-10-28 13:29 ` Olivier Sobrie [this message]
2013-10-30 18:43   ` Oliver Hartkopp
2013-10-30 19:09     ` Marc Kleine-Budde
2013-10-31 20:06     ` Marc Kleine-Budde

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131028132959.GA19808@hposo \
    --to=olivier@sobrie.be \
    --cc=linux-can@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.