Skip to content

Commit

Permalink
usb: hid: obtain the requested length from wLength
Browse files Browse the repository at this point in the history
Obtain the requested length from wLength and assign the
possible length to len argument.

Signed-off-by: Johann Fischer <[email protected]>
  • Loading branch information
jfischer-no authored and nashif committed Aug 3, 2021
1 parent 315e148 commit 961d4a6
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions subsys/usb/class/hid/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ static int hid_custom_handle_req(struct usb_setup_packet *setup,
{
LOG_DBG("Standard request:"
"bRequest 0x%02x, bmRequestType 0x%02x, len %d",
setup->bRequest, setup->bmRequestType, *len);
setup->bRequest, setup->bmRequestType, setup->wLength);

if (usb_reqtype_is_to_host(setup) &&
setup->RequestType.recipient == USB_REQTYPE_RECIPIENT_INTERFACE &&
Expand Down Expand Up @@ -524,21 +524,13 @@ static int hid_custom_handle_req(struct usb_setup_packet *setup,

LOG_DBG("Return HID Descriptor");

*len = MIN(*len, hid_desc->if0_hid.bLength);
*len = MIN(setup->wLength, hid_desc->if0_hid.bLength);
*data = (uint8_t *)&hid_desc->if0_hid;
break;
case USB_DESC_HID_REPORT:
LOG_DBG("Return Report Descriptor");

/* Some buggy system may be pass a larger wLength when
* it try read HID report descriptor, although we had
* already tell it the right descriptor size.
* So truncated wLength if it doesn't match. */
if (*len != dev_data->report_size) {
LOG_WRN("len %d doesn't match "
"Report Descriptor size", *len);
*len = MIN(*len, dev_data->report_size);
}
*len = MIN(setup->wLength, dev_data->report_size);
*data = (uint8_t *)dev_data->report_desc;
break;
default:
Expand Down

0 comments on commit 961d4a6

Please sign in to comment.