]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
wifi: libertas: refactor endpoint lookup
authorJohan Hovold <johan@kernel.org>
Tue, 7 Apr 2026 15:11:10 +0000 (17:11 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Wed, 8 Apr 2026 06:33:40 +0000 (08:33 +0200)
Use the common USB helpers for looking up bulk and interrupt endpoints
(and determining max packet size) instead of open coding.

Note that the driver has an implicit max packet size check which is
kept.

Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://patch.msgid.link/20260407151111.3187826-3-johan@kernel.org
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
drivers/net/wireless/marvell/libertas/if_usb.c

index 176f2106bab6f8d2b71bbd8226867c5a61e43771..4fae0e335136611548738887766aa8463b82ab24 100644 (file)
@@ -193,13 +193,12 @@ static void if_usb_reset_olpc_card(struct lbs_private *priv)
 static int if_usb_probe(struct usb_interface *intf,
                        const struct usb_device_id *id)
 {
+       struct usb_endpoint_descriptor *ep_in, *ep_out;
        struct usb_device *udev;
        struct usb_host_interface *iface_desc;
-       struct usb_endpoint_descriptor *endpoint;
        struct lbs_private *priv;
        struct if_usb_card *cardp;
        int r = -ENOMEM;
-       int i;
 
        udev = interface_to_usbdev(intf);
 
@@ -224,25 +223,25 @@ static int if_usb_probe(struct usb_interface *intf,
        init_usb_anchor(&cardp->rx_submitted);
        init_usb_anchor(&cardp->tx_submitted);
 
-       for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
-               endpoint = &iface_desc->endpoint[i].desc;
-               if (usb_endpoint_is_bulk_in(endpoint)) {
-                       cardp->ep_in_size = le16_to_cpu(endpoint->wMaxPacketSize);
-                       cardp->ep_in = usb_endpoint_num(endpoint);
+       if (usb_find_common_endpoints_reverse(iface_desc, &ep_in, &ep_out, NULL, NULL)) {
+               lbs_deb_usbd(&udev->dev, "Endpoints not found\n");
+               goto dealloc;
+       }
 
-                       lbs_deb_usbd(&udev->dev, "in_endpoint = %d\n", cardp->ep_in);
-                       lbs_deb_usbd(&udev->dev, "Bulk in size is %d\n", cardp->ep_in_size);
+       cardp->ep_in_size = usb_endpoint_maxp(ep_in);
+       cardp->ep_in = usb_endpoint_num(ep_in);
 
-               } else if (usb_endpoint_is_bulk_out(endpoint)) {
-                       cardp->ep_out_size = le16_to_cpu(endpoint->wMaxPacketSize);
-                       cardp->ep_out = usb_endpoint_num(endpoint);
+       lbs_deb_usbd(&udev->dev, "in_endpoint = %d\n", cardp->ep_in);
+       lbs_deb_usbd(&udev->dev, "Bulk in size is %d\n", cardp->ep_in_size);
+
+       cardp->ep_out_size = usb_endpoint_maxp(ep_out);
+       cardp->ep_out = usb_endpoint_num(ep_out);
+
+       lbs_deb_usbd(&udev->dev, "out_endpoint = %d\n", cardp->ep_out);
+       lbs_deb_usbd(&udev->dev, "Bulk out size is %d\n", cardp->ep_out_size);
 
-                       lbs_deb_usbd(&udev->dev, "out_endpoint = %d\n", cardp->ep_out);
-                       lbs_deb_usbd(&udev->dev, "Bulk out size is %d\n", cardp->ep_out_size);
-               }
-       }
        if (!cardp->ep_out_size || !cardp->ep_in_size) {
-               lbs_deb_usbd(&udev->dev, "Endpoints not found\n");
+               lbs_deb_usbd(&udev->dev, "Endpoints not valid\n");
                goto dealloc;
        }
        if (!(cardp->rx_urb = usb_alloc_urb(0, GFP_KERNEL))) {