diff options
Diffstat (limited to 'payloads/libpayload/drivers/usb/usbhid.c')
-rw-r--r-- | payloads/libpayload/drivers/usb/usbhid.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/payloads/libpayload/drivers/usb/usbhid.c b/payloads/libpayload/drivers/usb/usbhid.c index 0785df7b58..7ae40a8b35 100644 --- a/payloads/libpayload/drivers/usb/usbhid.c +++ b/payloads/libpayload/drivers/usb/usbhid.c @@ -449,14 +449,18 @@ usb_hid_init (usbdev_t *dev) usb_hid_set_idle(dev, interface, KEYBOARD_REPEAT_MS); usb_debug (" activating...\n"); - HID_INST (dev)->descriptor = - (hid_descriptor_t *) - get_descriptor(dev, gen_bmRequestType - (device_to_host, standard_type, iface_recp), - 0x21, 0, 0); - countrycode = HID_INST(dev)->descriptor->bCountryCode; + hid_descriptor_t *desc = malloc(sizeof(hid_descriptor_t)); + if (!desc || get_descriptor(dev, gen_bmRequestType( + device_to_host, standard_type, iface_recp), + 0x21, 0, desc, sizeof(*desc)) != sizeof(desc)) { + usb_debug ("get_descriptor(HID) failed\n"); + usb_detach_device (dev->controller, dev->address); + return; + } + HID_INST (dev)->descriptor = desc; + countrycode = desc->bCountryCode; /* 35 countries defined: */ - if (countrycode > 35) + if (countrycode >= ARRAY_SIZE(countries)) countrycode = 0; usb_debug (" Keyboard has %s layout (country code %02x)\n", countries[countrycode][0], countrycode); |