* [PATCH v2] iio: temperature: hid-sensor-temperature: switch to non-devm iio_device_register()
@ 2026-06-25 12:16 Sanjay Chitroda
2026-07-08 13:50 ` Sanjay Chitroda
2026-07-08 23:25 ` srinivas pandruvada
0 siblings, 2 replies; 4+ messages in thread
From: Sanjay Chitroda @ 2026-06-25 12:16 UTC (permalink / raw)
To: jikos, jic23, srinivas.pandruvada
Cc: dlechner, nuno.sa, andy, hongyan.song, linux-input, linux-iio,
linux-kernel
From: Sanjay Chitroda <sanjayembeddedse@gmail.com>
Avoid using devm_iio_device_register(), as this driver requires explicit
error handling and teardown ordering.
With devm_iio_device_register(), IIO device remains registered until the
devres cleanup phase. However, driver's remove() callback removes the
sensor hub callback and trigger support. This can create a race window
where IIO device is still visible and read_raw() requests are issued.
These requests might call sensor_hub_input_attr_get_raw_value(), which
waits up to 5 seconds for a response from the sensor hub callback that
has already been removed.
Add an explicit iio_device_unregister() call in the teardown path to
ensure deterministic cleanup, so that userspace can no longer access the
device once backend resources begin to be dismantled.
Fixes: 59d0f2da3569 ("iio: hid: Add temperature sensor support")
Cc: stable@vger.kernel.org
Reviewed-by: Maxwell Doose <m32285159@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Sanjay Chitroda <sanjayembeddedse@gmail.com>
---
Changes in v2:
- Added review tags of Maxwell and Andy along with stable Cc
- Based on input from Srinivas and investigation use-after-free
explanation was not sufficiently justified so updated the commit
message with appropriate information and kept Fixes tag
- Link to v1: https://lore.kernel.org/all/20260622052135.1804135-1-sanjayembedded@gmail.com
---
drivers/iio/temperature/hid-sensor-temperature.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/temperature/hid-sensor-temperature.c b/drivers/iio/temperature/hid-sensor-temperature.c
index a8d3a15f9c53..ab6ec8f659b8 100644
--- a/drivers/iio/temperature/hid-sensor-temperature.c
+++ b/drivers/iio/temperature/hid-sensor-temperature.c
@@ -244,7 +244,7 @@ static int hid_temperature_probe(struct platform_device *pdev)
if (ret)
goto error_remove_trigger;
- ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev);
+ ret = iio_device_register(indio_dev);
if (ret)
goto error_remove_callback;
@@ -264,6 +264,7 @@ static void hid_temperature_remove(struct platform_device *pdev)
struct iio_dev *indio_dev = platform_get_drvdata(pdev);
struct temperature_state *temp_st = iio_priv(indio_dev);
+ iio_device_unregister(indio_dev);
sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TEMPERATURE);
hid_sensor_remove_trigger(indio_dev, &temp_st->common_attributes);
}
--
--
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] iio: temperature: hid-sensor-temperature: switch to non-devm iio_device_register()
2026-06-25 12:16 [PATCH v2] iio: temperature: hid-sensor-temperature: switch to non-devm iio_device_register() Sanjay Chitroda
@ 2026-07-08 13:50 ` Sanjay Chitroda
2026-07-08 23:25 ` srinivas pandruvada
1 sibling, 0 replies; 4+ messages in thread
From: Sanjay Chitroda @ 2026-07-08 13:50 UTC (permalink / raw)
To: jikos, jic23, srinivas.pandruvada
Cc: dlechner, nuno.sa, andy, hongyan.song, linux-input, linux-iio,
linux-kernel
On 25 June 2026 5:46:11 pm IST, Sanjay Chitroda <sanjayembeddedse@gmail.com> wrote:
>From: Sanjay Chitroda <sanjayembeddedse@gmail.com>
>
>Avoid using devm_iio_device_register(), as this driver requires explicit
>error handling and teardown ordering.
>
>With devm_iio_device_register(), IIO device remains registered until the
>devres cleanup phase. However, driver's remove() callback removes the
>sensor hub callback and trigger support. This can create a race window
>where IIO device is still visible and read_raw() requests are issued.
>These requests might call sensor_hub_input_attr_get_raw_value(), which
>waits up to 5 seconds for a response from the sensor hub callback that
>has already been removed.
>
>Add an explicit iio_device_unregister() call in the teardown path to
>ensure deterministic cleanup, so that userspace can no longer access the
>device once backend resources begin to be dismantled.
>
>Fixes: 59d0f2da3569 ("iio: hid: Add temperature sensor support")
>Cc: stable@vger.kernel.org
>Reviewed-by: Maxwell Doose <m32285159@gmail.com>
>Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
>Signed-off-by: Sanjay Chitroda <sanjayembeddedse@gmail.com>
>
Hi Jonathan,
There are two pre-existing issue highlighted by Sashiko which can be analysed and fix in separate change if required.
Requesting your valuable input on this fix. also, this is pre-requisite for HID IIO devm conversation series.
Thanks, Sanjay
>---
>Changes in v2:
>- Added review tags of Maxwell and Andy along with stable Cc
>- Based on input from Srinivas and investigation use-after-free
> explanation was not sufficiently justified so updated the commit
> message with appropriate information and kept Fixes tag
>- Link to v1: https://lore.kernel.org/all/20260622052135.1804135-1-sanjayembedded@gmail.com
>---
> drivers/iio/temperature/hid-sensor-temperature.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
>diff --git a/drivers/iio/temperature/hid-sensor-temperature.c b/drivers/iio/temperature/hid-sensor-temperature.c
>index a8d3a15f9c53..ab6ec8f659b8 100644
>--- a/drivers/iio/temperature/hid-sensor-temperature.c
>+++ b/drivers/iio/temperature/hid-sensor-temperature.c
>@@ -244,7 +244,7 @@ static int hid_temperature_probe(struct platform_device *pdev)
> if (ret)
> goto error_remove_trigger;
>
>- ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev);
>+ ret = iio_device_register(indio_dev);
> if (ret)
> goto error_remove_callback;
>
>@@ -264,6 +264,7 @@ static void hid_temperature_remove(struct platform_device *pdev)
> struct iio_dev *indio_dev = platform_get_drvdata(pdev);
> struct temperature_state *temp_st = iio_priv(indio_dev);
>
>+ iio_device_unregister(indio_dev);
> sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TEMPERATURE);
> hid_sensor_remove_trigger(indio_dev, &temp_st->common_attributes);
> }
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] iio: temperature: hid-sensor-temperature: switch to non-devm iio_device_register()
2026-06-25 12:16 [PATCH v2] iio: temperature: hid-sensor-temperature: switch to non-devm iio_device_register() Sanjay Chitroda
2026-07-08 13:50 ` Sanjay Chitroda
@ 2026-07-08 23:25 ` srinivas pandruvada
2026-07-11 22:30 ` Jonathan Cameron
1 sibling, 1 reply; 4+ messages in thread
From: srinivas pandruvada @ 2026-07-08 23:25 UTC (permalink / raw)
To: Sanjay Chitroda, jikos, jic23
Cc: dlechner, nuno.sa, andy, hongyan.song, linux-input, linux-iio,
linux-kernel
On Thu, 2026-06-25 at 17:46 +0530, Sanjay Chitroda wrote:
> From: Sanjay Chitroda <sanjayembeddedse@gmail.com>
>
> Avoid using devm_iio_device_register(), as this driver requires
> explicit
> error handling and teardown ordering.
>
> With devm_iio_device_register(), IIO device remains registered until
> the
> devres cleanup phase. However, driver's remove() callback removes the
> sensor hub callback and trigger support. This can create a race
> window
> where IIO device is still visible and read_raw() requests are issued.
> These requests might call sensor_hub_input_attr_get_raw_value(),
> which
> waits up to 5 seconds for a response from the sensor hub callback
> that
> has already been removed.
>
> Add an explicit iio_device_unregister() call in the teardown path to
> ensure deterministic cleanup, so that userspace can no longer access
> the
> device once backend resources begin to be dismantled.
>
> Fixes: 59d0f2da3569 ("iio: hid: Add temperature sensor support")
> Cc: stable@vger.kernel.org
> Reviewed-by: Maxwell Doose <m32285159@gmail.com>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> Signed-off-by: Sanjay Chitroda <sanjayembeddedse@gmail.com>
>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> ---
> Changes in v2:
> - Added review tags of Maxwell and Andy along with stable Cc
> - Based on input from Srinivas and investigation use-after-free
> explanation was not sufficiently justified so updated the commit
> message with appropriate information and kept Fixes tag
> - Link to v1:
> https://lore.kernel.org/all/20260622052135.1804135-1-sanjayembedded@gmail.com
> ---
> drivers/iio/temperature/hid-sensor-temperature.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/temperature/hid-sensor-temperature.c
> b/drivers/iio/temperature/hid-sensor-temperature.c
> index a8d3a15f9c53..ab6ec8f659b8 100644
> --- a/drivers/iio/temperature/hid-sensor-temperature.c
> +++ b/drivers/iio/temperature/hid-sensor-temperature.c
> @@ -244,7 +244,7 @@ static int hid_temperature_probe(struct
> platform_device *pdev)
> if (ret)
> goto error_remove_trigger;
>
> - ret = devm_iio_device_register(indio_dev->dev.parent,
> indio_dev);
> + ret = iio_device_register(indio_dev);
> if (ret)
> goto error_remove_callback;
>
> @@ -264,6 +264,7 @@ static void hid_temperature_remove(struct
> platform_device *pdev)
> struct iio_dev *indio_dev = platform_get_drvdata(pdev);
> struct temperature_state *temp_st = iio_priv(indio_dev);
>
> + iio_device_unregister(indio_dev);
> sensor_hub_remove_callback(hsdev,
> HID_USAGE_SENSOR_TEMPERATURE);
> hid_sensor_remove_trigger(indio_dev, &temp_st-
> >common_attributes);
> }
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] iio: temperature: hid-sensor-temperature: switch to non-devm iio_device_register()
2026-07-08 23:25 ` srinivas pandruvada
@ 2026-07-11 22:30 ` Jonathan Cameron
0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2026-07-11 22:30 UTC (permalink / raw)
To: srinivas pandruvada
Cc: Sanjay Chitroda, jikos, dlechner, nuno.sa, andy, hongyan.song,
linux-input, linux-iio, linux-kernel
On Wed, 08 Jul 2026 16:25:41 -0700
srinivas pandruvada <srinivas.pandruvada@linux.intel.com> wrote:
> On Thu, 2026-06-25 at 17:46 +0530, Sanjay Chitroda wrote:
> > From: Sanjay Chitroda <sanjayembeddedse@gmail.com>
> >
> > Avoid using devm_iio_device_register(), as this driver requires
> > explicit
> > error handling and teardown ordering.
> >
> > With devm_iio_device_register(), IIO device remains registered until
> > the
> > devres cleanup phase. However, driver's remove() callback removes the
> > sensor hub callback and trigger support. This can create a race
> > window
> > where IIO device is still visible and read_raw() requests are issued.
> > These requests might call sensor_hub_input_attr_get_raw_value(),
> > which
> > waits up to 5 seconds for a response from the sensor hub callback
> > that
> > has already been removed.
> >
> > Add an explicit iio_device_unregister() call in the teardown path to
> > ensure deterministic cleanup, so that userspace can no longer access
> > the
> > device once backend resources begin to be dismantled.
> >
> > Fixes: 59d0f2da3569 ("iio: hid: Add temperature sensor support")
> > Cc: stable@vger.kernel.org
> > Reviewed-by: Maxwell Doose <m32285159@gmail.com>
> > Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> > Signed-off-by: Sanjay Chitroda <sanjayembeddedse@gmail.com>
> >
>
> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Applied to the fixes-togreg branch of iio.git.
Note that to take anything non fix related on top of this will require
me waiting until this is upstream. I'm not sure how many fixes
I'll have outstanding (and so if I will soon reach critical mass)
but most likely that will be at least a few weeks at least.
Thanks
Jonathan
>
> > ---
> > Changes in v2:
> > - Added review tags of Maxwell and Andy along with stable Cc
> > - Based on input from Srinivas and investigation use-after-free
> > explanation was not sufficiently justified so updated the commit
> > message with appropriate information and kept Fixes tag
> > - Link to v1:
> > https://lore.kernel.org/all/20260622052135.1804135-1-sanjayembedded@gmail.com
> > ---
> > drivers/iio/temperature/hid-sensor-temperature.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/iio/temperature/hid-sensor-temperature.c
> > b/drivers/iio/temperature/hid-sensor-temperature.c
> > index a8d3a15f9c53..ab6ec8f659b8 100644
> > --- a/drivers/iio/temperature/hid-sensor-temperature.c
> > +++ b/drivers/iio/temperature/hid-sensor-temperature.c
> > @@ -244,7 +244,7 @@ static int hid_temperature_probe(struct
> > platform_device *pdev)
> > if (ret)
> > goto error_remove_trigger;
> >
> > - ret = devm_iio_device_register(indio_dev->dev.parent,
> > indio_dev);
> > + ret = iio_device_register(indio_dev);
> > if (ret)
> > goto error_remove_callback;
> >
> > @@ -264,6 +264,7 @@ static void hid_temperature_remove(struct
> > platform_device *pdev)
> > struct iio_dev *indio_dev = platform_get_drvdata(pdev);
> > struct temperature_state *temp_st = iio_priv(indio_dev);
> >
> > + iio_device_unregister(indio_dev);
> > sensor_hub_remove_callback(hsdev,
> > HID_USAGE_SENSOR_TEMPERATURE);
> > hid_sensor_remove_trigger(indio_dev, &temp_st-
> > >common_attributes);
> > }
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-11 22:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-25 12:16 [PATCH v2] iio: temperature: hid-sensor-temperature: switch to non-devm iio_device_register() Sanjay Chitroda
2026-07-08 13:50 ` Sanjay Chitroda
2026-07-08 23:25 ` srinivas pandruvada
2026-07-11 22:30 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome