Skip to content

Commit

Permalink
HID: fix error message in hid_open_report()
Browse files Browse the repository at this point in the history
On HID report descriptor parsing error the code displays bogus
pointer instead of error offset (subtracts start=NULL from end).
Make the message more useful by displaying correct error offset
and include total buffer size for reference.

This was carried over from ancient times - "Fixed" commit just
promoted the message from DEBUG to ERROR.

Cc: [email protected]
Fixes: 8c3d52f ("HID: make parser more verbose about parsing errors by default")
Signed-off-by: Michał Mirosław <[email protected]>
Signed-off-by: Jiri Kosina <[email protected]>
  • Loading branch information
osctobe authored and Jiri Kosina committed Oct 1, 2019
1 parent 1ad0bc7 commit b3a81c7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drivers/hid/hid-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,7 @@ int hid_open_report(struct hid_device *device)
__u8 *start;
__u8 *buf;
__u8 *end;
__u8 *next;
int ret;
static int (*dispatch_type[])(struct hid_parser *parser,
struct hid_item *item) = {
Expand Down Expand Up @@ -1192,7 +1193,8 @@ int hid_open_report(struct hid_device *device)
device->collection_size = HID_DEFAULT_NUM_COLLECTIONS;

ret = -EINVAL;
while ((start = fetch_item(start, end, &item)) != NULL) {
while ((next = fetch_item(start, end, &item)) != NULL) {
start = next;

if (item.format != HID_ITEM_FORMAT_SHORT) {
hid_err(device, "unexpected long global item\n");
Expand Down Expand Up @@ -1230,7 +1232,8 @@ int hid_open_report(struct hid_device *device)
}
}

hid_err(device, "item fetching failed at offset %d\n", (int)(end - start));
hid_err(device, "item fetching failed at offset %u/%u\n",
size - (unsigned int)(end - start), size);
err:
kfree(parser->collection_stack);
alloc_err:
Expand Down

0 comments on commit b3a81c7

Please sign in to comment.