Hi,

On Wed, Jan 27, 2021 at 08:58:21AM +0100, Alexandre Ratchov wrote:
> ok ratchov

Thanks everyone for your OKs.

Here's an updated diff that caters for Marcus' recent attribute renaming
and which also has the long comment wrapped.

I'll commit it shortly if nothing else comes up.


Index: usbdi.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/usbdi.c,v
retrieving revision 1.107
diff -u -p -r1.107 usbdi.c
--- usbdi.c     27 Jan 2021 17:28:19 -0000      1.107
+++ usbdi.c     28 Jan 2021 00:01:11 -0000
@@ -638,12 +638,26 @@ usbd_status
 usbd_device2interface_handle(struct usbd_device *dev, u_int8_t ifaceno,
     struct usbd_interface **iface)
 {
+       u_int8_t idx;
+
        if (dev->cdesc == NULL)
                return (USBD_NOT_CONFIGURED);
-       if (ifaceno >= dev->cdesc->bNumInterfaces)
-               return (USBD_INVAL);
-       *iface = &dev->ifaces[ifaceno];
-       return (USBD_NORMAL_COMPLETION);
+       if (ifaceno < dev->cdesc->bNumInterfaces &&
+           dev->ifaces[ifaceno].idesc->bInterfaceNumber == ifaceno) {
+               *iface = &dev->ifaces[ifaceno];
+               return (USBD_NORMAL_COMPLETION);
+       }
+       /*
+        * With some non-compliant devices, the correct interface may be found
+        * at the wrong index.
+        */
+       for (idx = 0; idx < dev->cdesc->bNumInterfaces; idx++) {
+               if (dev->ifaces[idx].idesc->bInterfaceNumber == ifaceno) {
+                       *iface = &dev->ifaces[idx];
+                       return (USBD_NORMAL_COMPLETION);
+               }
+       }
+       return (USBD_INVAL);
 }
 
 /* XXXX use altno */


-- 
Best Regards
Edd Barrett

http://www.theunixzoo.co.uk

Reply via email to