Skip to content

Commit f1f7365

Browse files
author
Jiri Kosina
committed
HID: hid-sensor-custom: Fix big on-stack allocation in hid_sensor_custom_get_known()
struct hid_sensor_custom_properties is currently 384 bytes big, which consumes too much stack space for no good reason. Make it dynamically allocated. Fixes: 98c062e ("HID: hid-sensor-custom: Allow more custom iio sensors") Reported-by: kernel test robot <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent c8aca35 commit f1f7365

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

drivers/hid/hid-sensor-custom.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -911,21 +911,28 @@ hid_sensor_custom_get_known(struct hid_sensor_hub_device *hsdev,
911911
int ret;
912912
const struct hid_sensor_custom_match *match =
913913
hid_sensor_custom_known_table;
914-
struct hid_sensor_custom_properties prop;
914+
struct hid_sensor_custom_properties *prop;
915915

916-
ret = hid_sensor_custom_properties_get(hsdev, &prop);
916+
prop = kmalloc(sizeof(struct hid_sensor_custom_properties), GFP_KERNEL);
917+
if (!prop)
918+
return -ENOMEM;
919+
920+
ret = hid_sensor_custom_properties_get(hsdev, prop);
917921
if (ret < 0)
918-
return ret;
922+
goto out;
919923

920924
while (match->tag) {
921-
if (hid_sensor_custom_do_match(hsdev, match, &prop)) {
925+
if (hid_sensor_custom_do_match(hsdev, match, prop)) {
922926
*known = match;
923-
return 0;
927+
ret = 0;
928+
goto out;
924929
}
925930
match++;
926931
}
927-
928-
return -ENODATA;
932+
ret = -ENODATA;
933+
out:
934+
kfree(prop);
935+
return ret;
929936
}
930937

931938
static struct platform_device *

0 commit comments

Comments
 (0)