* [PATCH 0/2] can: refactor USB endpoint lookups
@ 2026-03-30 10:18 Johan Hovold
2026-03-30 10:18 ` [PATCH 1/2] can: kvaser_usb: leaf: refactor endpoint lookup Johan Hovold
2026-03-30 10:18 ` [PATCH 2/2] can: ucan: " Johan Hovold
0 siblings, 2 replies; 3+ messages in thread
From: Johan Hovold @ 2026-03-30 10:18 UTC (permalink / raw)
To: Marc Kleine-Budde, Vincent Mailhol; +Cc: linux-can, linux-kernel, Johan Hovold
Use the common USB helper for looking up bulk and interrupt endpoints
instead of open coding.
Johan
Johan Hovold (2):
can: kvaser_usb: leaf: refactor endpoint lookup
can: ucan: refactor endpoint lookup
.../net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 25 ++++--------
drivers/net/can/usb/ucan.c | 40 +++++--------------
2 files changed, 19 insertions(+), 46 deletions(-)
--
2.52.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] can: kvaser_usb: leaf: refactor endpoint lookup
2026-03-30 10:18 [PATCH 0/2] can: refactor USB endpoint lookups Johan Hovold
@ 2026-03-30 10:18 ` Johan Hovold
2026-03-30 10:18 ` [PATCH 2/2] can: ucan: " Johan Hovold
1 sibling, 0 replies; 3+ messages in thread
From: Johan Hovold @ 2026-03-30 10:18 UTC (permalink / raw)
To: Marc Kleine-Budde, Vincent Mailhol; +Cc: linux-can, linux-kernel, Johan Hovold
Use the common USB helper for looking up bulk and interrupt endpoints
instead of open coding.
Signed-off-by: Johan Hovold <johan@kernel.org>
---
.../net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 25 ++++++-------------
1 file changed, 8 insertions(+), 17 deletions(-)
diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
index fd191ec5738b..df737cfc5ea0 100644
--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
+++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
@@ -1957,27 +1957,18 @@ static int kvaser_usb_leaf_get_berr_counter(const struct net_device *netdev,
static int kvaser_usb_leaf_setup_endpoints(struct kvaser_usb *dev)
{
- const struct usb_host_interface *iface_desc;
- struct usb_endpoint_descriptor *endpoint;
- int i;
+ struct usb_host_interface *iface_desc;
+ int ret;
iface_desc = dev->intf->cur_altsetting;
- for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
- endpoint = &iface_desc->endpoint[i].desc;
-
- if (!dev->bulk_in && usb_endpoint_is_bulk_in(endpoint))
- dev->bulk_in = endpoint;
-
- if (!dev->bulk_out && usb_endpoint_is_bulk_out(endpoint))
- dev->bulk_out = endpoint;
+ /* use first bulk endpoint for in and out */
+ ret = usb_find_common_endpoints(iface_desc, &dev->bulk_in, &dev->bulk_out,
+ NULL, NULL);
+ if (ret)
+ return -ENODEV;
- /* use first bulk endpoint for in and out */
- if (dev->bulk_in && dev->bulk_out)
- return 0;
- }
-
- return -ENODEV;
+ return 0;
}
const struct kvaser_usb_dev_ops kvaser_usb_leaf_dev_ops = {
--
2.52.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] can: ucan: refactor endpoint lookup
2026-03-30 10:18 [PATCH 0/2] can: refactor USB endpoint lookups Johan Hovold
2026-03-30 10:18 ` [PATCH 1/2] can: kvaser_usb: leaf: refactor endpoint lookup Johan Hovold
@ 2026-03-30 10:18 ` Johan Hovold
1 sibling, 0 replies; 3+ messages in thread
From: Johan Hovold @ 2026-03-30 10:18 UTC (permalink / raw)
To: Marc Kleine-Budde, Vincent Mailhol; +Cc: linux-can, linux-kernel, Johan Hovold
Use the common USB helpers for looking up bulk and interrupt endpoints
(and determining endpoint numbers and max packet sizes) instead of open
coding.
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/net/can/usb/ucan.c | 40 +++++++++++---------------------------
1 file changed, 11 insertions(+), 29 deletions(-)
diff --git a/drivers/net/can/usb/ucan.c b/drivers/net/can/usb/ucan.c
index ee3c1abbd063..f72e0644c5fd 100644
--- a/drivers/net/can/usb/ucan.c
+++ b/drivers/net/can/usb/ucan.c
@@ -1302,13 +1302,12 @@ static int ucan_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
int ret;
- int i;
u32 protocol_version;
struct usb_device *udev;
struct net_device *netdev;
struct usb_host_interface *iface_desc;
struct ucan_priv *up;
- struct usb_endpoint_descriptor *ep;
+ struct usb_endpoint_descriptor *ep_in, *ep_out;
u16 in_ep_size;
u16 out_ep_size;
u8 in_ep_addr;
@@ -1343,37 +1342,20 @@ static int ucan_probe(struct usb_interface *intf,
}
/* check interface endpoints */
- in_ep_addr = 0;
- out_ep_addr = 0;
- in_ep_size = 0;
- out_ep_size = 0;
- for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
- ep = &iface_desc->endpoint[i].desc;
-
- if (((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) != 0) &&
- ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
- USB_ENDPOINT_XFER_BULK)) {
- /* In Endpoint */
- in_ep_addr = ep->bEndpointAddress;
- in_ep_addr &= USB_ENDPOINT_NUMBER_MASK;
- in_ep_size = le16_to_cpu(ep->wMaxPacketSize);
- } else if (((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) ==
- 0) &&
- ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
- USB_ENDPOINT_XFER_BULK)) {
- /* Out Endpoint */
- out_ep_addr = ep->bEndpointAddress;
- out_ep_addr &= USB_ENDPOINT_NUMBER_MASK;
- out_ep_size = le16_to_cpu(ep->wMaxPacketSize);
- }
- }
-
- /* check if interface is sane */
- if (!in_ep_addr || !out_ep_addr) {
+ ret = usb_find_common_endpoints_reverse(iface_desc, &ep_in, &ep_out,
+ NULL, NULL);
+ if (ret) {
dev_err(&udev->dev, "%s: invalid endpoint configuration\n",
UCAN_DRIVER_NAME);
goto err_firmware_needs_update;
}
+
+ in_ep_addr = usb_endpoint_num(ep_in);
+ out_ep_addr = usb_endpoint_num(ep_out);
+ in_ep_size = usb_endpoint_maxp(ep_in);
+ out_ep_size = usb_endpoint_maxp(ep_out);
+
+ /* check if interface is sane */
if (in_ep_size < sizeof(struct ucan_message_in)) {
dev_err(&udev->dev, "%s: invalid in_ep MaxPacketSize\n",
UCAN_DRIVER_NAME);
--
2.52.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-03-30 10:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-30 10:18 [PATCH 0/2] can: refactor USB endpoint lookups Johan Hovold
2026-03-30 10:18 ` [PATCH 1/2] can: kvaser_usb: leaf: refactor endpoint lookup Johan Hovold
2026-03-30 10:18 ` [PATCH 2/2] can: ucan: " Johan Hovold
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox