Skip to content

Commit 88231b5

Browse files
MarekPietahenrikbrixandersen
authored andcommitted
usb: device_next: usbd_hid: Fix size in HID report get
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]>
1 parent 06d0c58 commit 88231b5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

subsys/usb/device_next/class/usbd_hid.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ static int handle_get_report(const struct device *dev,
235235
const uint8_t id = HID_GET_REPORT_ID(setup->wValue);
236236
struct hid_device_data *const ddata = dev->data;
237237
const struct hid_device_ops *ops = ddata->ops;
238-
const size_t size = net_buf_tailroom(buf);
238+
const size_t size = setup->wLength;
239239
int ret = 0;
240240

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

259259
if (ret > 0) {
260-
__ASSERT(ret <= size, "Buffer overflow in the HID driver");
261-
net_buf_add(buf, MIN(size, ret));
260+
__ASSERT(ret <= net_buf_tailroom(buf),
261+
"Buffer overflow in the HID driver");
262+
net_buf_add(buf, MIN(net_buf_tailroom(buf), ret));
262263
} else {
263264
errno = ret ? ret : -ENOTSUP;
264265
}

0 commit comments

Comments
 (0)