Re: [PATCH 00/35] iio: closing default trigger handling leaks

From: Andy Shevchenko

Date: Tue Nov 17 2026 - 02:20:58 EST


On Mon, Nov 16, 2026 at 01:47:48AM +0000, Jonathan Cameron wrote:
>
> Note this is compile tested only! I definitely want a few people
> to test that I didn't break everything.
>
> This is the first part of what I think is a long term solution to the
> currently really fragile ordering constraints around setting default
> triggers. Today these are set by iio_dev->trig = iio_trigger_get(trig).
> The reference is only released on the iio_dev.release callback and
> only if we have set the mode to include one that means there might be
> a trigger set. That mode set only occurs when a buffer is registered.
> Thus trigger release only works if we have already registered a buffer.
>
> One solution would be to reorder so that the default trigger is always
> set after the buffer registration (we have had various recent proposed
> patches to do that for individual drivers) but that is non obvious and
> fragile.
>
> The solution here is easier to reason about. Decouple the setting
> of the default trigger from the acquisition of a reference. Thus
> we can acquire the reference in iio_device_register() when we know
> all the conditions for it's release have been achieved.
> So that's all we do in this part 1 series.
>
> Part 2 will address immutable triggers and those that are effectively
> immutable but predate that logic. That is those that set a one to one
> relationship between device and trigger. That change is rather less
> mechanical than this one and 35 patches is really a bit big anyway
> even if most of them are small!
>
> Part 3 and beyond will move to a situation where the iio_dev->trig
> will become opaque. That should stop anyone manipulating that directly.
> I have a few related cunning plans to test out before we get to that,
> not because the particular challenge is hard, but because they will
> trample on the same code.

> Jonathan Cameron (35):
> iio: core: add default_trigger and take reference in
> iio_device_register()

I have reviewed the first patch and briefly looked at the rest which seems
like a semi-automatic translation in most cases.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>

> media: pci: mgb4: use IIO default_trigger
> iio: chemical: ens160: use default_trigger
> iio: adc: ad4130: use default_trigger
> iio: adc: ad4170-4: use default_trigger
> iio: adc: ad7768-1: use default_trigger
> iio: adc: ad7779: use default_trigger
> iio: adc: ti-ads131e08: use default_trigger
> iio: addac: ad74115: use default_trigger
> iio: addac: ad74413r: use default_trigger
> iio: temperature: tmp006: use default_trigger
> iio: adc: ad4062: use default_trigger
> iio: accel: bma220: use default_trigger
> iio: accel: bma400: use default_trigger
> iio: imu: smi330: use default_trigger
> iio: light: acpi-als: use default_trigger
> iio: chemical: scd30: use default_trigger
> iio: accel: bma180: use default_trigger
> iio: accel: kxcjk-1013: use default_trigger
> iio: accel: mma8452: use default_trigger
> iio: chemical: ccs811: use default_trigger
> iio: pressure: mpl3115: use default_trigger
> iio: common: st_sensors: use default_trigger
> iio: common: hid-sensors: use default_trigger
> iio: pressure: bmp280: use default_trigger
> iio: light: vl6180: use default_trigger
> iio: gyro: itg3200: use default_trigger
> iio: imu: bmi160: use default_trigger
> iio: accel: adxl355: use default_trigger
> iio: gyro: adxrs290: use default_trigger
> iio: accel: adxl372: use default_trigger
> iio: light: si1145: use default_trigger
> iio: adc: ti-tsc2046: use default_trigger
> iio: accel: mxc4005: use default_trigger
> iio: gyro: mpu3050: use default_trigger

--
With Best Regards,
Andy Shevchenko