]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
can: ucan: refactor endpoint lookup
authorJohan Hovold <johan@kernel.org>
Mon, 30 Mar 2026 10:18:17 +0000 (12:18 +0200)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Wed, 1 Apr 2026 07:27:58 +0000 (09:27 +0200)
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>
Link: https://patch.msgid.link/20260330101817.1664787-3-johan@kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
drivers/net/can/usb/ucan.c

index 0ea0ac75e42f9a9b8e13a01b5b23d9fa051fdcc5..506d9e74aa7960db67dcbcf0b2705686f0b0c2d7 100644 (file)
@@ -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);