Skip to content

Commit

Permalink
can: kvaser_usb: fix usb endpoints detection
Browse files Browse the repository at this point in the history
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 for this patch.

Cc: linux-stable <stable@vger.kernel.org>
Signed-off-by: Olivier Sobrie <olivier@sobrie.be>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
  • Loading branch information
Olivier Sobrie authored and Marc Kleine-Budde committed Oct 31, 2013
1 parent 5d0f801 commit 896e23b
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions drivers/net/can/usb/kvaser_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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;
}
Expand Down

0 comments on commit 896e23b

Please sign in to comment.