Skip to content

Commit

Permalink
usb: device_next: usbd_hid: Fix size in HID report get
Browse files Browse the repository at this point in the history
Since UDC buffers are allocated with `UDC_BUF_GRANULARITY` granularity,
the `net_buf_tailroom` may no longer be equal to the HID report size.
Use `setup->wLength` instead to ensure that proper HID report size is
passed to the application's callback.

Signed-off-by: Marek Pieta <[email protected]>
  • Loading branch information
MarekPieta committed Sep 25, 2024
1 parent 7cf5dd9 commit fc7b40a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions subsys/usb/device_next/class/usbd_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ static int handle_get_report(const struct device *dev,
const uint8_t id = HID_GET_REPORT_ID(setup->wValue);
struct hid_device_data *const ddata = dev->data;
const struct hid_device_ops *ops = ddata->ops;
const size_t size = net_buf_tailroom(buf);
const size_t size = setup->wLength;
int ret = 0;

switch (type) {
Expand All @@ -257,8 +257,9 @@ static int handle_get_report(const struct device *dev,
}

if (ret > 0) {
__ASSERT(ret <= size, "Buffer overflow in the HID driver");
net_buf_add(buf, MIN(size, ret));
__ASSERT(ret <= net_buf_tailroom(buf),
"Buffer overflow in the HID driver");
net_buf_add(buf, MIN(net_buf_tailroom(buf), ret));

Check notice on line 262 in subsys/usb/device_next/class/usbd_hid.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/usb/device_next/class/usbd_hid.c:262 - __ASSERT(ret <= net_buf_tailroom(buf), - "Buffer overflow in the HID driver"); + __ASSERT(ret <= net_buf_tailroom(buf), "Buffer overflow in the HID driver");
} else {
errno = ret ? ret : -ENOTSUP;
}
Expand Down

0 comments on commit fc7b40a

Please sign in to comment.