Skip to content

Commit

Permalink
HID: core: save one kmemdup during .probe()
Browse files Browse the repository at this point in the history
Turns out the first kmemdup is only required for the .report_fixup()
driver callback. There is no need to do two kmemdup() in a row in case
.report_fixup() is not present.

Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Link: https://patch.msgid.link/20241001-hid-bpf-hid-generic-v3-2-2ef1019468df@kernel.org
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
  • Loading branch information
Benjamin Tissoires committed Oct 4, 2024
1 parent 8b7fd6a commit 52cd190
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions drivers/hid/hid-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ int hid_open_report(struct hid_device *device)
struct hid_item item;
unsigned int size;
const __u8 *start;
__u8 *buf;
__u8 *buf = NULL;
const __u8 *end;
const __u8 *next;
int ret;
Expand All @@ -1235,14 +1235,18 @@ int hid_open_report(struct hid_device *device)
return -ENODEV;
size = device->bpf_rsize;

buf = kmemdup(start, size, GFP_KERNEL);
if (buf == NULL)
return -ENOMEM;
if (device->driver->report_fixup) {
/*
* device->driver->report_fixup() needs to work
* on a copy of our report descriptor so it can
* change it.
*/
buf = kmemdup(start, size, GFP_KERNEL);
if (buf == NULL)
return -ENOMEM;

if (device->driver->report_fixup)
start = device->driver->report_fixup(device, buf, &size);
else
start = buf;
}

start = kmemdup(start, size, GFP_KERNEL);
kfree(buf);
Expand Down

0 comments on commit 52cd190

Please sign in to comment.