On Sun, 2026-11-29 at 12:26 -0500, Shan Rizvi wrote: > On Sun, 2026-11-29 at 06:37 -0800, Srinivas Pandruvada wrote: > > Try this: > > > > Replace: > >     if (state && poll_value) > >         msleep_interruptible(poll_value * 2); > > > > with > > > > if (state && poll_value > 0) { > > unsigned long max_sleep_ms = 120 * MSEC_PER_SEC; > > unsigned long sleep_ms; > > > > 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 (poll_value * 2 > max_sleep_ms) > > return -EIO; > > > > sleep_ms = min_t(u64, (u64)poll_value * 2, max_sleep_ms); > > msleep_interruptible(sleep_ms); > > } > > Thanks for the quick reply! > > I built and tested this on the HP 8EA2 laptop (with (u64)poll_value * > 2 > in the if condition as well, since poll_value is s32 and REPORT_ID 17 > declares max=2147483647, so s32 * 2 could overflow). > > Good news: > - The multi-hour stall and rpm_resume() D-state hang on >   HID-SENSOR-200011.6.auto are gone, and the working 10 Hz proximity >   sensor (HID-SENSOR-200011.3.auto) and ALS (HID-SENSOR- > 200041.4.auto) >   continue to work normally. > > However, testing turned up a side effect from returning -EIO inside > _hid_sensor_power_state(): > > Every read of HID-SENSOR-200011.6.auto now triggers a runtime PM > underflow in dmesg: > >   hid_sensor_prox HID-SENSOR-200011.6.auto: Runtime PM usage count > underflow! > > Tracing why: > 1. drivers/iio/light/hid-sensor-prox.c:prox_read_raw() (lines 93, > 103) >    calls hid_sensor_power_state(..., true) without checking the > return >    value, proceeds into sensor_hub_input_attr_get_raw_value() (~5s > sync >    timeout -> returns 0), and then unconditionally calls >    hid_sensor_power_state(..., false). Because >    pm_runtime_resume_and_get() already dropped the usage count on - > EIO, >    the paired pm_runtime_put_autosuspend() underflows on every read. > 2. Returning -EIO at line 146 also runs after > sensor_hub_device_open(), >    atomic_inc(&st->data_ready), powering the sensor to D0/ALL_EVENTS, >    and atomic_inc(&st->user_requested_state) in > hid_sensor_power_state() >    without unwinding them on the error path (affecting callers like >    buffer_postenable() that do check the return value), and latches >    dev->power.runtime_error = -EIO. > > Two small additional notes: > - Capping sleep_ms to CONFIG_DEFAULT_HUNG_TASK_TIMEOUT (120s) could >   still let a concurrent reader in rpm_resume() trip the 120s hung- > task >   warning if a device reports e.g. poll_value = 60000 ms; capping > lower >   (or returning 0 after a smaller clamped sleep, e.g. a few seconds) >   would avoid both the hung-task warning and the -EIO > unwind/underflow >   issues above. > - While unloading the unpatched stock module before this test, >   modprobe -r hid_sensor_prox also hit the same multi-hour >   msleep_interruptible() stall via __device_release_driver() -> >   pm_runtime_get_sync() -> hid_sensor_runtime_resume() once runtime > PM >   had previously been enabled on HID-SENSOR-200011.6.auto (woken by >   SIGINT). > > Would you prefer: > (a) clamping the sleep in _hid_sensor_power_state() and returning 0 >     (no runtime PM error/underflow, e.g. capping at a few seconds or >     half of hung_task timeout), or > (b) keeping the -EIO rejection, checking poll_value before >     sensor_hub_device_open() (and decrementing user_requested_state > on >     failure), plus checking hid_sensor_power_state() return values in >     hid-sensor-prox (and other hid-sensor-* callers)? > This may be better. Try the attached: Thanks, Srinivas > Happy to test either approach on this hardware and send a patch if > you'd > like. > > Thanks, > Shan Rizvi