Skip to content

Commit 1dfa068

Browse files
osctobesmb49
authored andcommitted
HID: fix error message in hid_open_report()
BugLink: https://bugs.launchpad.net/bugs/1851550 commit b3a81c7 upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Connor Kuehl <[email protected]> Signed-off-by: Khalid Elmously <[email protected]>
1 parent 6083d13 commit 1dfa068

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/hid/hid-core.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,7 @@ int hid_open_report(struct hid_device *device)
11391139
__u8 *start;
11401140
__u8 *buf;
11411141
__u8 *end;
1142+
__u8 *next;
11421143
int ret;
11431144
static int (*dispatch_type[])(struct hid_parser *parser,
11441145
struct hid_item *item) = {
@@ -1192,7 +1193,8 @@ int hid_open_report(struct hid_device *device)
11921193
device->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
11931194

11941195
ret = -EINVAL;
1195-
while ((start = fetch_item(start, end, &item)) != NULL) {
1196+
while ((next = fetch_item(start, end, &item)) != NULL) {
1197+
start = next;
11961198

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

1233-
hid_err(device, "item fetching failed at offset %d\n", (int)(end - start));
1235+
hid_err(device, "item fetching failed at offset %u/%u\n",
1236+
size - (unsigned int)(end - start), size);
12341237
err:
12351238
kfree(parser->collection_stack);
12361239
alloc_err:

0 commit comments

Comments
 (0)