Skip to content

Commit 52cd190

Browse files
author
Benjamin Tissoires
committed
HID: core: save one kmemdup during .probe()
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 <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Benjamin Tissoires <[email protected]>
1 parent 8b7fd6a commit 52cd190

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

drivers/hid/hid-core.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ int hid_open_report(struct hid_device *device)
12141214
struct hid_item item;
12151215
unsigned int size;
12161216
const __u8 *start;
1217-
__u8 *buf;
1217+
__u8 *buf = NULL;
12181218
const __u8 *end;
12191219
const __u8 *next;
12201220
int ret;
@@ -1235,14 +1235,18 @@ int hid_open_report(struct hid_device *device)
12351235
return -ENODEV;
12361236
size = device->bpf_rsize;
12371237

1238-
buf = kmemdup(start, size, GFP_KERNEL);
1239-
if (buf == NULL)
1240-
return -ENOMEM;
1238+
if (device->driver->report_fixup) {
1239+
/*
1240+
* device->driver->report_fixup() needs to work
1241+
* on a copy of our report descriptor so it can
1242+
* change it.
1243+
*/
1244+
buf = kmemdup(start, size, GFP_KERNEL);
1245+
if (buf == NULL)
1246+
return -ENOMEM;
12411247

1242-
if (device->driver->report_fixup)
12431248
start = device->driver->report_fixup(device, buf, &size);
1244-
else
1245-
start = buf;
1249+
}
12461250

12471251
start = kmemdup(start, size, GFP_KERNEL);
12481252
kfree(buf);

0 commit comments

Comments
 (0)