Skip to contentSkip to conversation

iio: introduce devm_ API for hid sensro setup and cleanup

PATCH In review Sanjay Chitroda 7 participants 28 messages May 9 – May 19

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 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 cleanup and prepratory changes before updating driver for devm_
- few sample driver update using devm conversion to auto release resource

changes in v3:
- Added cleanup and prepratory changes before adding devm_ API
conversion based on self review: 0002, 0004, 0006, 0007 and 0008
- Address andy's review comment on commit message and coding style
- v2 series -> https://lore.kernel.org/all/[email protected]/
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 (9):
iio: hid-sensors: drop redundant iio_dev argument
iio: hid-sensors: cleanup codestyle warning
iio: hid-sensors: introduce device managed API
iio: gyro: hid-sensor-gyro-3d: cleanup codestyle warning
iio: gyro: hid-sensor-gyro-3d: drop hid_sensor_remove_trigger() using
devm API
iio: humidity: hid-sensor-humidity: cleanup codestyle check
iio: humidity: hid-sensor-humidity: use common device for devres
iio: humidity: hid-sensor-humidity: use local struct device
iio: humidity: hid-sensor-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   | 24 +++++++-
 .../common/hid-sensors/hid-sensor-trigger.h   |  5 +-
 drivers/iio/gyro/hid-sensor-gyro-3d.c         | 16 ++---
 drivers/iio/humidity/hid-sensor-humidity.c    | 61 +++++++++----------
 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, 78 insertions(+), 64 deletions(-)

base-commit: 39b80c5c9830d12d2d6531059001301c4265322a

Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/9 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
index 2ff591b3458f..a63dae90dadc 100644
@@ -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
index 417c4ab8c1b2..28d050b45c74 100644
@@ -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
index f94fca4f1edf..afec46ecbe71 100644
@@ -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
index c340cc899a7c..fe663b19e902 100644
@@ -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
index be2338d5f407..e580a2af9562 100644
@@ -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
index 384572844162..9b57cdced18a 100644
@@ -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
index efa904a70d0e..473c45626487 100644
@@ -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
index b01dd53eb100..8be3dfe4dd58 100644
@@ -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
index 4e23a598a3fb..56fd9c53dfc2 100644
@@ -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
index 4a11e4555099..56fdb3412fe3 100644
@@ -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
index a26d391661fd..5288b63f4e21 100644
@@ -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
index 5f1d6abda3e4..2bf5d055e175 100644
@@ -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
index 9f628a8e5cfb..60d4fcc8043b 100644
@@ -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
#5 lore raw

PATCH v3 2/9 iio: hid-sensors: cleanup codestyle warning

In reply to Sanjay Chitroda

From: Sanjay Chitroda <[email protected]>

Reported by checkpatch:
FILE: drivers/iio/common/hid-sensors/hid-sensor-trigger.c

WARNING: Missing a blank line after declarations

---
 drivers/iio/common/hid-sensors/hid-sensor-trigger.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/iio/common/hid-sensors/hid-sensor-trigger.c +3 -0
index 28d050b45c74..98fadc61a68a 100644
@@ -313,7 +313,9 @@ static int __maybe_unused hid_sensor_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct hid_sensor_common *attrb = iio_device_get_drvdata(indio_dev);
+
 	schedule_work(&attrb->work);
+
 	return 0;
 }
 
@@ -321,6 +323,7 @@ static int __maybe_unused hid_sensor_runtime_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct hid_sensor_common *attrb = iio_device_get_drvdata(indio_dev);
+
 	return _hid_sensor_power_state(attrb, true);
 }
 
Signature · 1 line
2.34.1
#8 lore raw

PATCH v3 3/9 iio: hid-sensors: introduce device managed API

In reply to Sanjay Chitroda

From: 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.

---
Changes in v3:
- Remove cast and update function based on review comment from Andy
- v2 link -> https://lore.kernel.org/all/[email protected]/

---
 .../common/hid-sensors/hid-sensor-trigger.c    | 18 ++++++++++++++++++
 .../common/hid-sensors/hid-sensor-trigger.h    |  2 ++
 2 files changed, 20 insertions(+)
drivers/iio/common/hid-sensors/hid-sensor-trigger.c +18 -0
index 98fadc61a68a..fb6a4587ae03 100644
@@ -301,6 +301,24 @@ 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 *attrb)
+{
+	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;
+
+	return devm_add_action_or_reset(dev, hid_sensor_remove_trigger_action, attrb);
+}
+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
index afec46ecbe71..6fd7c39a240d 100644
@@ -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
#12 lore raw

PATCH v3 4/9 iio: gyro: hid-sensor-gyro-3d: cleanup codestyle warning

In reply to Sanjay Chitroda

From: Sanjay Chitroda <[email protected]>

Reported by checkpatch:
FILE: drivers/iio/gyro/hid-sensor-gyro-3d.c

WARNING: Prefer 'unsigned int' to bare use of 'unsigned'
+ unsigned usage_id,

---
 drivers/iio/gyro/hid-sensor-gyro-3d.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/gyro/hid-sensor-gyro-3d.c +3 -3
index fe663b19e902..87537f9c58fb 100644
@@ -187,7 +187,7 @@ static const struct iio_info gyro_3d_info = {
 
 /* Callback handler to send event after all samples are received and captured */
 static int gyro_3d_proc_event(struct hid_sensor_hub_device *hsdev,
-				unsigned usage_id,
+				unsigned int usage_id,
 				void *priv)
 {
 	struct iio_dev *indio_dev = platform_get_drvdata(priv);
@@ -209,7 +209,7 @@ static int gyro_3d_proc_event(struct hid_sensor_hub_device *hsdev,
 
 /* Capture samples in local storage */
 static int gyro_3d_capture_sample(struct hid_sensor_hub_device *hsdev,
-				unsigned usage_id,
+				unsigned int usage_id,
 				size_t raw_len, char *raw_data,
 				void *priv)
 {
@@ -244,7 +244,7 @@ static int gyro_3d_capture_sample(struct hid_sensor_hub_device *hsdev,
 static int gyro_3d_parse_report(struct platform_device *pdev,
 				struct hid_sensor_hub_device *hsdev,
 				struct iio_chan_spec *channels,
-				unsigned usage_id,
+				unsigned int usage_id,
 				struct gyro_3d_state *st)
 {
 	int ret;
Signature · 1 line
2.34.1
#15 lore raw

PATCH v3 5/9 iio: gyro: hid-sensor-gyro-3d: drop hid_sensor_remove_trigger() using devm API

In reply to Sanjay Chitroda

From: 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
index 87537f9c58fb..72e7db8ce3b2 100644
@@ -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
#16 lore raw

PATCH v3 6/9 iio: humidity: hid-sensor-humidity: cleanup codestyle check

In reply to Sanjay Chitroda

From: Sanjay Chitroda <[email protected]>

Reported by checkpatch:
FILE: drivers/iio/humidity/hid-sensor-humidity.c

CHECK: Alignment should match open parenthesis

---
 drivers/iio/humidity/hid-sensor-humidity.c | 46 +++++++++++-----------
 1 file changed, 23 insertions(+), 23 deletions(-)
drivers/iio/humidity/hid-sensor-humidity.c +23 -23
index e580a2af9562..968dd8d4bb35 100644
@@ -45,7 +45,7 @@ static const struct iio_chan_spec humidity_channels[] = {
 
 /* Adjust channel real bits based on report descriptor */
 static void humidity_adjust_channel_bit_mask(struct iio_chan_spec *channels,
-					int channel, int size)
+					     int channel, int size)
 {
 	channels[channel].scan_type.sign = 's';
 	/* Real storage bits will change based on the report desc. */
@@ -55,8 +55,8 @@ static void humidity_adjust_channel_bit_mask(struct iio_chan_spec *channels,
 }
 
 static int humidity_read_raw(struct iio_dev *indio_dev,
-				struct iio_chan_spec const *chan,
-				int *val, int *val2, long mask)
+			     struct iio_chan_spec const *chan,
+			     int *val, int *val2, long mask)
 {
 	struct hid_humidity_state *humid_st = iio_priv(indio_dev);
 
@@ -101,8 +101,8 @@ static int humidity_read_raw(struct iio_dev *indio_dev,
 }
 
 static int humidity_write_raw(struct iio_dev *indio_dev,
-				struct iio_chan_spec const *chan,
-				int val, int val2, long mask)
+			      struct iio_chan_spec const *chan,
+			      int val, int val2, long mask)
 {
 	struct hid_humidity_state *humid_st = iio_priv(indio_dev);
 
@@ -127,7 +127,7 @@ static const struct iio_info humidity_info = {
 
 /* Callback handler to send event after all samples are received and captured */
 static int humidity_proc_event(struct hid_sensor_hub_device *hsdev,
-				unsigned int usage_id, void *pdev)
+			       unsigned int usage_id, void *pdev)
 {
 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
 	struct hid_humidity_state *humid_st = iio_priv(indio_dev);
@@ -141,8 +141,8 @@ static int humidity_proc_event(struct hid_sensor_hub_device *hsdev,
 
 /* Capture samples in local storage */
 static int humidity_capture_sample(struct hid_sensor_hub_device *hsdev,
-				unsigned int usage_id, size_t raw_len,
-				char *raw_data, void *pdev)
+				   unsigned int usage_id, size_t raw_len,
+				   char *raw_data, void *pdev)
 {
 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
 	struct hid_humidity_state *humid_st = iio_priv(indio_dev);
@@ -159,17 +159,17 @@ static int humidity_capture_sample(struct hid_sensor_hub_device *hsdev,
 
 /* Parse report which is specific to an usage id */
 static int humidity_parse_report(struct platform_device *pdev,
-				struct hid_sensor_hub_device *hsdev,
-				struct iio_chan_spec *channels,
-				unsigned int usage_id,
-				struct hid_humidity_state *st)
+				 struct hid_sensor_hub_device *hsdev,
+				 struct iio_chan_spec *channels,
+				 unsigned int usage_id,
+				 struct hid_humidity_state *st)
 {
 	int ret;
 
 	ret = sensor_hub_input_get_attribute_info(hsdev, HID_INPUT_REPORT,
-					usage_id,
-					HID_USAGE_SENSOR_ATMOSPHERIC_HUMIDITY,
-					&st->humidity_attr);
+						  usage_id,
+						  HID_USAGE_SENSOR_ATMOSPHERIC_HUMIDITY,
+						  &st->humidity_attr);
 	if (ret < 0)
 		return ret;
 
@@ -208,20 +208,20 @@ static int hid_humidity_probe(struct platform_device *pdev)
 	humid_st->common_attributes.pdev = pdev;
 
 	ret = hid_sensor_parse_common_attributes(hsdev,
-					HID_USAGE_SENSOR_HUMIDITY,
-					&humid_st->common_attributes,
-					humidity_sensitivity_addresses,
-					ARRAY_SIZE(humidity_sensitivity_addresses));
+						 HID_USAGE_SENSOR_HUMIDITY,
+						 &humid_st->common_attributes,
+						 humidity_sensitivity_addresses,
+						 ARRAY_SIZE(humidity_sensitivity_addresses));
 	if (ret)
 		return ret;
 
 	humid_chans = devm_kmemdup(&indio_dev->dev, humidity_channels,
-					sizeof(humidity_channels), GFP_KERNEL);
+				   sizeof(humidity_channels), GFP_KERNEL);
 	if (!humid_chans)
 		return -ENOMEM;
 
 	ret = humidity_parse_report(pdev, hsdev, humid_chans,
-				HID_USAGE_SENSOR_HUMIDITY, humid_st);
+				    HID_USAGE_SENSOR_HUMIDITY, humid_st);
 	if (ret)
 		return ret;
 
@@ -234,7 +234,7 @@ 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);
+				       &humid_st->common_attributes);
 	if (ret)
 		return ret;
 
@@ -242,7 +242,7 @@ static int hid_humidity_probe(struct platform_device *pdev)
 
 	humidity_callbacks.pdev = pdev;
 	ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_HUMIDITY,
-					&humidity_callbacks);
+					   &humidity_callbacks);
 	if (ret)
 		goto error_remove_trigger;
 
Signature · 1 line
2.34.1
#17 lore raw

PATCH v3 7/9 iio: humidity: hid-sensor-humidity: use common device for devres

In reply to Sanjay Chitroda

From: Sanjay Chitroda <[email protected]>

kmemdup() is used for memory that is logically tied to the HID platform device, even though the driver binds into the IIO framework.

Using &indio_dev->dev for devres allocations works functionally, but it results in two separate devres ownership trees—one for the HID platform device (pdev) and another for the IIO device (indio_dev).

The devres framework is intended to have a single, well-defined parent device. Since the memory originates from HID sensor probing and is not IIO-specific, &pdev->dev is the correct and logical owner.

Switch to using the platform device for devm_kmemdup() so that all resources are released deterministically and consistently.

---
 drivers/iio/humidity/hid-sensor-humidity.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/humidity/hid-sensor-humidity.c +1 -1
index 968dd8d4bb35..18d4e376376d 100644
@@ -215,7 +215,7 @@ static int hid_humidity_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	humid_chans = devm_kmemdup(&indio_dev->dev, humidity_channels,
+	humid_chans = devm_kmemdup(&pdev->dev, humidity_channels,
 				   sizeof(humidity_channels), GFP_KERNEL);
 	if (!humid_chans)
 		return -ENOMEM;
Signature · 1 line
2.34.1
#21 lore raw

PATCH v3 8/9 iio: humidity: hid-sensor-humidity: use local struct device

In reply to Sanjay Chitroda

From: Sanjay Chitroda <[email protected]>

Introduce a local struct device pointer derived from &pdev->dev. This avoids repeated &pdev->dev usage and improves readability.

---
 drivers/iio/humidity/hid-sensor-humidity.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/iio/humidity/hid-sensor-humidity.c +4 -3
index 18d4e376376d..d310ec43a118 100644
@@ -196,10 +196,11 @@ static int hid_humidity_probe(struct platform_device *pdev)
 	struct iio_dev *indio_dev;
 	struct hid_humidity_state *humid_st;
 	struct iio_chan_spec *humid_chans;
-	struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
+	struct device *dev = &pdev->dev;
+	struct hid_sensor_hub_device *hsdev = dev_get_platdata(dev);
 	int ret;
 
-	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*humid_st));
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*humid_st));
 	if (!indio_dev)
 		return -ENOMEM;
 
@@ -215,7 +216,7 @@ static int hid_humidity_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	humid_chans = devm_kmemdup(&pdev->dev, humidity_channels,
+	humid_chans = devm_kmemdup(dev, humidity_channels,
 				   sizeof(humidity_channels), GFP_KERNEL);
 	if (!humid_chans)
 		return -ENOMEM;
Signature · 1 line
2.34.1
#22 lore raw

PATCH v3 9/9 iio: humidity: hid-sensor-humidity: drop hid_sensor_remove_trigger() using devm API

In reply to Sanjay Chitroda

From: Sanjay Chitroda <[email protected]>

Use devm_hid_sensor_setup_trigger() to automatically release resources during failure, unbind or removal of driver using devres framework.

This is done in a way to simplify the setup, remove goto and avoid manual resource cleanup in teardown path.

---
changes in v3:
- Update commit message based on review comment from Andy
- Based on discussion using parent device of HID platform driver used
with devres framework for this driver
- v2 link -> https://lore.kernel.org/all/[email protected]/

---
 drivers/iio/humidity/hid-sensor-humidity.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/iio/humidity/hid-sensor-humidity.c +3 -7
index d310ec43a118..4d4282e4b6e4 100644
@@ -234,8 +234,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(dev, indio_dev, name,
+					    &humid_st->common_attributes);
 	if (ret)
 		return ret;
 
@@ -245,7 +245,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)
@@ -255,8 +255,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;
 }
 
@@ -265,11 +263,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
#2 lore raw

Re: [PATCH v3 1/9] iio: hid-sensors: drop redundant iio_dev argument

In reply to Sanjay Chitroda
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] This problem wasn't introduced by this patch, but the removal sequence across HID IIO drivers…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] This problem wasn't introduced by this patch, but the removal sequence across HID IIO drivers cancels asynchronous suspend requests, leaving the hardware powered on, which violates PM subsystem guidelines.
- [High] This problem wasn't introduced by this patch, but in hid-sensor-temperature.c, the trigger is manually unregistered and freed in the remove callback while the IIO device is still active and registered, creating a use-after-free vulnerability. --

commit 774f02b73d8b538afc5af51312b8682afec55f98
Author: Sanjay Chitroda <[email protected]>

iio: hid-sensors: drop redundant iio_dev argument

This commit removes the unused iio_dev argument from hid_sensor_remove_trigger() across all HID IIO drivers, adapting the function prototype to simplify the API for a future devm-based conversion.

Quoted 4 lines
drivers/iio/accel/hid-sensor-accel-3d.c +0 -0
index 2ff591b3458f7..a63dae90dadc5 100644

[ ... ]

drivers/iio/accel/hid-sensor-accel-3d.c static void hid_accel_3d_remove(struct platform_device *pdev) · line 433

Quoted 7 lines
drivers/iio/accel/hid-sensor-accel-3d.c +1 -1
@@ -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);
 }

This problem wasn't introduced by this patch, but could this removal sequence leave the hardware powered on?

Looking at the removal path across these drivers, iio_device_unregister() disables the IIO buffers, which eventually calls hid_sensor_power_state() and queues an asynchronous suspend via pm_runtime_put_autosuspend().

Immediately afterward, hid_sensor_remove_trigger() calls pm_runtime_disable(). Does calling pm_runtime_disable() immediately after an async put cancel the pending suspend work, leaving the physical device active while marking it suspended in the PM core?

[ ... ]

Quoted 4 lines
drivers/iio/temperature/hid-sensor-temperature.c +0 -0
index 9f628a8e5cfbe..60d4fcc8043b6 100644

[ ... ]

drivers/iio/temperature/hid-sensor-temperature.c static void hid_temperature_remove(struct platform_device *pdev) · line 269

Quoted 7 lines
drivers/iio/temperature/hid-sensor-temperature.c +1 -1
@@ -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);
 }

This problem also wasn't introduced by this patch, but is there a use-after-free risk in this specific driver's removal sequence?

The temperature driver uses devm_iio_device_register() to register the IIO device, which means the device unregistration is deferred until the devres cleanup phase after hid_temperature_remove() returns.

However, hid_sensor_remove_trigger() is called manually here and it calls iio_trigger_free(). Since the IIO device remains fully registered and exposed to user-space until devres runs, could concurrent sysfs access or buffer operations dereference the freed trigger pointer?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#18 lore raw

Re: [PATCH v3 7/9] iio: humidity: hid-sensor-humidity: use common device for devres

In reply to Sanjay Chitroda
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Use-After-Free due to lifetime mismatch between IIO device and platform device devres --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Use-After-Free due to lifetime mismatch between IIO device and platform device devres --

commit 2edcf899b7cb430d80f56a0ef1506dd20ea46d9d
Author: Sanjay Chitroda <[email protected]>

iio: humidity: hid-sensor-humidity: use common device for devres

This commit changes the devres allocation of humidity channels to use the platform device instead of the IIO device. The goal is to have a single, well-defined parent device for devres ownership.

drivers/iio/humidity/hid-sensor-humidity.c static int hid_humidity_probe(struct platform_device *pdev) · line 219

Quoted 10 lines
drivers/iio/humidity/hid-sensor-humidity.c +1 -1
@@ -215,7 +215,7 @@ static int hid_humidity_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	humid_chans = devm_kmemdup(&indio_dev->dev, humidity_channels,
+	humid_chans = devm_kmemdup(&pdev->dev, humidity_channels,
 				   sizeof(humidity_channels), GFP_KERNEL);

Could this change introduce a use-after-free if the IIO device outlives the driver binding?

The indio_dev object is allocated using devm_iio_device_alloc(), meaning it is reference-counted and its lifetime can exceed the platform device binding if consumers hold a reference.

If the driver unbinds, the pdev devres callbacks will execute and free the humid_chans memory. However, indio_dev->channels still points to this freed array.

If a consumer later calls IIO APIs like iio_read_channel_ext_info(), they will dereference the freed humid_chans memory.

Quoted 2 lines
drivers/iio/humidity/hid-sensor-humidity.c +0 -0
 	if (!humid_chans)
 		return -ENOMEM;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
reviewer
#3 lore raw

Re: [PATCH v3 1/9] iio: hid-sensors: drop redundant iio_dev argument

In reply to Sanjay Chitroda
Quoted 9 lines · Sanjay Chitroda

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.

Quoted 5 lines

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.

The subject and commit message don't make sense to me. It looks like it is just removing an unused argument.

Code looks fine though.

reviewer
#6 lore raw

Re: [PATCH v3 2/9] iio: hid-sensors: cleanup codestyle warning

In reply to Sanjay Chitroda
Quoted 4 lines · Sanjay Chitroda

From: Sanjay Chitroda <[email protected]>

Reported by checkpatch:
FILE: drivers/iio/common/hid-sensors/hid-sensor-trigger.c

checkpatch (or any other linter) says so is not a good reason for a change. They are suggestions, not requirements. If the code is improved, say why this is better. I.e. improve readability.

Quoted 30 lines

WARNING: Missing a blank line after declarations

---
 drivers/iio/common/hid-sensors/hid-sensor-trigger.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/iio/common/hid-sensors/hid-sensor-trigger.c +3 -0
index 28d050b45c74..98fadc61a68a 100644
@@ -313,7 +313,9 @@ static int __maybe_unused hid_sensor_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct hid_sensor_common *attrb = iio_device_get_drvdata(indio_dev);
+
 	schedule_work(&attrb->work);
+
 	return 0;
 }
 
@@ -321,6 +323,7 @@ static int __maybe_unused hid_sensor_runtime_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct hid_sensor_common *attrb = iio_device_get_drvdata(indio_dev);
+
 	return _hid_sensor_power_state(attrb, true);
 }
 
reviewer
#13 lore raw

Re: [PATCH v3 4/9] iio: gyro: hid-sensor-gyro-3d: cleanup codestyle warning

In reply to Sanjay Chitroda
Quoted 7 lines · Sanjay Chitroda

From: Sanjay Chitroda <[email protected]>

Reported by checkpatch:
FILE: drivers/iio/gyro/hid-sensor-gyro-3d.c

WARNING: Prefer 'unsigned int' to bare use of 'unsigned'
+ unsigned usage_id,

Even better would be to use u32 since this driver already uses that type.

Quoted 37 lines
---
 drivers/iio/gyro/hid-sensor-gyro-3d.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/gyro/hid-sensor-gyro-3d.c +3 -3
index fe663b19e902..87537f9c58fb 100644
@@ -187,7 +187,7 @@ static const struct iio_info gyro_3d_info = {
 
 /* Callback handler to send event after all samples are received and captured */
 static int gyro_3d_proc_event(struct hid_sensor_hub_device *hsdev,
-				unsigned usage_id,
+				unsigned int usage_id,
 				void *priv)
 {
 	struct iio_dev *indio_dev = platform_get_drvdata(priv);
@@ -209,7 +209,7 @@ static int gyro_3d_proc_event(struct hid_sensor_hub_device *hsdev,
 
 /* Capture samples in local storage */
 static int gyro_3d_capture_sample(struct hid_sensor_hub_device *hsdev,
-				unsigned usage_id,
+				unsigned int usage_id,
 				size_t raw_len, char *raw_data,
 				void *priv)
 {
@@ -244,7 +244,7 @@ static int gyro_3d_capture_sample(struct hid_sensor_hub_device *hsdev,
 static int gyro_3d_parse_report(struct platform_device *pdev,
 				struct hid_sensor_hub_device *hsdev,
 				struct iio_chan_spec *channels,
-				unsigned usage_id,
+				unsigned int usage_id,
 				struct gyro_3d_state *st)
 {
 	int ret;
reviewer
#23 lore raw
In reply to Sanjay Chitroda
Quoted 31 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 using devm_add_action_or_reset()
- few cleanup and prepratory changes before updating driver for devm_
- few sample driver update using devm conversion to auto release resource

changes in v3:
- Added cleanup and prepratory changes before adding devm_ API
conversion based on self review: 0002, 0004, 0006, 0007 and 0008
- Address andy's review comment on commit message and coding style
- v2 series -> https://lore.kernel.org/all/[email protected]/
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

Quoted 12 lines

Sanjay Chitroda (9):
iio: hid-sensors: drop redundant iio_dev argument
iio: hid-sensors: cleanup codestyle warning
iio: hid-sensors: introduce device managed API
iio: gyro: hid-sensor-gyro-3d: cleanup codestyle warning
iio: gyro: hid-sensor-gyro-3d: drop hid_sensor_remove_trigger() using
devm API
iio: humidity: hid-sensor-humidity: cleanup codestyle check
iio: humidity: hid-sensor-humidity: use common device for devres
iio: humidity: hid-sensor-humidity: use local struct device
iio: humidity: hid-sensor-humidity: drop hid_sensor_remove_trigger()
using devm API

The series would be easier to follow if all of the cleanups were first and then all of the new code was the last 3 patches.

Quoted 18 lines
 drivers/iio/accel/hid-sensor-accel-3d.c       |  4 +-
 .../common/hid-sensors/hid-sensor-trigger.c   | 24 +++++++-
 .../common/hid-sensors/hid-sensor-trigger.h   |  5 +-
 drivers/iio/gyro/hid-sensor-gyro-3d.c         | 16 ++---
 drivers/iio/humidity/hid-sensor-humidity.c    | 61 +++++++++----------
 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, 78 insertions(+), 64 deletions(-)

base-commit: 39b80c5c9830d12d2d6531059001301c4265322a

#9 lore raw

Re: [PATCH v3 3/9] iio: hid-sensors: introduce device managed API

In reply to Sanjay Chitroda
Quoted 7 lines · Sanjay Chitroda

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.

...

drivers/iio/common/hid-sensors/hid-sensor-trigger.c int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name, · line 310

Quoted 2 lines
drivers/iio/common/hid-sensors/hid-sensor-trigger.c +2 -0
+int devm_hid_sensor_setup_trigger(struct device *dev, struct iio_dev *indio_dev,
+				  const char *name, struct hid_sensor_common *attrb)

At this point don't we have indio_dev->dev.parent == dev?

Quoted 9 lines
drivers/iio/common/hid-sensors/hid-sensor-trigger.c +9 -0
+{
+	int ret;
+
+	ret = hid_sensor_setup_trigger(indio_dev, name, attrb);
+	if (ret)
+		return ret;
+
+	return devm_add_action_or_reset(dev, hid_sensor_remove_trigger_action, attrb);
+}
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#14 lore raw

Re: [PATCH v3 4/9] iio: gyro: hid-sensor-gyro-3d: cleanup codestyle warning

In reply to Sanjay Chitroda
Quoted 5 lines · Sanjay Chitroda

Reported by checkpatch:
FILE: drivers/iio/gyro/hid-sensor-gyro-3d.c

WARNING: Prefer 'unsigned int' to bare use of 'unsigned'
+ unsigned usage_id,

Use the type that is in the respective prototypes.

Also note, there was a patch doing exactly that. Find it in the mailing lists and ask author if you can take it or what the status of affairs is.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#19 lore raw

Re: [PATCH v3 7/9] iio: humidity: hid-sensor-humidity: use common device for devres

In reply to Sanjay Chitroda
Quoted 7 lines · Sanjay Chitroda

kmemdup() is used for memory that is logically tied to the HID platform device, even though the driver binds into the IIO framework.

Using &indio_dev->dev for devres allocations works functionally, but it results in two separate devres ownership trees—one for the HID platform device (pdev) and another for the IIO device (indio_dev).

Quoted 6 lines

The devres framework is intended to have a single, well-defined parent device. Since the memory originates from HID sensor probing and is not IIO-specific, &pdev->dev is the correct and logical owner.

Switch to using the platform device for devm_kmemdup() so that all resources are released deterministically and consistently.

This patch sounds like a required fix and has to be placed in the beginning of the series along with the Fixes tag.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#10 lore raw

Re: [PATCH v3 3/9] iio: hid-sensors: introduce device managed API

In reply to Andy Shevchenko
Quoted 10 lines · On Sun, 10 May 2026 09:36:49 +0300 Andy Shevchenko…
Quoted 7 lines · Sanjay Chitroda

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.

Quoted 6 lines

...

drivers/iio/common/hid-sensors/hid-sensor-trigger.c int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name, · line 310

Quoted 2 lines
drivers/iio/common/hid-sensors/hid-sensor-trigger.c +2 -0
+int devm_hid_sensor_setup_trigger(struct device *dev, struct iio_dev *indio_dev,
+				  const char *name, struct hid_sensor_common *attrb)  

At this point don't we have indio_dev->dev.parent == dev?

yes probably but I'd rather we didn't use that. For devm calls it's nicer to have the owner device explicit.

Quoted 11 lines
Quoted 10 lines
drivers/iio/common/hid-sensors/hid-sensor-trigger.c +9 -0
+{
+	int ret;
+
+	ret = hid_sensor_setup_trigger(indio_dev, name, attrb);
+	if (ret)
+		return ret;
+
+	return devm_add_action_or_reset(dev, hid_sensor_remove_trigger_action, attrb);
+}  
maintainer
#20 lore raw

Re: [PATCH v3 7/9] iio: humidity: hid-sensor-humidity: use common device for devres

In reply to Andy Shevchenko
Quoted 13 lines · On Sun, 10 May 2026 09:42:49 +0300 Andy Shevchenko…
Quoted 11 lines · Sanjay Chitroda

kmemdup() is used for memory that is logically tied to the HID platform device, even though the driver binds into the IIO framework.

Using &indio_dev->dev for devres allocations works functionally, but it results in two separate devres ownership trees—one for the HID platform device (pdev) and another for the IIO device (indio_dev).

The devres framework is intended to have a single, well-defined parent device. Since the memory originates from HID sensor probing and is not IIO-specific, &pdev->dev is the correct and logical owner.

Quoted 5 lines
Quoted 2 lines

Switch to using the platform device for devm_kmemdup() so that all resources are released deterministically and consistently.

This patch sounds like a required fix and has to be placed in the beginning of the series along with the Fixes tag.

Hmm. I always find these hard to prove...
Ultimately for a device for which no driver is ever bound I believe the call to devres_release_all() in device_release() catches these.

That should I think happen when the last reference to the iio_dev->dev is dropped (for the device we care about in the 'buggy' code). Now that may well be at a different time to when it would happen on the underlying bus device unbind. However here we are talking about an allocation so as long as we release it at somepoint and that's late enough (which it will be either way) then it's not a bug - it just makes the code harder to reason about.

Jonathan

p.s. I remember testing the releases on some other drivers years ago
to figure out if they had an actual bug based on the pattern we have here. It 'works' but yuk.

maintainer Acked-by on v3 1/9
#4 lore raw

Re: [PATCH v3 1/9] iio: hid-sensors: drop redundant iio_dev argument

In reply to Sanjay Chitroda
Quoted 9 lines · Sanjay Chitroda

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.

Quoted 7 lines

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.

Quoted 355 lines

---
 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 +0 -0
index 2ff591b3458f..a63dae90dadc 100644
@@ -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:

drivers/iio/accel/hid-sensor-accel-3d.c +0 -1
-	hid_sensor_remove_trigger(indio_dev, &accel_state-
Quoted 1 line

common_attributes);

drivers/iio/accel/hid-sensor-accel-3d.c +1 -0
+	hid_sensor_remove_trigger(&accel_state->common_attributes);

  return ret;
 }

drivers/iio/accel/hid-sensor-accel-3d.c +0 -0
@@ -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);

drivers/iio/accel/hid-sensor-accel-3d.c +0 -1
-	hid_sensor_remove_trigger(indio_dev, &accel_state-
Quoted 1 line

common_attributes);

drivers/iio/accel/hid-sensor-accel-3d.c +1 -0
+	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 +0 -0
index 417c4ab8c1b2..28d050b45c74 100644
@@ -218,8 +218,7 @@ static const struct iio_buffer_setup_ops
 hid_sensor_buffer_ops = {
  	.predisable = buffer_predisable,
  };

drivers/iio/common/hid-sensors/hid-sensor-trigger.c +1 -2
-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 +0 -0
index f94fca4f1edf..afec46ecbe71 100644
@@ -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);

drivers/iio/common/hid-sensors/hid-sensor-trigger.h +1 -2
-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 +0 -0
index c340cc899a7c..fe663b19e902 100644
@@ -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:

drivers/iio/gyro/hid-sensor-gyro-3d.c +0 -1
-	hid_sensor_remove_trigger(indio_dev, &gyro_state-
Quoted 1 line

common_attributes);

drivers/iio/gyro/hid-sensor-gyro-3d.c +1 -0
+	hid_sensor_remove_trigger(&gyro_state->common_attributes);

  return ret;
 }

drivers/iio/gyro/hid-sensor-gyro-3d.c +0 -0
@@ -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);

drivers/iio/gyro/hid-sensor-gyro-3d.c +0 -1
-	hid_sensor_remove_trigger(indio_dev, &gyro_state-
Quoted 1 line

common_attributes);

drivers/iio/gyro/hid-sensor-gyro-3d.c +1 -0
+	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 +0 -0
index be2338d5f407..e580a2af9562 100644
@@ -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:

drivers/iio/humidity/hid-sensor-humidity.c +0 -1
-	hid_sensor_remove_trigger(indio_dev, &humid_st-
Quoted 1 line

common_attributes);

drivers/iio/humidity/hid-sensor-humidity.c +1 -0
+	hid_sensor_remove_trigger(&humid_st->common_attributes);

  return ret;
 }

drivers/iio/humidity/hid-sensor-humidity.c +0 -0
@@ -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);

drivers/iio/humidity/hid-sensor-humidity.c +0 -1
-	hid_sensor_remove_trigger(indio_dev, &humid_st-
Quoted 1 line

common_attributes);

drivers/iio/humidity/hid-sensor-humidity.c +1 -0
+	hid_sensor_remove_trigger(&humid_st->common_attributes);

 }

 static const struct platform_device_id hid_humidity_ids[] = {

drivers/iio/light/hid-sensor-als.c +0 -0
index 384572844162..9b57cdced18a 100644
@@ -432,7 +432,7 @@ static int hid_als_probe(struct platform_device
 *pdev)

 error_iio_unreg:
  iio_device_unregister(indio_dev);
 error_remove_trigger:

drivers/iio/light/hid-sensor-als.c +0 -1
-	hid_sensor_remove_trigger(indio_dev, &als_state-
Quoted 1 line

common_attributes);

drivers/iio/light/hid-sensor-als.c +1 -0
+	hid_sensor_remove_trigger(&als_state->common_attributes);

  return ret;
 }

drivers/iio/light/hid-sensor-als.c +0 -0
@@ -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);

drivers/iio/light/hid-sensor-als.c +0 -1
-	hid_sensor_remove_trigger(indio_dev, &als_state-
Quoted 1 line

common_attributes);

drivers/iio/light/hid-sensor-als.c +1 -0
+	hid_sensor_remove_trigger(&als_state->common_attributes);

 }

 static const struct platform_device_id hid_als_ids[] = {

drivers/iio/light/hid-sensor-prox.c +0 -0
index efa904a70d0e..473c45626487 100644
@@ -340,7 +340,7 @@ static int hid_prox_probe(struct platform_device
 *pdev)

 error_iio_unreg:
  iio_device_unregister(indio_dev);
 error_remove_trigger:

drivers/iio/light/hid-sensor-prox.c +0 -1
-	hid_sensor_remove_trigger(indio_dev, &prox_state-
Quoted 1 line

common_attributes);

drivers/iio/light/hid-sensor-prox.c +1 -0
+	hid_sensor_remove_trigger(&prox_state->common_attributes);

  return ret;
 }

drivers/iio/light/hid-sensor-prox.c +0 -0
@@ -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);

drivers/iio/light/hid-sensor-prox.c +0 -1
-	hid_sensor_remove_trigger(indio_dev, &prox_state-
Quoted 1 line

common_attributes);

drivers/iio/light/hid-sensor-prox.c +1 -0
+	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 +0 -0
index b01dd53eb100..8be3dfe4dd58 100644
@@ -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:

drivers/iio/magnetometer/hid-sensor-magn-3d.c +0 -1
-	hid_sensor_remove_trigger(indio_dev, &magn_state-
Quoted 1 line

magn_flux_attributes);

drivers/iio/magnetometer/hid-sensor-magn-3d.c +1 -0
+	hid_sensor_remove_trigger(&magn_state-
Quoted 1 line

magn_flux_attributes);

  return ret;
 }

drivers/iio/magnetometer/hid-sensor-magn-3d.c +0 -0
@@ -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);

drivers/iio/magnetometer/hid-sensor-magn-3d.c +0 -1
-	hid_sensor_remove_trigger(indio_dev, &magn_state-
Quoted 1 line

magn_flux_attributes);

drivers/iio/magnetometer/hid-sensor-magn-3d.c +1 -0
+	hid_sensor_remove_trigger(&magn_state-
Quoted 1 line

magn_flux_attributes);

 }

 static const struct platform_device_id hid_magn_3d_ids[] = {

drivers/iio/orientation/hid-sensor-incl-3d.c +0 -0
index 4e23a598a3fb..56fd9c53dfc2 100644
@@ -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:

drivers/iio/orientation/hid-sensor-incl-3d.c +0 -1
-	hid_sensor_remove_trigger(indio_dev, &incl_state-
Quoted 1 line

common_attributes);

drivers/iio/orientation/hid-sensor-incl-3d.c +1 -0
+	hid_sensor_remove_trigger(&incl_state->common_attributes);

  return ret;
 }

drivers/iio/orientation/hid-sensor-incl-3d.c +0 -0
@@ -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);

drivers/iio/orientation/hid-sensor-incl-3d.c +0 -1
-	hid_sensor_remove_trigger(indio_dev, &incl_state-
Quoted 1 line

common_attributes);

drivers/iio/orientation/hid-sensor-incl-3d.c +1 -0
+	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 +0 -0
index 4a11e4555099..56fdb3412fe3 100644
@@ -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:

drivers/iio/orientation/hid-sensor-rotation.c +0 -1
-	hid_sensor_remove_trigger(indio_dev, &rot_state-
Quoted 1 line

common_attributes);

drivers/iio/orientation/hid-sensor-rotation.c +1 -0
+	hid_sensor_remove_trigger(&rot_state->common_attributes);

  return ret;
 }

drivers/iio/orientation/hid-sensor-rotation.c +0 -0
@@ -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);

drivers/iio/orientation/hid-sensor-rotation.c +0 -1
-	hid_sensor_remove_trigger(indio_dev, &rot_state-
Quoted 1 line

common_attributes);

drivers/iio/orientation/hid-sensor-rotation.c +1 -0
+	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 +0 -0
index a26d391661fd..5288b63f4e21 100644
@@ -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:

drivers/iio/position/hid-sensor-custom-intel-hinge.c +0 -1
-	hid_sensor_remove_trigger(indio_dev, &st-
Quoted 1 line

common_attributes);

drivers/iio/position/hid-sensor-custom-intel-hinge.c +1 -0
+	hid_sensor_remove_trigger(&st->common_attributes);

  return ret;
 }

drivers/iio/position/hid-sensor-custom-intel-hinge.c +0 -0
@@ -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);

drivers/iio/position/hid-sensor-custom-intel-hinge.c +0 -1
-	hid_sensor_remove_trigger(indio_dev, &st-
Quoted 1 line

common_attributes);

drivers/iio/position/hid-sensor-custom-intel-hinge.c +1 -0
+	hid_sensor_remove_trigger(&st->common_attributes);

 }

 static const struct platform_device_id hid_hinge_ids[] = {

drivers/iio/pressure/hid-sensor-press.c +0 -0
index 5f1d6abda3e4..2bf5d055e175 100644
@@ -319,7 +319,7 @@ static int hid_press_probe(struct platform_device
 *pdev)

 error_iio_unreg:
  iio_device_unregister(indio_dev);
 error_remove_trigger:

drivers/iio/pressure/hid-sensor-press.c +0 -1
-	hid_sensor_remove_trigger(indio_dev, &press_state-
Quoted 1 line

common_attributes);

drivers/iio/pressure/hid-sensor-press.c +1 -0
+	hid_sensor_remove_trigger(&press_state->common_attributes);

  return ret;
 }

drivers/iio/pressure/hid-sensor-press.c +0 -0
@@ -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);

drivers/iio/pressure/hid-sensor-press.c +0 -1
-	hid_sensor_remove_trigger(indio_dev, &press_state-
Quoted 1 line

common_attributes);

drivers/iio/pressure/hid-sensor-press.c +1 -0
+	hid_sensor_remove_trigger(&press_state->common_attributes);

 }

 static const struct platform_device_id hid_press_ids[] = {

drivers/iio/temperature/hid-sensor-temperature.c +0 -0
index 9f628a8e5cfb..60d4fcc8043b 100644
@@ -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:

drivers/iio/temperature/hid-sensor-temperature.c +0 -1
-	hid_sensor_remove_trigger(indio_dev, &temp_st-
Quoted 1 line

common_attributes);

drivers/iio/temperature/hid-sensor-temperature.c +1 -0
+	hid_sensor_remove_trigger(&temp_st->common_attributes);

  return ret;
 }

drivers/iio/temperature/hid-sensor-temperature.c +0 -0
@@ -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);

drivers/iio/temperature/hid-sensor-temperature.c +0 -1
-	hid_sensor_remove_trigger(indio_dev, &temp_st-
Quoted 1 line

common_attributes);

drivers/iio/temperature/hid-sensor-temperature.c +1 -0
+	hid_sensor_remove_trigger(&temp_st->common_attributes);

 }

 static const struct platform_device_id hid_temperature_ids[] = {

maintainer Acked-by on v3 2/9
#7 lore raw

Re: [PATCH v3 2/9] iio: hid-sensors: cleanup codestyle warning

In reply to Sanjay Chitroda
Quoted 8 lines · Sanjay Chitroda

From: Sanjay Chitroda <[email protected]>

Reported by checkpatch:
FILE: drivers/iio/common/hid-sensors/hid-sensor-trigger.c

WARNING: Missing a blank line after declarations

Quoted 31 lines

---
 drivers/iio/common/hid-sensors/hid-sensor-trigger.c | 3 +++

 1 file changed, 3 insertions(+)
drivers/iio/common/hid-sensors/hid-sensor-trigger.c +0 -0
index 28d050b45c74..98fadc61a68a 100644
@@ -313,7 +313,9 @@ static int __maybe_unused
 hid_sensor_resume(struct device *dev)
  {
  	struct iio_dev *indio_dev = dev_get_drvdata(dev);

  struct hid_sensor_common *attrb =
iio_device_get_drvdata(indio_dev);
+
  schedule_work(&attrb->work);
+
  return 0;
 }

drivers/iio/common/hid-sensors/hid-sensor-trigger.c +0 -0
@@ -321,6 +323,7 @@ static int __maybe_unused
 hid_sensor_runtime_resume(struct device *dev)
  {
  	struct iio_dev *indio_dev = dev_get_drvdata(dev);

  struct hid_sensor_common *attrb = iio_device_get_drvdata(indio_dev);
+
  return _hid_sensor_power_state(attrb, true); }

#11 lore raw

Re: [PATCH v3 3/9] iio: hid-sensors: introduce device managed API

In reply to Sanjay Chitroda
Quoted 9 lines · Sanjay Chitroda

From: 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.

Quoted 5 lines

Register action with devm_add_action_or_reset() to release resource with
devres framework.

Looks good but we have to test by unbinding ISH PCI device.

Thanks,
Srinivas

Quoted 63 lines

---
Changes in v3:
- Remove cast and update function based on review comment from Andy
- v2 link ->
https://lore.kernel.org/all/[email protected]/
---
 .../common/hid-sensors/hid-sensor-trigger.c    | 18
++++++++++++++++++
 .../common/hid-sensors/hid-sensor-trigger.h    |  2 ++

 2 files changed, 20 insertions(+)
drivers/iio/common/hid-sensors/hid-sensor-trigger.c +0 -0
index 98fadc61a68a..fb6a4587ae03 100644
@@ -301,6 +301,24 @@ int hid_sensor_setup_trigger(struct iio_dev
 *indio_dev, const char *name,
  }
  EXPORT_SYMBOL_NS(hid_sensor_setup_trigger, "IIO_HID");

drivers/iio/common/hid-sensors/hid-sensor-trigger.c +6 -0
+static void hid_sensor_remove_trigger_action(void *attrb)
+{
+	hid_sensor_remove_trigger(attrb);
+}
+
+int devm_hid_sensor_setup_trigger(struct device *dev, struct iio_dev

*indio_dev,

drivers/iio/common/hid-sensors/hid-sensor-trigger.c +1 -0
+				  const char *name, struct

hid_sensor_common *attrb)

drivers/iio/common/hid-sensors/hid-sensor-trigger.c +8 -0
+{
+	int ret;
+
+	ret = hid_sensor_setup_trigger(indio_dev, name, attrb);
+	if (ret)
+		return ret;
+
+	return devm_add_action_or_reset(dev,

hid_sensor_remove_trigger_action, attrb);

drivers/iio/common/hid-sensors/hid-sensor-trigger.c +3 -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 +0 -0
index afec46ecbe71..6fd7c39a240d 100644
@@ -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,

drivers/iio/common/hid-sensors/hid-sensor-trigger.h +1 -0
+				  const char *name, struct

hid_sensor_common *attrb);
 int hid_sensor_power_state(struct hid_sensor_common *st, bool state);

 #endif

Tested-by on the v3 series
#24 lore raw
In reply to Sanjay Chitroda
Quoted 77 lines

-----Original Message-----
From: Sanjay Chitroda <[email protected]>
Sent: Saturday, May 9, 2026 6:11 PM
To: [email protected]; [email protected]; [email protected]
Cc: Lechner, David <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: [PATCH v3 0/9] 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 cleanup and prepratory changes before updating driver for devm_
- few sample driver update using devm conversion to auto release resource

changes in v3:
- Added cleanup and prepratory changes before adding devm_ API conversion based on self review: 0002, 0004, 0006, 0007 and 0008
- Address andy's review comment on commit message and coding style
- v2 series -> https://lore.kernel.org/all/20260429175918.2541914-1-
[email protected]/
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/20260428071613.1134053-1-
[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 (9):
iio: hid-sensors: drop redundant iio_dev argument
iio: hid-sensors: cleanup codestyle warning
iio: hid-sensors: introduce device managed API
iio: gyro: hid-sensor-gyro-3d: cleanup codestyle warning
iio: gyro: hid-sensor-gyro-3d: drop hid_sensor_remove_trigger() using
devm API
iio: humidity: hid-sensor-humidity: cleanup codestyle check
iio: humidity: hid-sensor-humidity: use common device for devres
iio: humidity: hid-sensor-humidity: use local struct device
iio: humidity: hid-sensor-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   | 24 +++++++-
.../common/hid-sensors/hid-sensor-trigger.h   |  5 +-
drivers/iio/gyro/hid-sensor-gyro-3d.c         | 16 ++---
drivers/iio/humidity/hid-sensor-humidity.c    | 61 +++++++++----------
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, 78 insertions(+), 64 deletions(-)

base-commit: 39b80c5c9830d12d2d6531059001301c4265322a --
2.34.1

#25 lore raw
Quoted 1 line · Lixu

Hi Zhang,

Thanks for the testing and validaiton.
I hope you validated the complete series, including the unbind flow for the drivers using devm API.

Hi Jonathan,

How should we take this series forward? should I extend the series to cover remaining HID IIO drivers for this devm API, or this series can applied to IIO tree first and sent followup patches on top of that?

Thanks, Sanjay

Quoted 79 lines
Quoted 78 lines

-----Original Message-----
From: Sanjay Chitroda <[email protected]>
Sent: Saturday, May 9, 2026 6:11 PM
To: [email protected]; [email protected]; [email protected]
Cc: Lechner, David <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: [PATCH v3 0/9] 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 cleanup and prepratory changes before updating driver for devm_
- few sample driver update using devm conversion to auto release resource

changes in v3:
- Added cleanup and prepratory changes before adding devm_ API conversion based on self review: 0002, 0004, 0006, 0007 and 0008
- Address andy's review comment on commit message and coding style
- v2 series -> https://lore.kernel.org/all/20260429175918.2541914-1-
[email protected]/
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/20260428071613.1134053-1-
[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 (9):
iio: hid-sensors: drop redundant iio_dev argument
iio: hid-sensors: cleanup codestyle warning
iio: hid-sensors: introduce device managed API
iio: gyro: hid-sensor-gyro-3d: cleanup codestyle warning
iio: gyro: hid-sensor-gyro-3d: drop hid_sensor_remove_trigger() using
devm API
iio: humidity: hid-sensor-humidity: cleanup codestyle check
iio: humidity: hid-sensor-humidity: use common device for devres
iio: humidity: hid-sensor-humidity: use local struct device
iio: humidity: hid-sensor-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   | 24 +++++++-
.../common/hid-sensors/hid-sensor-trigger.h   |  5 +-
drivers/iio/gyro/hid-sensor-gyro-3d.c         | 16 ++---
drivers/iio/humidity/hid-sensor-humidity.c    | 61 +++++++++----------
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, 78 insertions(+), 64 deletions(-)

base-commit: 39b80c5c9830d12d2d6531059001301c4265322a --
2.34.1

maintainer
#26 lore raw
Quoted 9 lines · On Mon, 18 May 2026 01:49:51 +0530 Sanjay Chitroda…
Quoted 1 line · Lixu

Hi Zhang,

Thanks for the testing and validaiton.
I hope you validated the complete series, including the unbind flow for the drivers using devm API.

Quoted 5 lines

Hi Jonathan,

How should we take this series forward? should I extend the series to cover remaining HID IIO drivers for this devm API, or this series can applied to IIO tree first and sent followup patches on top of that?

There is just enough minor feedback on various patches that it needs a v4 I think, or response to those bits of review feedback to argue against the requested changes.

I'd like to see the new API applied everywhere unless there is a reason it's not suitable. Key aim being that the last patch should remove the now unused non devm functions or maybe make them private if they are still useful from a code structure point of view.

We may be waiting on testing though for some of them so make sure it is clear what Zhang has tested (obviously not the stuff you haven't sent yet :)

Jonathan

Quoted 83 lines

Thanks, Sanjay

Quoted 79 lines
Quoted 78 lines

-----Original Message-----
From: Sanjay Chitroda <[email protected]>
Sent: Saturday, May 9, 2026 6:11 PM
To: [email protected]; [email protected]; [email protected]
Cc: Lechner, David <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: [PATCH v3 0/9] 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 cleanup and prepratory changes before updating driver for devm_
- few sample driver update using devm conversion to auto release resource

changes in v3:
- Added cleanup and prepratory changes before adding devm_ API conversion based on self review: 0002, 0004, 0006, 0007 and 0008
- Address andy's review comment on commit message and coding style
- v2 series -> https://lore.kernel.org/all/20260429175918.2541914-1-
[email protected]/
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/20260428071613.1134053-1-
[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 (9):
iio: hid-sensors: drop redundant iio_dev argument
iio: hid-sensors: cleanup codestyle warning
iio: hid-sensors: introduce device managed API
iio: gyro: hid-sensor-gyro-3d: cleanup codestyle warning
iio: gyro: hid-sensor-gyro-3d: drop hid_sensor_remove_trigger() using
devm API
iio: humidity: hid-sensor-humidity: cleanup codestyle check
iio: humidity: hid-sensor-humidity: use common device for devres
iio: humidity: hid-sensor-humidity: use local struct device
iio: humidity: hid-sensor-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   | 24 +++++++-
.../common/hid-sensors/hid-sensor-trigger.h   |  5 +-
drivers/iio/gyro/hid-sensor-gyro-3d.c         | 16 ++---
drivers/iio/humidity/hid-sensor-humidity.c    | 61 +++++++++----------
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, 78 insertions(+), 64 deletions(-)

base-commit: 39b80c5c9830d12d2d6531059001301c4265322a --
2.34.1

#27 lore raw
In reply to Sanjay Chitroda
Quoted 11 lines

-----Original Message-----
From: Sanjay Chitroda <[email protected]>
Sent: Monday, May 18, 2026 4:20 AM
To: Zhang, Lixu <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Lechner, David <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v3 0/9] iio: introduce devm_ API for hid sensro setup and cleanup

Quoted 8 lines
Quoted 1 line · Lixu

Hi Zhang,

Thanks for the testing and validaiton.
I hope you validated the complete series, including the unbind flow for the drivers using devm API.

Hi Sanjay,

Yes, I validated the complete series. The unbind flow was tested as Srinivas previously suggested - performing the unbind while iio-sensor-proxy has an open session. No regression issues were observed.

Since iio-sensor-proxy does not typically open a gyro session, I applied the same changes from hid-sensor-gyro-3d to hid-sensor-accel-3d and tested the unbind flow on that driver as well. Again, no regression issues were found.

Thanks,
Lixu

Quoted 92 lines

Hi Jonathan,

How should we take this series forward? should I extend the series to cover remaining HID IIO drivers for this devm API, or this series can applied to IIO tree first and sent followup patches on top of that?

Thanks, Sanjay

Quoted 62 lines
Quoted 62 lines

-----Original Message-----
From: Sanjay Chitroda <[email protected]>
Sent: Saturday, May 9, 2026 6:11 PM
To: [email protected]; [email protected]; [email protected]
Cc: Lechner, David <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: [PATCH v3 0/9] 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 cleanup and prepratory changes before updating driver for devm_
- few sample driver update using devm conversion to auto release resource

changes in v3:
- Added cleanup and prepratory changes before adding devm_ API conversion based on self review: 0002, 0004, 0006, 0007 and 0008
- Address andy's review comment on commit message and coding style
- v2 series -> https://lore.kernel.org/all/20260429175918.2541914-1-
[email protected]/
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/20260428071613.1134053-1-
[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 (9):
iio: hid-sensors: drop redundant iio_dev argument
iio: hid-sensors: cleanup codestyle warning
iio: hid-sensors: introduce device managed API
iio: gyro: hid-sensor-gyro-3d: cleanup codestyle warning
iio: gyro: hid-sensor-gyro-3d: drop hid_sensor_remove_trigger() using
devm API
iio: humidity: hid-sensor-humidity: cleanup codestyle check
iio: humidity: hid-sensor-humidity: use common device for devres
iio: humidity: hid-sensor-humidity: use local struct device
iio: humidity: hid-sensor-humidity: drop hid_sensor_remove_trigger()
using devm API

Quoted 10 lines
Quoted 10 lines
drivers/iio/accel/hid-sensor-accel-3d.c       |  4 +-
.../common/hid-sensors/hid-sensor-trigger.c   | 24 +++++++-
.../common/hid-sensors/hid-sensor-trigger.h   |  5 +-
drivers/iio/gyro/hid-sensor-gyro-3d.c         | 16 ++---
drivers/iio/humidity/hid-sensor-humidity.c    | 61 +++++++++----------
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 +-

Quoted 10 lines
Quoted 9 lines
drivers/iio/pressure/hid-sensor-press.c       |  4 +-
.../iio/temperature/hid-sensor-temperature.c  |  4 +-
13 files changed, 78 insertions(+), 64 deletions(-)

base-commit: 39b80c5c9830d12d2d6531059001301c4265322a --
2.34.1