[PATCH 24/35] iio: common: hid-sensors: use default_trigger

From: Jonathan Cameron

Date: Sun Nov 15 2026 - 20:52:17 EST


From: Jonathan Cameron <jonathan.cameron@xxxxxxxxxxxxxxxx>

Set indio_dev->default_trigger rather than taking a reference to the
trigger in hid_sensor_setup_trigger(). The IIO core now takes the
reference during iio_device_register(), so it is not leaked if probe()
fails after the trigger is set up.

Set it only once nothing else in hid_sensor_setup_trigger() can fail,
so the error path does not leave it pointing at the freed trigger.

All users call devm_hid_sensor_setup_trigger() before
devm_iio_device_register() and do not access indio_dev->trig.

The ordering in this driver ensures there is no leak today but
this patch will make that ordering much less fragile going forwards.

Signed-off-by: Jonathan Cameron <jonathan.cameron@xxxxxxxxxxxxxxxx>
---
drivers/iio/common/hid-sensors/hid-sensor-trigger.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
index df6c07d6a6b7..44fb4bd1d316 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
@@ -278,12 +278,13 @@ int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
goto error_free_trig;
}
attrb->trigger = trig;
- indio_dev->trig = iio_trigger_get(trig);

ret = pm_runtime_set_active(&indio_dev->dev);
if (ret)
goto error_unreg_trigger;

+ indio_dev->default_trigger = trig;
+
iio_device_set_drvdata(indio_dev, attrb);

INIT_WORK(&attrb->work, hid_sensor_set_power_work);
--
2.56.1