Re: [PATCH v3 2/3] iio: temperature: hid-sensor-temperature: Use per-instance callbacks

From: Andy Shevchenko

Date: Mon Oct 19 2026 - 06:58:08 EST


On Sun, Oct 18, 2026 at 07:34:19PM -0700, Christopher Hoover wrote:
> hid-sensor-temperature keeps a single static struct
> hid_sensor_hub_callbacks for all instances and overwrites its pdev in
> every probe. With two temperature sensors, input reports for one are
> delivered with the other's platform device; once that device is
> removed, platform_get_drvdata() returns NULL and
> temperature_capture_sample() dereferences it:
>
> BUG: kernel NULL pointer dereference, address: 00000000000003a8
> RIP: 0010:temperature_capture_sample+0xd/0x50 [hid_sensor_temperature]
>
> The oops happens in sensor_hub_raw_event() with the hub's spinlock
> held, so the hub's removal then hangs. It reproduces with two uhid
> devices that each declare a temperature sensor, one destroyed while
> the other still sends input reports.
>
> Keep the callbacks in struct temperature_state, as the other HID
> sensor drivers (accel, gyro, als, ...) do.

...

> struct temperature_state {
> struct hid_sensor_common common_attributes;
> + struct hid_sensor_hub_callbacks callbacks;
> struct hid_sensor_hub_attribute_info temperature_attr;

To me sounds like this new member is misplaced. The _attributes and _attr
current members kinda tighten to each other, while callbacks is separate from
this "group".

> struct {
> s32 temperature_data;

No need to resend just for this, I hope Jonathan will tweak this whilst
applying.

--
With Best Regards,
Andy Shevchenko