RE: [PATCH v2] HID: sensor-hub: Avoid holding spinlock across child iteration

From: Zhang, Lixu

Date: Sun Nov 22 2026 - 21:39:55 EST


>-----Original Message-----
>From: Srinivas Pandruvada <srinivas.pandruvada@xxxxxxxxxxxxxxx>
>Sent: Friday, November 20, 2026 11:12 PM
>To: Zheng Shuhao <viennaoffh@xxxxxxxxx>; linux-input@xxxxxxxxxxxxxxx;
>Zhang, Lixu <lixu.zhang@xxxxxxxxx>
>Cc: jikos@xxxxxxxxxx; jic23@xxxxxxxxxx; bentiss@xxxxxxxxxx; heiko@xxxxxxxxx;
>lee@xxxxxxxxxx; linux-iio@xxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx;
>ayaanmirzabaig85@xxxxxxxxx;
>syzbot+fb951970a334aaff00ba@xxxxxxxxxxxxxxxxxxxxxxxxx
>Subject: Re: [PATCH v2] HID: sensor-hub: Avoid holding spinlock across child
>iteration
>
>+Lixu
>
>On Fri, 2026-11-20 at 21:50 +0800, Zheng Shuhao wrote:
>> sensor_hub_remove() holds sensor_data->lock while walking the HID
>> device's children with device_for_each_child(). The child iteration
>> takes the device core's klist lock, while sensor_hub_raw_event() takes
>> sensor_data->lock with interrupts disabled. This creates a lock-order
>> inversion.
>>
>> Pass sensor_data to the callback and take the lock only while
>> examining pending.status and completing pending.ready.
>>
>> The callback also visits non-Sensor Hub children. When HID battery
>> strength support is enabled, the HID input layer may register a
>> power-supply child without platform_data. Skip children without Sensor
>> Hub data before dereferencing it.
>>
>> Testing:
>> - With CONFIG_HID_BATTERY_STRENGTH=y, ran a UHID Sensor Hub/Joystick
>> device
>>   exposing Battery Strength through 15 create/destroy cycles across
>> three
>>   QEMU boots. The power-supply child was found each time; no Oops,
>> BUG, or
>>   KASAN report occurred.
>> - In the same configuration, hid_bpf passed 45 tests with 1 skip,
>> hidraw
>>   passed 27 tests, and hid-core, hid-apple, hid-gamepad, hid-ite,
>>   hid-keyboard, and hid-mouse passed.
>> - The full HID suite was not completed; it stopped during hid-
>> multitouch.
>> - The #syz test request was rejected because syzbot's automated patch
>>   testing is temporarily unavailable.
>
>None of the above tested devices are HID SENSOR HUB related, so need some
>tests.
>Hi Lixu,
>
>Please give a try.

Hi Shuhao,

Thanks for the patch. This v2 does not apply cleanly on top of
hid/for-next due to commit 41cb3076a221 ("HID: sensor-hub: Remove
clients before stopping hardware").

Could you please rebase it on top of hid/for-next and resend as v3?
I'd be happy to test v3 and provide a Tested-by tag.

Thanks,
Lixu

>Thanks,
>Srinivas