On Thu, 22 Dec 2022, Philipp Jungkamp wrote: > Hello, > > does this mean the problem lies in 'hid_sensor_custom_probe' itself or > could this also be caused by local variables in nested functions. > > I suspect the problem lies in 'hid_sensor_custom_get_known' where I put > an instance of 'struct hid_sensor_custom_properties' on the stack. > > This struct is way too large (I didn't know there was a upper stack > limit of 1024). It's current size is sizeof(u16) * 3 * > HID_CUSTOM_MAX_FEATURE_BYTES = 384. > > Would allocating it for the scope of 'hid_sensor_custom_get_known' make > sense? > > Which kind of kernel allocation functions should I use here? As there was no followup to this as far as I can see, I have just queued the patch below on top of the hid-sensor branch. From: Jiri Kosina <jkosina@xxxxxxx> Subject: [PATCH] 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: 98c062e824519 ("HID: hid-sensor-custom: Allow more custom iio sensors") Reported-by: kernel test robot <lkp@xxxxxxxxx> Signed-off-by: Jiri Kosina <jkosina@xxxxxxx> --- drivers/hid/hid-sensor-custom.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c index 0c287dde345c..3e3f89e01d81 100644 --- a/drivers/hid/hid-sensor-custom.c +++ b/drivers/hid/hid-sensor-custom.c @@ -911,21 +911,28 @@ hid_sensor_custom_get_known(struct hid_sensor_hub_device *hsdev, int ret; const struct hid_sensor_custom_match *match = hid_sensor_custom_known_table; - struct hid_sensor_custom_properties prop; + struct hid_sensor_custom_properties *prop; - ret = hid_sensor_custom_properties_get(hsdev, &prop); + prop = kmalloc(sizeof(struct hid_sensor_custom_properties), GFP_KERNEL); + if (!prop) + return -ENOMEM; + + ret = hid_sensor_custom_properties_get(hsdev, prop); if (ret < 0) - return ret; + goto out; while (match->tag) { - if (hid_sensor_custom_do_match(hsdev, match, &prop)) { + if (hid_sensor_custom_do_match(hsdev, match, prop)) { *known = match; - return 0; + ret = 0; + goto out; } match++; } - - return -ENODATA; + ret = -ENODATA; +out: + kfree(prop); + return ret; } static struct platform_device * -- Jiri Kosina SUSE Labs