iio: introduce devm_ API for hid sensro setup and cleanup
Subsystems (3)
v2 cover iio: introduce devm_ API for hid sensro setup and cleanup
From: Sanjay Chitroda <[email protected]>
Key highlights:
- Prepare change as pre-requisite for devm conversion for HID IIO drivers by removing redundant argument
- Add devm API to setup trigger and clenaup resource using devm_add_action_or_reset()
- few sample driver update using devm conversion to auto release resource
changes in v2:
- Following input from Jonathan and Andy, squash initial patch v1
series in single change as individual change should not break anything
- Add devm API support and two driver using the same
- v1 series -> https://lore.kernel.org/all/[email protected]/
Testing:
- Compiled with W=1
- Build-tested on QEMU x86_64
Based on further feedback and reviews, I would extend this series to convert all HID IIO driver to use devm_* API.
Thanks,
Sanjay Chitroda
Sanjay Chitroda (4):
iio: hid-sensors: drop redundant iio_dev argument
iio: hid-sensors: introduce device managed API
iio: gyro: drop hid_sensor_remove_trigger() using devm API
iio: humidity: drop hid_sensor_remove_trigger() using devm API
drivers/iio/accel/hid-sensor-accel-3d.c | 4 +-- .../common/hid-sensors/hid-sensor-trigger.c | 27 +++++++++++++++++-- .../common/hid-sensors/hid-sensor-trigger.h | 5 ++-- drivers/iio/gyro/hid-sensor-gyro-3d.c | 10 +++---- drivers/iio/humidity/hid-sensor-humidity.c | 10 +++---- drivers/iio/light/hid-sensor-als.c | 4 +-- drivers/iio/light/hid-sensor-prox.c | 4 +-- drivers/iio/magnetometer/hid-sensor-magn-3d.c | 4 +-- drivers/iio/orientation/hid-sensor-incl-3d.c | 4 +-- drivers/iio/orientation/hid-sensor-rotation.c | 4 +-- .../position/hid-sensor-custom-intel-hinge.c | 4 +-- drivers/iio/pressure/hid-sensor-press.c | 4 +-- .../iio/temperature/hid-sensor-temperature.c | 4 +-- 13 files changed, 52 insertions(+), 36 deletions(-)
base-commit: eade2b843d9b1f668fc1775f15611bb0a1999cd9
Signature · 1 line
2.34.1
PATCH v2 1/4 iio: hid-sensors: drop redundant iio_dev argument
From: Sanjay Chitroda <[email protected]>
hid_sensor_remove_trigger() uses struct hid_sensor_common to release resources acquired during trigger setup.
Earlier implementations required struct iio_dev to clean up buffers, but with the current code this argument is no longer used and is redundant.
Adapt to hid_sensor_remove_trigger() API change across all HID IIO drivers to match updated prototype.
Removing it simplifies the API and is a preparatory step toward converting the trigger handling to a devm-based API.
--- drivers/iio/accel/hid-sensor-accel-3d.c | 4 ++-- drivers/iio/common/hid-sensors/hid-sensor-trigger.c | 3 +-- drivers/iio/common/hid-sensors/hid-sensor-trigger.h | 3 +-- drivers/iio/gyro/hid-sensor-gyro-3d.c | 4 ++-- drivers/iio/humidity/hid-sensor-humidity.c | 4 ++-- drivers/iio/light/hid-sensor-als.c | 4 ++-- drivers/iio/light/hid-sensor-prox.c | 4 ++-- drivers/iio/magnetometer/hid-sensor-magn-3d.c | 4 ++-- drivers/iio/orientation/hid-sensor-incl-3d.c | 4 ++-- drivers/iio/orientation/hid-sensor-rotation.c | 4 ++-- drivers/iio/position/hid-sensor-custom-intel-hinge.c | 4 ++-- drivers/iio/pressure/hid-sensor-press.c | 4 ++-- drivers/iio/temperature/hid-sensor-temperature.c | 4 ++-- 13 files changed, 24 insertions(+), 26 deletions(-)
drivers/iio/accel/hid-sensor-accel-3d.c +2 -2
@@ -416,7 +416,7 @@ static int hid_accel_3d_probe(struct platform_device *pdev) error_iio_unreg:iio_device_unregister (indio_dev); error_remove_trigger: -hid_sensor_remove_trigger (indio_dev, &accel_state->common_attributes); +hid_sensor_remove_trigger (&accel_state->common_attributes);return ret; }
@@ -429,7 +429,7 @@ static void hid_accel_3d_remove(struct platform_device *pdev)sensor_hub_remove_callback (hsdev, hsdev->usage);iio_device_unregister (indio_dev); -hid_sensor_remove_trigger (indio_dev, &accel_state->common_attributes); +hid_sensor_remove_trigger (&accel_state->common_attributes); }static const struct platform_device_id hid_accel_3d_ids[] = {
drivers/iio/common/hid-sensors/hid-sensor-trigger.c +1 -2
@@ -218,8 +218,7 @@ static const struct iio_buffer_setup_ops hid_sensor_buffer_ops = { .predisable = buffer_predisable, }; -void hid_sensor_remove_trigger (struct iio_dev *indio_dev, -struct hid_sensor_common *attrb) +void hid_sensor_remove_trigger (struct hid_sensor_common *attrb) {if (atomic_read (&attrb->runtime_pm_enable))pm_runtime_disable (&attrb->pdev->dev);
drivers/iio/common/hid-sensors/hid-sensor-trigger.h +1 -2
@@ -16,8 +16,7 @@ extern const struct dev_pm_ops hid_sensor_pm_ops;int hid_sensor_setup_trigger (struct iio_dev *indio_dev,const char *name,struct hid_sensor_common *attrb); -void hid_sensor_remove_trigger (struct iio_dev *indio_dev, -struct hid_sensor_common *attrb); +void hid_sensor_remove_trigger (struct hid_sensor_common *attrb);int hid_sensor_power_state (struct hid_sensor_common *st,bool state);#endif
drivers/iio/gyro/hid-sensor-gyro-3d.c +2 -2
@@ -354,7 +354,7 @@ static int hid_gyro_3d_probe(struct platform_device *pdev) error_iio_unreg:iio_device_unregister (indio_dev); error_remove_trigger: -hid_sensor_remove_trigger (indio_dev, &gyro_state->common_attributes); +hid_sensor_remove_trigger (&gyro_state->common_attributes);return ret; }
@@ -367,7 +367,7 @@ static void hid_gyro_3d_remove(struct platform_device *pdev)sensor_hub_remove_callback (hsdev,HID_USAGE_SENSOR_GYRO_3D );iio_device_unregister (indio_dev); -hid_sensor_remove_trigger (indio_dev, &gyro_state->common_attributes); +hid_sensor_remove_trigger (&gyro_state->common_attributes); }static const struct platform_device_id hid_gyro_3d_ids[] = {
drivers/iio/humidity/hid-sensor-humidity.c +2 -2
@@ -255,7 +255,7 @@ static int hid_humidity_probe(struct platform_device *pdev) error_remove_callback:sensor_hub_remove_callback (hsdev,HID_USAGE_SENSOR_HUMIDITY ); error_remove_trigger: -hid_sensor_remove_trigger (indio_dev, &humid_st->common_attributes); +hid_sensor_remove_trigger (&humid_st->common_attributes);return ret; }
@@ -268,7 +268,7 @@ static void hid_humidity_remove(struct platform_device *pdev)iio_device_unregister (indio_dev);sensor_hub_remove_callback (hsdev,HID_USAGE_SENSOR_HUMIDITY ); -hid_sensor_remove_trigger (indio_dev, &humid_st->common_attributes); +hid_sensor_remove_trigger (&humid_st->common_attributes); }static const struct platform_device_id hid_humidity_ids[] = {
drivers/iio/light/hid-sensor-als.c +2 -2
@@ -432,7 +432,7 @@ static int hid_als_probe(struct platform_device *pdev) error_iio_unreg:iio_device_unregister (indio_dev); error_remove_trigger: -hid_sensor_remove_trigger (indio_dev, &als_state->common_attributes); +hid_sensor_remove_trigger (&als_state->common_attributes);return ret; }
@@ -445,7 +445,7 @@ static void hid_als_remove(struct platform_device *pdev)sensor_hub_remove_callback (hsdev, hsdev->usage);iio_device_unregister (indio_dev); -hid_sensor_remove_trigger (indio_dev, &als_state->common_attributes); +hid_sensor_remove_trigger (&als_state->common_attributes); }static const struct platform_device_id hid_als_ids[] = {
drivers/iio/light/hid-sensor-prox.c +2 -2
@@ -340,7 +340,7 @@ static int hid_prox_probe(struct platform_device *pdev) error_iio_unreg:iio_device_unregister (indio_dev); error_remove_trigger: -hid_sensor_remove_trigger (indio_dev, &prox_state->common_attributes); +hid_sensor_remove_trigger (&prox_state->common_attributes);return ret; }
@@ -353,7 +353,7 @@ static void hid_prox_remove(struct platform_device *pdev)sensor_hub_remove_callback (hsdev, hsdev->usage);iio_device_unregister (indio_dev); -hid_sensor_remove_trigger (indio_dev, &prox_state->common_attributes); +hid_sensor_remove_trigger (&prox_state->common_attributes); }static const struct platform_device_id hid_prox_ids[] = {
drivers/iio/magnetometer/hid-sensor-magn-3d.c +2 -2
@@ -542,7 +542,7 @@ static int hid_magn_3d_probe(struct platform_device *pdev) error_iio_unreg:iio_device_unregister (indio_dev); error_remove_trigger: -hid_sensor_remove_trigger (indio_dev, &magn_state->magn_flux_attributes); +hid_sensor_remove_trigger (&magn_state->magn_flux_attributes);return ret; }
@@ -555,7 +555,7 @@ static void hid_magn_3d_remove(struct platform_device *pdev)sensor_hub_remove_callback (hsdev,HID_USAGE_SENSOR_COMPASS_3D );iio_device_unregister (indio_dev); -hid_sensor_remove_trigger (indio_dev, &magn_state->magn_flux_attributes); +hid_sensor_remove_trigger (&magn_state->magn_flux_attributes); }static const struct platform_device_id hid_magn_3d_ids[] = {
drivers/iio/orientation/hid-sensor-incl-3d.c +2 -2
@@ -378,7 +378,7 @@ static int hid_incl_3d_probe(struct platform_device *pdev) error_iio_unreg:iio_device_unregister (indio_dev); error_remove_trigger: -hid_sensor_remove_trigger (indio_dev, &incl_state->common_attributes); +hid_sensor_remove_trigger (&incl_state->common_attributes);return ret; }
@@ -391,7 +391,7 @@ static void hid_incl_3d_remove(struct platform_device *pdev)sensor_hub_remove_callback (hsdev,HID_USAGE_SENSOR_INCLINOMETER_3D );iio_device_unregister (indio_dev); -hid_sensor_remove_trigger (indio_dev, &incl_state->common_attributes); +hid_sensor_remove_trigger (&incl_state->common_attributes); }static const struct platform_device_id hid_incl_3d_ids[] = {
drivers/iio/orientation/hid-sensor-rotation.c +2 -2
@@ -353,7 +353,7 @@ static int hid_dev_rot_probe(struct platform_device *pdev) error_iio_unreg:iio_device_unregister (indio_dev); error_remove_trigger: -hid_sensor_remove_trigger (indio_dev, &rot_state->common_attributes); +hid_sensor_remove_trigger (&rot_state->common_attributes);return ret; }
@@ -366,7 +366,7 @@ static void hid_dev_rot_remove(struct platform_device *pdev)sensor_hub_remove_callback (hsdev, hsdev->usage);iio_device_unregister (indio_dev); -hid_sensor_remove_trigger (indio_dev, &rot_state->common_attributes); +hid_sensor_remove_trigger (&rot_state->common_attributes); }static const struct platform_device_id hid_dev_rot_ids[] = {
drivers/iio/position/hid-sensor-custom-intel-hinge.c +2 -2
@@ -337,7 +337,7 @@ static int hid_hinge_probe(struct platform_device *pdev) error_remove_callback:sensor_hub_remove_callback (hsdev, hsdev->usage); error_remove_trigger: -hid_sensor_remove_trigger (indio_dev, &st->common_attributes); +hid_sensor_remove_trigger (&st->common_attributes);return ret; }
@@ -350,7 +350,7 @@ static void hid_hinge_remove(struct platform_device *pdev)iio_device_unregister (indio_dev);sensor_hub_remove_callback (hsdev, hsdev->usage); -hid_sensor_remove_trigger (indio_dev, &st->common_attributes); +hid_sensor_remove_trigger (&st->common_attributes); }static const struct platform_device_id hid_hinge_ids[] = {
drivers/iio/pressure/hid-sensor-press.c +2 -2
@@ -319,7 +319,7 @@ static int hid_press_probe(struct platform_device *pdev) error_iio_unreg:iio_device_unregister (indio_dev); error_remove_trigger: -hid_sensor_remove_trigger (indio_dev, &press_state->common_attributes); +hid_sensor_remove_trigger (&press_state->common_attributes);return ret; }
@@ -332,7 +332,7 @@ static void hid_press_remove(struct platform_device *pdev)sensor_hub_remove_callback (hsdev,HID_USAGE_SENSOR_PRESSURE );iio_device_unregister (indio_dev); -hid_sensor_remove_trigger (indio_dev, &press_state->common_attributes); +hid_sensor_remove_trigger (&press_state->common_attributes); }static const struct platform_device_id hid_press_ids[] = {
drivers/iio/temperature/hid-sensor-temperature.c +2 -2
@@ -253,7 +253,7 @@ static int hid_temperature_probe(struct platform_device *pdev) error_remove_callback:sensor_hub_remove_callback (hsdev,HID_USAGE_SENSOR_TEMPERATURE ); error_remove_trigger: -hid_sensor_remove_trigger (indio_dev, &temp_st->common_attributes); +hid_sensor_remove_trigger (&temp_st->common_attributes);return ret; }
@@ -265,7 +265,7 @@ static void hid_temperature_remove(struct platform_device *pdev)struct temperature_state *temp_st =iio_priv (indio_dev);sensor_hub_remove_callback (hsdev,HID_USAGE_SENSOR_TEMPERATURE ); -hid_sensor_remove_trigger (indio_dev, &temp_st->common_attributes); +hid_sensor_remove_trigger (&temp_st->common_attributes); }static const struct platform_device_id hid_temperature_ids[] = {
Signature · 1 line
2.34.1
PATCH v2 2/4 iio: hid-sensors: introduce device managed API
In reply to Sanjay ChitrodaFrom: Sanjay Chitroda <[email protected]>
hid_sensor_setup_trigger() is common API used for the HID IIO drivers, prepare devm API devm_hid_sensor_setup_trigger() to acquire resource during setup and release using device managed framework during drivers fail, unbind or remove path.
Register action with devm_add_action_or_reset() to release resource with devres framework.
--- .../common/hid-sensors/hid-sensor-trigger.c | 24 +++++++++++++++++++ .../common/hid-sensors/hid-sensor-trigger.h | 2 ++ 2 files changed, 26 insertions(+)
drivers/iio/common/hid-sensors/hid-sensor-trigger.c +24 -0
@@ -301,6 +301,30 @@ int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name, }EXPORT_SYMBOL_NS (hid_sensor_setup_trigger,"IIO_HID" ); +static void hid_sensor_remove_trigger_action (void *ptr) +{ +struct hid_sensor_common *attrb = ptr; + +hid_sensor_remove_trigger (attrb); +} + +int devm_hid_sensor_setup_trigger (struct device *dev,struct iio_dev *indio_dev, +const char *name,struct hid_sensor_common *attrb) +{ +int ret; + + ret =hid_sensor_setup_trigger (indio_dev, name, attrb); +if (ret) +return ret; + + ret =devm_add_action_or_reset (dev, hid_sensor_remove_trigger_action, attrb); +if (ret) +return ret; + +return 0 ; +} +EXPORT_SYMBOL_NS (devm_hid_sensor_setup_trigger,"IIO_HID" ); +static int __maybe_unused hid_sensor_suspend (struct device *dev) {struct iio_dev *indio_dev =dev_get_drvdata (dev);
drivers/iio/common/hid-sensors/hid-sensor-trigger.h +2 -0
@@ -17,6 +17,8 @@ extern const struct dev_pm_ops hid_sensor_pm_ops;int hid_sensor_setup_trigger (struct iio_dev *indio_dev,const char *name,struct hid_sensor_common *attrb);void hid_sensor_remove_trigger (struct hid_sensor_common *attrb); +int devm_hid_sensor_setup_trigger (struct device *dev,struct iio_dev *indio_dev, +const char *name,struct hid_sensor_common *attrb);int hid_sensor_power_state (struct hid_sensor_common *st,bool state);#endif
Signature · 1 line
2.34.1
PATCH v2 3/4 iio: gyro: drop hid_sensor_remove_trigger() using devm API
In reply to Sanjay ChitrodaFrom: Sanjay Chitroda <[email protected]>
Use devm_hid_sensor_setup_trigger() to automatically release resource during fail, unbind or removal of driver using devres framework.
This simplify the setup, remove goto, avoid manual resource cleanup in teardown path.
--- drivers/iio/gyro/hid-sensor-gyro-3d.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/iio/gyro/hid-sensor-gyro-3d.c +3 -7
@@ -326,8 +326,8 @@ static int hid_gyro_3d_probe(struct platform_device *pdev)atomic_set (&gyro_state->common_attributes.data_ready,0 ); - ret =hid_sensor_setup_trigger (indio_dev, name, - &gyro_state->common_attributes); + ret =devm_hid_sensor_setup_trigger (&pdev->dev, indio_dev, name, + &gyro_state->common_attributes);if (ret <0 ) {dev_err (&pdev->dev,"trigger setup failed\n" );return ret;
@@ -336,7 +336,7 @@ static int hid_gyro_3d_probe(struct platform_device *pdev) ret =iio_device_register (indio_dev);if (ret) {dev_err (&pdev->dev,"device register failed\n" ); - goto error_remove_trigger; +return ret; } gyro_state->callbacks.send_event = gyro_3d_proc_event;
@@ -353,8 +353,6 @@ static int hid_gyro_3d_probe(struct platform_device *pdev) error_iio_unreg:iio_device_unregister (indio_dev); -error_remove_trigger: -hid_sensor_remove_trigger (&gyro_state->common_attributes);return ret; }
@@ -363,11 +361,9 @@ static void hid_gyro_3d_remove(struct platform_device *pdev) {struct hid_sensor_hub_device *hsdev =dev_get_platdata (&pdev->dev);struct iio_dev *indio_dev =platform_get_drvdata (pdev); -struct gyro_3d_state *gyro_state =iio_priv (indio_dev);sensor_hub_remove_callback (hsdev,HID_USAGE_SENSOR_GYRO_3D );iio_device_unregister (indio_dev); -hid_sensor_remove_trigger (&gyro_state->common_attributes); }static const struct platform_device_id hid_gyro_3d_ids[] = {
Signature · 1 line
2.34.1
PATCH v2 4/4 iio: humidity: drop hid_sensor_remove_trigger() using devm API
In reply to Sanjay ChitrodaFrom: Sanjay Chitroda <[email protected]>
Use devm_hid_sensor_setup_trigger() to automatically release resource during fail, unbind or removal of driver using devres framework.
This simplify the setup, remove goto, avoid manual resource cleanup in teardown path.
--- drivers/iio/humidity/hid-sensor-humidity.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/iio/humidity/hid-sensor-humidity.c +3 -7
@@ -233,8 +233,8 @@ static int hid_humidity_probe(struct platform_device *pdev)atomic_set (&humid_st->common_attributes.data_ready,0 ); - ret =hid_sensor_setup_trigger (indio_dev, name, - &humid_st->common_attributes); + ret =devm_hid_sensor_setup_trigger (&indio_dev->dev, indio_dev, name, + &humid_st->common_attributes);if (ret)return ret;
@@ -244,7 +244,7 @@ static int hid_humidity_probe(struct platform_device *pdev) ret =sensor_hub_register_callback (hsdev,HID_USAGE_SENSOR_HUMIDITY , &humidity_callbacks);if (ret) - goto error_remove_trigger; +return ret; ret =iio_device_register (indio_dev);if (ret)
@@ -254,8 +254,6 @@ static int hid_humidity_probe(struct platform_device *pdev) error_remove_callback:sensor_hub_remove_callback (hsdev,HID_USAGE_SENSOR_HUMIDITY ); -error_remove_trigger: -hid_sensor_remove_trigger (&humid_st->common_attributes);return ret; }
@@ -264,11 +262,9 @@ static void hid_humidity_remove(struct platform_device *pdev) {struct hid_sensor_hub_device *hsdev =dev_get_platdata (&pdev->dev);struct iio_dev *indio_dev =platform_get_drvdata (pdev); -struct hid_humidity_state *humid_st =iio_priv (indio_dev);iio_device_unregister (indio_dev);sensor_hub_remove_callback (hsdev,HID_USAGE_SENSOR_HUMIDITY ); -hid_sensor_remove_trigger (&humid_st->common_attributes); }static const struct platform_device_id hid_humidity_ids[] = {
Signature · 1 line
2.34.1
Re: [PATCH v2 2/4] iio: hid-sensors: introduce device managed API
In reply to Sanjay ChitrodaQuoted 7 lines · Sanjay Chitroda
hid_sensor_setup_trigger()is common API used for the HID IIO drivers, prepare devm APIdevm_hid_sensor_setup_trigger()to acquire resource during setup and release using device managed framework during drivers fail, unbind or remove path.Register action with
devm_add_action_or_reset()to release resource with devres framework.
...
drivers/iio/common/hid-sensors/hid-sensor-trigger.c int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name, · line 309
Quoted 6 lines
drivers/iio/common/hid-sensors/hid-sensor-trigger.c +6
-0+static void hid_sensor_remove_trigger_action (void *ptr) +{ +struct hid_sensor_common *attrb = ptr; + +hid_sensor_remove_trigger (attrb); +}
Casting is not needed here.
static void hid_sensor_remove_trigger_action(void *attrb)
{
hid_sensor_remove_trigger(attrb);
}...
Quoted 4 lines
drivers/iio/common/hid-sensors/hid-sensor-trigger.c +4
-0+int devm_hid_sensor_setup_trigger (struct device *dev,struct iio_dev *indio_dev, +const char *name,struct hid_sensor_common *attrb) +{ +int ret;
drivers/iio/common/hid-sensors/hid-sensor-trigger.c int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name, · line 324
Quoted 10 lines
drivers/iio/common/hid-sensors/hid-sensor-trigger.c +9
-0+ + ret =hid_sensor_setup_trigger (indio_dev, name, attrb); +if (ret) +return ret; + ret =devm_add_action_or_reset (dev, hid_sensor_remove_trigger_action, attrb); +if (ret) +return ret; + +return 0 ;
return devm_add_action_or_reset(dev, hid_sensor_remove_trigger_action, attrb);
Quoted 1 line
+}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 4/4] iio: humidity: drop hid_sensor_remove_trigger() using devm API
In reply to Sanjay ChitrodaQuoted 5 lines · Sanjay Chitroda
Use
devm_hid_sensor_setup_trigger()to automatically release resource during fail, unbind or removal of driver using devres framework.This simplify the setup, remove goto, avoid manual resource cleanup in teardown path.
...
drivers/iio/humidity/hid-sensor-humidity.c static int hid_humidity_probe(struct platform_device *pdev) · line 237
Quoted 4 lines
drivers/iio/humidity/hid-sensor-humidity.c +2
-2- ret =hid_sensor_setup_trigger (indio_dev, name, - &humid_st->common_attributes); + ret =devm_hid_sensor_setup_trigger (&indio_dev->dev, indio_dev, name, + &humid_st->common_attributes);
I believe the first parameter is utterly wrong here. Or other way around, same issue but in the previous patch.
Quoted 2 lines
drivers/iio/humidity/hid-sensor-humidity.c +0
-0if (ret)return ret;
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 9 lines · Sanjay Chitroda
Key highlights:
- Prepare change as pre-requisite for devm conversion for HID IIO drivers by removing redundant argument
- Add devm API to setup trigger and clenaup resource usingdevm_add_action_or_reset()
- few sample driver update using devm conversion to auto release resourceBased on further feedback and reviews, I would extend this series to convert all HID IIO driver to use devm_* API.
Not sure about this. But if people (and HID sensors maintainers in particular) are fine with this, I have no objections. There are some nit-picks and one serious problem to address, though.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 4/4] iio: humidity: drop hid_sensor_remove_trigger() using devm API
In reply to Andy ShevchenkoQuoted 10 lines · Andy Shevchenko
Quoted 5 lines · Sanjay Chitroda
Use
devm_hid_sensor_setup_trigger()to automatically release resource during fail, unbind or removal of driver using devres framework.This simplify the setup, remove goto, avoid manual resource cleanup in teardown path.
...
Quoted 8 lines
drivers/iio/humidity/hid-sensor-humidity.c static int hid_humidity_probe(struct platform_device *pdev) · line 237
Quoted 4 lines
drivers/iio/humidity/hid-sensor-humidity.c +2
-2- ret =hid_sensor_setup_trigger (indio_dev, name, - &humid_st->common_attributes); + ret =devm_hid_sensor_setup_trigger (&indio_dev->dev, indio_dev, name, + &humid_st->common_attributes);I believe the first parameter is utterly wrong here. Or other way around, same issue but in the previous patch.
Thank you Andy for the review comment.
It looks in same humidity probe of hid sensor with devm API two device pointer are used &pdev->dev and &indio_dev->dev; ideally all devm should have same parent device for devres resource framework and over here preferable and consistent device should be &pdev->dev;
I would first update existing devm_* API to have consistent device and on top of that will use same device in devm conversation.
While for gyro change device is consistent as &pdev->dev across all devm API.
Thanks,
Sanjay Chitroda
Quoted 3 lines
Quoted 2 lines
drivers/iio/humidity/hid-sensor-humidity.c +0
-0if (ret)return ret;
Re: [PATCH v2 2/4] iio: hid-sensors: introduce device managed API
In reply to Andy ShevchenkoQuoted 21 lines · Andy Shevchenko
Quoted 7 lines · Sanjay Chitroda
hid_sensor_setup_trigger()is common API used for the HID IIO drivers, prepare devm APIdevm_hid_sensor_setup_trigger()to acquire resource during setup and release using device managed framework during drivers fail, unbind or remove path.Register action with
devm_add_action_or_reset()to release resource with devres framework....
drivers/iio/common/hid-sensors/hid-sensor-trigger.c int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name, · line 309
Quoted 6 lines
drivers/iio/common/hid-sensors/hid-sensor-trigger.c +6
-0+static void hid_sensor_remove_trigger_action (void *ptr) +{ +struct hid_sensor_common *attrb = ptr; + +hid_sensor_remove_trigger (attrb); +}Casting is not needed here.
Quoted 5 lines
static void
hid_sensor_remove_trigger_action(void *attrb){ hid_sensor_remove_trigger(attrb); }
True, the cast isn’t required. I kept the typed variable for clarity and type checking on devm_add.. API which pass void * callback and remove trigger API which has struct hid_sensor_common.
Happy to simplify if preferred.
Quoted 11 lines
...
Quoted 8 lines
drivers/iio/common/hid-sensors/hid-sensor-trigger.c +8
-0+int devm_hid_sensor_setup_trigger (struct device *dev,struct iio_dev *indio_dev, +const char *name,struct hid_sensor_common *attrb) +{ +int ret; + + ret =hid_sensor_setup_trigger (indio_dev, name, attrb); +if (ret) +return ret;
Quoted 8 lines
drivers/iio/common/hid-sensors/hid-sensor-trigger.c int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name, · line 324
Quoted 5 lines
drivers/iio/common/hid-sensors/hid-sensor-trigger.c +5
-0+ ret =devm_add_action_or_reset (dev, hid_sensor_remove_trigger_action, attrb); +if (ret) +return ret; + +return 0 ;return devm_add_action_or_reset(dev, hid_sensor_remove_trigger_action, attrb);
Agree, will update in next series.
Thanks,
Sanjay Chitroda
Quoted 2 lines
Quoted 1 line
+}
srinivas pandruvada
maintainer+ Lixu
Quoted 10 lines · Sanjay Chitroda
From: Sanjay Chitroda <[email protected]>
Key highlights:
- Prepare change as pre-requisite for devm conversion for HID IIO drivers by removing redundant argument
- Add devm API to setup trigger and clenaup resource usingdevm_add_action_or_reset()
- few sample driver update using devm conversion to auto release resource
devm_* calls are fine but needs tests particularly when forces ISH PCI drivers unbind, while iio-sensor-proxy has open sessions.
Lixu, Please check.
Thanks,
Srinivas
Quoted 42 lines
changes in v2:
- Following input from Jonathan and Andy, squash initial patch v1 series in single change as individual change should not break anything
- Add devm API support and two driver using the same
- v1 series ->
https://lore.kernel.org/all/[email protected]/Testing:
- Compiled with W=1
- Build-tested on QEMUx86_64Based on further feedback and reviews, I would extend this series to convert all HID IIO driver to use devm_* API.
Thanks,
Sanjay ChitrodaSanjay Chitroda (4):
iio: hid-sensors: drop redundantiio_devargument
iio: hid-sensors: introduce device managed API
iio: gyro: drophid_sensor_remove_trigger()using devm API
iio: humidity: drophid_sensor_remove_trigger()using devm APIdrivers/iio/accel/hid-sensor-accel-3d.c | 4 +-- .../common/hid-sensors/hid-sensor-trigger.c | 27
+++++++++++++++++--
.../common/hid-sensors/hid-sensor-trigger.h | 5 ++-- drivers/iio/gyro/hid-sensor-gyro-3d.c | 10 +++---- drivers/iio/humidity/hid-sensor-humidity.c | 10 +++---- drivers/iio/light/hid-sensor-als.c | 4 +-- drivers/iio/light/hid-sensor-prox.c | 4 +--drivers/iio/magnetometer/hid-sensor-magn-3d.c| 4 +-- drivers/iio/orientation/hid-sensor-incl-3d.c | 4 +--drivers/iio/orientation/hid-sensor-rotation.c| 4 +-- .../position/hid-sensor-custom-intel-hinge.c | 4 +-- drivers/iio/pressure/hid-sensor-press.c | 4 +-- .../iio/temperature/hid-sensor-temperature.c | 4 +--13 files changed, 52 insertions(+), 36 deletions(-)base-commit:
eade2b843d9b1f668fc1775f15611bb0a1999cd9
Re: [PATCH v2 2/4] iio: hid-sensors: introduce device managed API
In reply to Sanjay ChitrodaQuoted 2 lines · Sanjay Chitroda
Quoted 1 line · Andy Shevchenko
On Wed, Apr 29, 2026 at 11:29:16PM +0530, Sanjay Chitroda wrote:
...
Quoted 9 lines
Quoted 9 lines
drivers/iio/common/hid-sensors/hid-sensor-trigger.c int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name, · line 309
Quoted 6 lines
drivers/iio/common/hid-sensors/hid-sensor-trigger.c +6
-0+static void hid_sensor_remove_trigger_action (void *ptr) +{ +struct hid_sensor_common *attrb = ptr; + +hid_sensor_remove_trigger (attrb); +}Casting is not needed here.
Quoted 8 lines
Quoted 4 lines
static void
hid_sensor_remove_trigger_action(void *attrb){ hid_sensor_remove_trigger(attrb); }True, the cast isn’t required. I kept the typed variable for clarity and type checking on
devm_add.. API which pass void * callback and remove trigger API which has structhid_sensor_common.Happy to simplify if preferred.
Please, do.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 4/4] iio: humidity: drop hid_sensor_remove_trigger() using devm API
In reply to Sanjay ChitrodaQuoted 4 lines · Sanjay Chitroda
Quoted 3 lines · Andy Shevchenko
Quoted 1 line · Sanjay Chitroda
Use
devm_hid_sensor_setup_trigger()to automatically release resource
resources
Quoted 1 line
Quoted 1 line
Quoted 1 line
during fail, unbind or removal of driver using devres framework.
failure
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
This simplify the setup, remove goto, avoid manual resource cleanup in
simplifies
removes
and avoids
OR
"This is done in a way to simplify..."
Quoted 1 line
Quoted 1 line
Quoted 1 line
teardown path.
...
Quoted 6 lines
Quoted 6 lines
drivers/iio/humidity/hid-sensor-humidity.c static int hid_humidity_probe(struct platform_device *pdev) · line 237
Quoted 2 lines
drivers/iio/humidity/hid-sensor-humidity.c +2
-0+ ret =devm_hid_sensor_setup_trigger (&indio_dev->dev, indio_dev, name, + &humid_st->common_attributes);I believe the first parameter is utterly wrong here. Or other way around, same issue but in the previous patch.
Quoted 7 lines
Thank you Andy for the review comment.
It looks in same humidity probe of hid sensor with devm API two device pointer are used
&pdev->devand&indio_dev->dev; ideally all devm should have same parent device for devres resource framework and over here preferable and consistent device should be&pdev->dev;I would first update existing devm_* API to have consistent device and on top of that will use same device in devm conversation.
While for gyro change device is consistent as
&pdev->devacross all devm API.
The idea is that you have to go deeply understanding the object lifetimes for the cases of different device instances along with userspace communication channels (all possible ABIs the driver uses). With only that the proper parameter may be chosen or even confirmed that device managed resources must not be used. Yeah, this is one of the downsides of devm_*() APIs.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerRe: [PATCH v2 4/4] iio: humidity: drop hid_sensor_remove_trigger() using devm API
Quoted 40 lines · On Fri, 1 May 2026 21:25:35 +0300 Andy Shevchenko <[email protected]>…
Quoted 4 lines · Sanjay Chitroda
Quoted 3 lines · Andy Shevchenko
Quoted 1 line · Sanjay Chitroda
Use
devm_hid_sensor_setup_trigger()to automatically release resourceresources
Quoted 1 line
Quoted 1 line
Quoted 1 line
during fail, unbind or removal of driver using devres framework.
failure
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
This simplify the setup, remove goto, avoid manual resource cleanup in
simplifies
removes
and avoidsOR
"This is done in a way to simplify..."
Quoted 1 line
Quoted 1 line
Quoted 1 line
teardown path.
...
Quoted 12 lines
Quoted 6 lines
drivers/iio/humidity/hid-sensor-humidity.c static int hid_humidity_probe(struct platform_device *pdev) · line 237
Quoted 2 lines
drivers/iio/humidity/hid-sensor-humidity.c +2
-0+ ret =devm_hid_sensor_setup_trigger (&indio_dev->dev, indio_dev, name, + &humid_st->common_attributes);I believe the first parameter is utterly wrong here. Or other way around, same issue but in the previous patch.
Thank you Andy for the review comment.
It looks in same humidity probe of hid sensor with devm API two device pointer are used
&pdev->devand&indio_dev->dev; ideally all devm should have same parent device for devres resource framework and over here preferable and consistent device should be&pdev->dev;I would first update existing devm_* API to have consistent device and on top of that will use same device in devm conversation.
Quoted 9 lines
Quoted 1 line
While for gyro change device is consistent as
&pdev->devacross all devm API.The idea is that you have to go deeply understanding the object lifetimes for the cases of different device instances along with userspace communication channels (all possible ABIs the driver uses). With only that the proper parameter may be chosen or even confirmed that device managed resources must not be used. Yeah, this is one of the downsides of devm_*() APIs.
FWIW it's always wrong from a design point of view to use iio_dev->dev for devm. It works but leaves us open to getting the ordering wrong as some other stuff (including things you can't necessarily see explicitly in a driver) will be using the parent device.
Jonathan
Jonathan Cameron
maintainerQuoted 14 lines · On Fri, 01 May 2026 04:53:38 -0700 srinivas pandruvada…
+ Lixu
Quoted 10 lines · Sanjay Chitroda
From: Sanjay Chitroda <[email protected]>
Key highlights:
- Prepare change as pre-requisite for devm conversion for HID IIO drivers by removing redundant argument
- Add devm API to setup trigger and clenaup resource usingdevm_add_action_or_reset()
- few sample driver update using devm conversion to auto release resource
Quoted 4 lines
devm_* calls are fine but needs tests particularly when forces ISH PCI drivers unbind, while iio-sensor-proxy has open sessions.
Lixu, Please check.
Hold off perhaps until we have a v3 with fixes for the existing devm calls against wrong struct device.
Thanks,
Jonathan
Quoted 48 lines
Thanks,
SrinivasQuoted 42 lines
changes in v2:
- Following input from Jonathan and Andy, squash initial patch v1 series in single change as individual change should not break anything
- Add devm API support and two driver using the same
- v1 series ->
https://lore.kernel.org/all/[email protected]/Testing:
- Compiled with W=1
- Build-tested on QEMUx86_64Based on further feedback and reviews, I would extend this series to convert all HID IIO driver to use devm_* API.
Thanks,
Sanjay ChitrodaSanjay Chitroda (4):
iio: hid-sensors: drop redundantiio_devargument
iio: hid-sensors: introduce device managed API
iio: gyro: drophid_sensor_remove_trigger()using devm API
iio: humidity: drophid_sensor_remove_trigger()using devm APIdrivers/iio/accel/hid-sensor-accel-3d.c | 4 +-- .../common/hid-sensors/hid-sensor-trigger.c | 27
+++++++++++++++++--
.../common/hid-sensors/hid-sensor-trigger.h | 5 ++-- drivers/iio/gyro/hid-sensor-gyro-3d.c | 10 +++---- drivers/iio/humidity/hid-sensor-humidity.c | 10 +++---- drivers/iio/light/hid-sensor-als.c | 4 +-- drivers/iio/light/hid-sensor-prox.c | 4 +--drivers/iio/magnetometer/hid-sensor-magn-3d.c| 4 +-- drivers/iio/orientation/hid-sensor-incl-3d.c | 4 +--drivers/iio/orientation/hid-sensor-rotation.c| 4 +-- .../position/hid-sensor-custom-intel-hinge.c | 4 +-- drivers/iio/pressure/hid-sensor-press.c | 4 +-- .../iio/temperature/hid-sensor-temperature.c | 4 +--13 files changed, 52 insertions(+), 36 deletions(-)base-commit:
eade2b843d9b1f668fc1775f15611bb0a1999cd9
Quoted 29 lines
-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Wednesday, May 6, 2026 12:33 AM
To: srinivas pandruvada <[email protected]>
Cc: Sanjay Chitroda <[email protected]>; [email protected]; Lechner, David <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Zhang, Lixu <[email protected]>
Subject: Re: [PATCH v2 0/4] iio: introducedevm_API for hid sensro setup and cleanupQuoted 14 lines · On Fri, 01 May 2026 04:53:38 -0700 srinivas pandruvada…
+ Lixu
Quoted 10 lines · Sanjay Chitroda
From: Sanjay Chitroda <[email protected]>
Key highlights:
- Prepare change as pre-requisite for devm conversion for HID IIO drivers by removing redundant argument
- Add devm API to setup trigger and clenaup resource usingdevm_add_action_or_reset()
- few sample driver update using devm conversion to auto release resource
Quoted 6 lines
Quoted 4 lines
devm_* calls are fine but needs tests particularly when forces ISH PCI drivers unbind, while iio-sensor-proxy has open sessions.
Lixu, Please check.
Hold off perhaps until we have a v3 with fixes for the existing devm calls against wrong struct device.
Sure, I'll test the ISH unbind scenario once v3 is out.
Thanks,
Lixu
Quoted 9 lines
Thanks,
Jonathan
Quoted 4 lines
Thanks,
Srinivas