Re: [PATCH] HID: hid-sensor-hub: avoid lock inversion in sensor_hub_remove()
From: Arnav Kapoor
Date: Thu Nov 19 2026 - 15:16:08 EST
On Fri, Nov 20, 2026 at 12:50:46AM +0530, Ayaan Mirza Baig wrote:
> Move spin_lock_irqsave()/spin_unlock_irqrestore() into
> sensor_hub_finalize_pending_fn() and pass data through
> device_for_each_child(), so &data->lock is only held while inspecting
> and completing each child's pending state after klist_next() releases
> &k->k_lock.
...
> static int sensor_hub_finalize_pending_fn(struct device *dev, void *data)
> {
> struct hid_sensor_hub_device *hsdev = dev->platform_data;
> + struct sensor_hub_data *sd = data;
> + unsigned long flags;
>
> + spin_lock_irqsave(&sd->lock, flags);
...
> device_for_each_child(&hdev->dev, NULL,
> sensor_hub_finalize_pending_fn);
The commit message says data is passed through device_for_each_child(),
but the call still passes NULL, so sd is NULL in the callback and
spin_lock_irqsave(&sd->lock, flags) dereferences it. That would oops on
every removal of a hub with child devices, instead of the lockdep
warning. Sashiko flags the same thing.
I think it should be:
device_for_each_child(&hdev->dev, data,
sensor_hub_finalize_pending_fn);
With that, moving the lock into the callback looks right to me: k_lock
is a plain spinlock, so it shouldn't nest inside data->lock, which
sensor_hub_raw_event() takes from interrupt context.
Could you send a v2 with that change, and say whether the syzbot
reproducer runs clean with it?
Thanks,
Arnav