Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

can: kvaser_usb: fix usb endpoints detection

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>

authored by

Olivier Sobrie and committed by
Marc Kleine-Budde
896e23bd 5d0f801a

+13 -7
+13 -7
drivers/net/can/usb/kvaser_usb.c
··· 1544 1544 return 0; 1545 1545 } 1546 1546 1547 - static void kvaser_usb_get_endpoints(const struct usb_interface *intf, 1548 - struct usb_endpoint_descriptor **in, 1549 - struct usb_endpoint_descriptor **out) 1547 + static int kvaser_usb_get_endpoints(const struct usb_interface *intf, 1548 + struct usb_endpoint_descriptor **in, 1549 + struct usb_endpoint_descriptor **out) 1550 1550 { 1551 1551 const struct usb_host_interface *iface_desc; 1552 1552 struct usb_endpoint_descriptor *endpoint; ··· 1557 1557 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { 1558 1558 endpoint = &iface_desc->endpoint[i].desc; 1559 1559 1560 - if (usb_endpoint_is_bulk_in(endpoint)) 1560 + if (!*in && usb_endpoint_is_bulk_in(endpoint)) 1561 1561 *in = endpoint; 1562 1562 1563 - if (usb_endpoint_is_bulk_out(endpoint)) 1563 + if (!*out && usb_endpoint_is_bulk_out(endpoint)) 1564 1564 *out = endpoint; 1565 + 1566 + /* use first bulk endpoint for in and out */ 1567 + if (*in && *out) 1568 + return 0; 1565 1569 } 1570 + 1571 + return -ENODEV; 1566 1572 } 1567 1573 1568 1574 static int kvaser_usb_probe(struct usb_interface *intf, ··· 1582 1576 if (!dev) 1583 1577 return -ENOMEM; 1584 1578 1585 - kvaser_usb_get_endpoints(intf, &dev->bulk_in, &dev->bulk_out); 1586 - if (!dev->bulk_in || !dev->bulk_out) { 1579 + err = kvaser_usb_get_endpoints(intf, &dev->bulk_in, &dev->bulk_out); 1580 + if (err) { 1587 1581 dev_err(&intf->dev, "Cannot get usb endpoint(s)"); 1588 1582 return err; 1589 1583 }