diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c index cb7713646e21..b995bbe0811f 100644 --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c @@ -518,6 +518,18 @@ int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev, int i; hid_sensor_get_reporting_interval(hsdev, usage_id, st); + value = hid_sensor_read_poll_value(st); + if (value > 0) { + unsigned long max_sleep_ms = 120 * MSEC_PER_SEC; /* default hung task timeout */ + + if (IS_ENABLED(CONFIG_DETECT_HUNG_TASK) && CONFIG_DEFAULT_HUNG_TASK_TIMEOUT > 0) + max_sleep_ms = CONFIG_DEFAULT_HUNG_TASK_TIMEOUT * MSEC_PER_SEC; + + if (value * 2 >= max_sleep_ms) { + hid_err(hsdev->hdev, "Invalid sampling interval, will cause task hangs\n"); + return -EINVAL; + } + } sensor_hub_input_get_attribute_info(hsdev, HID_FEATURE_REPORT, usage_id,