home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   linux.debian.kernel      Debian kernel discussions      2,884 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 1,946 of 2,884   
   Benjamin Tissoires to Sam Halliday   
   Bug#1122193: usb hid descriptor requirem   
   15 Dec 25 13:30:01   
   
   XPost: linux.debian.bugs.dist, linux.kernel   
   From: bentiss@kernel.org   
      
   On Dec 15, 2025, Sam Halliday wrote:   
   > Hi Ben,   
   >   
   > In answer to your logging request, this is the output after running   
   >   
   > echo 'file drivers/hid/usbhid/hid-core.c +p' | sudo tee /sys/k   
   rnel/debug/dynamic_debug/control   
   >   
   > and plugging in the device (with the debian kernel, not my patched one)   
   >   
   > [  371.897694] usb 1-2: new full-speed USB device number 8 using xhci_hcd   
   > [  372.036133] usb 1-2: New USB device found, idVendor=03c3, idProduct=1f01,   
   bcdDevice= 0.00   
   > [  372.036145] usb 1-2: New USB device strings: Mfr=1, Product=2,   
   SerialNumber=0   
   > [  372.036149] usb 1-2: Product: ZWO EFW   
   > [  372.036152] usb 1-2: Manufacturer: ZW0   
   > [  372.043375] drivers/hid/usbhid/hid-core.c: HID probe called for ifnum 0   
   > [  372.043404] drivers/hid/usbhid/hid-core.c: hid descriptor invalid, bLen=9   
   bNum=2   
      
   Looks like the length is shorter than expected. However, after looking   
   more carefully into the code, it seems we can bypass the check as long   
   as the provided length is greater than sizeof(*hdesc), because later in   
   the code we simply ignore any optional HID class descriptors.   
      
   Would you mind testing the following patch?:   
      
   ---   
   From 07020d68764a29a9e5d4e95be1820e0c75a4216a Mon Sep 17 00:00:00 2001   
   From: Benjamin Tissoires    
   Date: Mon, 15 Dec 2025 12:57:21 +0100   
   Subject: [PATCH] HID: usbhid: paper over wrong bNumDescriptor field   
      
   Some faulty devices (ZWO EFWmini) have a wrong optional HID class   
   descriptor count compared to the provided length.   
      
   Given that we plainly ignore those optional descriptor, we can attempt   
   to fix the provided number so we do not lock out those devices.   
      
   Signed-off-by: Benjamin Tissoires    
   ---   
    drivers/hid/usbhid/hid-core.c | 17 ++++++++++++++++-   
    1 file changed, 16 insertions(+), 1 deletion(-)   
      
   diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c   
   index aac0051a2cf6..758eb21430cd 100644   
   --- a/drivers/hid/usbhid/hid-core.c   
   +++ b/drivers/hid/usbhid/hid-core.c   
   @@ -985,6 +985,7 @@ static int usbhid_parse(struct hid_device *hid)   
    	struct usb_device *dev = interface_to_usbdev (intf);   
    	struct hid_descriptor *hdesc;   
    	struct hid_class_descriptor *hcdesc;   
   +	__u8 fixed_opt_descriptors_size;   
    	u32 quirks = 0;   
    	unsigned int rsize = 0;   
    	char *rdesc;   
   @@ -1015,7 +1016,21 @@ static int usbhid_parse(struct hid_device *hid)   
    			      (hdesc->bNumDescriptors - 1) * sizeof(*hcdesc)) {   
    		dbg_hid("hid descriptor invalid, bLen=%hhu bNum=%hhu\n",   
    			hdesc->bLength, hdesc->bNumDescriptors);   
   -		return -EINVAL;   
   +   
   +		/*   
   +		 * Some devices may expose a wrong number of descriptors compared   
   +		 * to the provided length.   
   +		 * However, we ignore the optional hid class descriptors entirely   
   +		 * so we can safely recompute the proper field.   
   +		 */   
   +		if (hdesc->bLength >= sizeof(*hdesc)) {   
   +			fixed_opt_descriptors_size = hdesc->bLength - sizeof(*hdesc);   
   +   
   +			hid_warn(intf, "fixing wrong optional hid class descriptors count\n");   
   +			hdesc->bNumDescriptors = fixed_opt_descriptors_size / sizeof(*hcdesc) + 1;   
   +		} else {   
   +			return -EINVAL;   
   +		}   
    	}   
      
    	hid->version = le16_to_cpu(hdesc->bcdHID);   
   --   
   2.51.1   
      
   ---   
      
   Cheers,   
   Benjamin   
      
   > [  372.043409] usbhid 1-2:1.0: can't add hid device: -22   
   > [  372.043422] usbhid 1-2:1.0: probe with driver usbhid failed with error -22   
   >   
   > Also here is a more detailed lsusb output   
   >   
   >   
   > Bus 001 Device 008: ID 03c3:1f01 ZWO ZWO EFW   
   > Negotiated speed: Full Speed (12Mbps)   
   > Device Descriptor:   
   >   bLength                18   
   >   bDescriptorType         1   
   >   bcdUSB               1.10   
   >   bDeviceClass            0 [unknown]   
   >   bDeviceSubClass         0 [unknown]   
   >   bDeviceProtocol         0   
   >   bMaxPacketSize0        16   
   >   idVendor           0x03c3 ZWO   
   >   idProduct          0x1f01 ZWO EFW   
   >   bcdDevice            0.00   
   >   iManufacturer           1 ZW0   
   >   iProduct                2 ZWO EFW   
   >   iSerial                 0   
   >   bNumConfigurations      1   
   >   Configuration Descriptor:   
   >     bLength                 9   
   >     bDescriptorType         2   
   >     wTotalLength       0x0029   
   >     bNumInterfaces          1   
   >     bConfigurationValue     1   
   >     iConfiguration          0   
   >     bmAttributes         0x80   
   >       (Bus Powered)   
   >     MaxPower               64mA   
   >     Interface Descriptor:   
   >       bLength                 9   
   >       bDescriptorType         4   
   >       bInterfaceNumber        0   
   >       bAlternateSetting       0   
   >       bNumEndpoints           2   
   >       bInterfaceClass         3 Human Interface Device   
   >       bInterfaceSubClass      0 [unknown]   
   >       bInterfaceProtocol      0   
   >       iInterface              0   
   >       Warning: Descriptor too short   
   >         HID Device Descriptor:   
   >           bLength                 9   
   >           bDescriptorType        33   
   >           bcdHID               1.01   
   >           bCountryCode            0 Not supported   
   >           bNumDescriptors         2   
   >           bDescriptorType        34 (null)   
   >           wDescriptorLength      68   
   >           bDescriptorType         0 (null)   
   >           wDescriptorLength       0   
   >           Report Descriptor: (length is 68)   
   >             Item(Global): Usage Page, data= [ 0x00 0xff ] 65280   
   >                             (null)   
   >             Item(Local ): (null), data= [ 0x01 ] 1   
   >                             (null)   
   >             Item(Main  ): (null), data= [ 0x01 ] 1   
   >                             Application   
   >             Item(Global): (null), data= [ 0x01 ] 1   
   >             Item(Global): (null), data= [ 0x0f ] 15   
   >             Item(Global): (null), data= [ 0x08 ] 8   
      
   [continued in next message]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca