@@ -984,12 +984,11 @@ static int usbhid_parse(struct hid_device *hid)
984984 struct usb_host_interface * interface = intf -> cur_altsetting ;
985985 struct usb_device * dev = interface_to_usbdev (intf );
986986 struct hid_descriptor * hdesc ;
987+ struct hid_class_descriptor * hcdesc ;
987988 u32 quirks = 0 ;
988989 unsigned int rsize = 0 ;
989990 char * rdesc ;
990- int ret , n ;
991- int num_descriptors ;
992- size_t offset = offsetof(struct hid_descriptor , desc );
991+ int ret ;
993992
994993 quirks = hid_lookup_quirk (hid );
995994
@@ -1011,20 +1010,19 @@ static int usbhid_parse(struct hid_device *hid)
10111010 return - ENODEV ;
10121011 }
10131012
1014- if (hdesc -> bLength < sizeof (struct hid_descriptor )) {
1015- dbg_hid ("hid descriptor is too short\n" );
1013+ if (!hdesc -> bNumDescriptors ||
1014+ hdesc -> bLength != sizeof (* hdesc ) +
1015+ (hdesc -> bNumDescriptors - 1 ) * sizeof (* hcdesc )) {
1016+ dbg_hid ("hid descriptor invalid, bLen=%hhu bNum=%hhu\n" ,
1017+ hdesc -> bLength , hdesc -> bNumDescriptors );
10161018 return - EINVAL ;
10171019 }
10181020
10191021 hid -> version = le16_to_cpu (hdesc -> bcdHID );
10201022 hid -> country = hdesc -> bCountryCode ;
10211023
1022- num_descriptors = min_t (int , hdesc -> bNumDescriptors ,
1023- (hdesc -> bLength - offset ) / sizeof (struct hid_class_descriptor ));
1024-
1025- for (n = 0 ; n < num_descriptors ; n ++ )
1026- if (hdesc -> desc [n ].bDescriptorType == HID_DT_REPORT )
1027- rsize = le16_to_cpu (hdesc -> desc [n ].wDescriptorLength );
1024+ if (hdesc -> rpt_desc .bDescriptorType == HID_DT_REPORT )
1025+ rsize = le16_to_cpu (hdesc -> rpt_desc .wDescriptorLength );
10281026
10291027 if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE ) {
10301028 dbg_hid ("weird size of report descriptor (%u)\n" , rsize );
@@ -1052,6 +1050,11 @@ static int usbhid_parse(struct hid_device *hid)
10521050 goto err ;
10531051 }
10541052
1053+ if (hdesc -> bNumDescriptors > 1 )
1054+ hid_warn (intf ,
1055+ "%u unsupported optional hid class descriptors\n" ,
1056+ (int )(hdesc -> bNumDescriptors - 1 ));
1057+
10551058 hid -> quirks |= quirks ;
10561059
10571060 return 0 ;
0 commit comments