IIO: Ensure iio_trigger_poll() is of the device owned trigger.
Subsystems (11)
Jonathan Cameron
maintainercover IIO: Ensure iio_trigger_poll() is of the device owned trigger.
From: Jonathan Cameron <[email protected]>
Resend due to wrong linux-iio email address. Sorry for the noise!
LLM used to help pull this fairly straight forward series together.
The primary aim here is to ensure a clean layering between the two sides of the trigger / pollfunc (push to buffers) divide. The caller of iio_trigger_poll() and iio_trigger_poll_nested() should be using data relevant to the trigger, not iio_dev->trig which is the current_trigger for the device. Most drivers got this layering right, but not this set!
This is also step 1 in a plan to make iio_dev->trig opaque allowing more control of how it is assigned and avoiding traps around lifetimes.
Includes one precursor fix that has been broken long enough I think we can just merge it via the slow path along with the rest of these.
Jonathan Cameron (14):
iio: accel: mma8452: unregister own trigger rather than current one
iio: accel: mma8452: poll own trigger from interrupt handler
iio: adc: max1027: poll own trigger from interrupt handler
iio: adc: ti-ads1119: poll own trigger from interrupt handler
iio: adc: mxs-lradc-adc: poll own trigger from interrupt handler
iio: adc: at91-sama5d2: poll own trigger on data ready interrupt
iio: light: vl6180: poll own trigger from interrupt handler
iio: proximity: vl53l0x-i2c: poll own trigger from interrupt handler
iio: adc: ad4691: poll own trigger from interrupt handler
iio: chemical: scd30: poll own trigger from interrupt handler
iio: proximity: vl53l1x-i2c: poll own trigger from interrupt handler
iio: proximity: irsd200: poll own trigger from interrupt handler
iio: light: vcnl4000: poll own trigger from interrupt handler
iio: adc: at91_adc: poll the enabled trigger from interrupt handler
drivers/iio/accel/mma8452.c | 11 ++++++++--- drivers/iio/adc/ad4691.c | 4 +++- drivers/iio/adc/at91-sama5d2_adc.c | 2 +- drivers/iio/adc/at91_adc.c | 6 ++++-- drivers/iio/adc/max1027.c | 2 +- drivers/iio/adc/mxs-lradc-adc.c | 2 +- drivers/iio/adc/ti-ads1119.c | 2 +- drivers/iio/chemical/scd30.h | 2 ++ drivers/iio/chemical/scd30_core.c | 4 +++- drivers/iio/light/vcnl4000.c | 4 +++- drivers/iio/light/vl6180.c | 2 +- drivers/iio/proximity/irsd200.c | 4 +++- drivers/iio/proximity/vl53l0x-i2c.c | 2 +- drivers/iio/proximity/vl53l1x-i2c.c | 4 +++- 14 files changed, 35 insertions(+), 16 deletions(-)
Signature · 1 line
2.56.0
Jonathan Cameron
maintainerPATCH RESEND 1/14 iio: accel: mma8452: unregister own trigger rather than current one
From: Jonathan Cameron <[email protected]>
mma8452_trigger_cleanup() uses indio_dev->trig to unregister the trigger. That may or may not be the one it registered as this driver allows triggers other than its own to be used.
Keep a pointer to the driver's own trigger in struct mma8452_data and unregister that instead.
--- drivers/iio/accel/mma8452.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/iio/accel/mma8452.c +7 -2
@@ -115,6 +115,7 @@* @orientation: mounting matrix, flipped axis etc. * @chip_info: chip specific data * @regs: reference to voltage regulators +* @trig: data ready trigger, if an interrupt is available * @buffer: triggered buffer * @sleep_val: time in ms to sleep while waiting for drdy * @ctrl_reg1: CTRL_REG1 register shadow value
@@ -127,6 +128,7 @@ struct mma8452_data {struct iio_mount_matrix orientation;const struct mma_chip_info *chip_info;struct regulator_bulk_data regs[2 ]; +struct iio_trigger *trig;/* Ensure correct alignment of time stamp when present */ struct {
@@ -1526,6 +1528,7 @@ static int mma8452_trigger_setup(struct iio_dev *indio_dev)if (ret)return ret; + data->trig = trig; indio_dev->trig =iio_trigger_get (trig);return 0 ;
@@ -1533,8 +1536,10 @@ static int mma8452_trigger_setup(struct iio_dev *indio_dev)static void mma8452_trigger_cleanup (struct iio_dev *indio_dev) { -if (indio_dev->trig) -iio_trigger_unregister (indio_dev->trig); +struct mma8452_data *data =iio_priv (indio_dev); + +if (data->trig) +iio_trigger_unregister (data->trig); }static int mma8452_reset (struct i2c_client *client)
Signature · 1 line
2.56.0
Jonathan Cameron
maintainerPATCH RESEND 2/14 iio: accel: mma8452: poll own trigger from interrupt handler
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
Poll data->trig from mma8452_interrupt() rather than indio_dev->trig. The data ready interrupt is only enabled by the driver's own trigger's set_trigger_state() callback, so that is the trigger in use whenever this path is reached.
This removes a dependency on the trig field of struct iio_dev, which is to become private to the IIO core.
--- drivers/iio/accel/mma8452.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/accel/mma8452.c +1 -1
@@ -1099,7 +1099,7 @@ static irqreturn_t mma8452_interrupt(int irq, void *p)return IRQ_NONE ;if (src &MMA8452_INT_DRDY ) { -iio_trigger_poll_nested (indio_dev->trig); +iio_trigger_poll_nested (data->trig); ret =IRQ_HANDLED ; }
Signature · 1 line
2.56.0
Jonathan Cameron
maintainerPATCH RESEND 3/14 iio: adc: max1027: poll own trigger from interrupt handler
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
Poll st->trig from max1027_handler() rather than indio_dev->trig. The poll is only reached when the buffer is enabled and the device's own trigger is in use.
This removes a dependency on the trig field of struct iio_dev, which is to become private to the IIO core.
--- drivers/iio/adc/max1027.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/max1027.c +1 -1
@@ -481,7 +481,7 @@ static irqreturn_t max1027_handler(int irq, void *private)if (!iio_buffer_enabled (indio_dev) || !iio_trigger_using_own (indio_dev))complete (&st->complete);else -iio_trigger_poll (indio_dev->trig); +iio_trigger_poll (st->trig);return IRQ_HANDLED ; }
Signature · 1 line
2.56.0
Re: [RESEND PATCH 03/14] iio: adc: max1027: poll own trigger from interrupt handler
Quoted 10 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Poll
st->trigfrommax1027_handler()rather thanindio_dev->trig. The poll is only reached when the buffer is enabled and the device's own trigger is in use.This removes a dependency on the trig field of struct
iio_dev, which is to become private to the IIO core.Signed-off-by Jonathan Cameron <[email protected]>
Jonathan Cameron
maintainerPATCH RESEND 4/14 iio: adc: ti-ads1119: poll own trigger from interrupt handler
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
Poll st->trig from ads1119_irq_handler() rather than indio_dev->trig. The poll is only reached when iio_trigger_using_own() is true.
This removes a dependency on the trig field of struct iio_dev, which is to become private to the IIO core.
--- drivers/iio/adc/ti-ads1119.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ti-ads1119.c +1 -1
@@ -497,7 +497,7 @@ static irqreturn_t ads1119_irq_handler(int irq, void *dev_id)struct ads1119_state *st =iio_priv (indio_dev);if (iio_buffer_enabled (indio_dev) &&iio_trigger_using_own (indio_dev)) -iio_trigger_poll (indio_dev->trig); +iio_trigger_poll (st->trig);else complete (&st->completion);
Signature · 1 line
2.56.0
Jonathan Cameron
maintainerPATCH RESEND 5/14 iio: adc: mxs-lradc-adc: poll own trigger from interrupt handler
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
Poll adc->trig from the interrupt handler rather than iio->trig. Conversions that raise this interrupt are only started when the driver's own trigger is enabled, via its set_trigger_state() callback.
This removes a dependency on the trig field of struct iio_dev, which is to become private to the IIO core.
--- drivers/iio/adc/mxs-lradc-adc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/mxs-lradc-adc.c +1 -1
@@ -393,7 +393,7 @@ static irqreturn_t mxs_lradc_adc_handle_irq(int irq, void *data)if (iio_buffer_enabled (iio)) {if (reg & lradc->buffer_vchans) {spin_lock_irqsave (&adc->lock, flags); -iio_trigger_poll (iio->trig); +iio_trigger_poll (adc->trig);spin_unlock_irqrestore (&adc->lock, flags); } }else if (reg &LRADC_CTRL1_LRADC_IRQ (0 )) {
Signature · 1 line
2.56.0
Jonathan Cameron
maintainerPATCH RESEND 6/14 iio: adc: at91-sama5d2: poll own trigger on data ready interrupt
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
Poll st->trig from the data ready interrupt path rather than indio->trig. The data ready interrupt is only enabled for the triggered buffer when DMA is not in use and the device's own trigger is in use, see at91_adc_buffer_check_use_irq().
The DMA completion callback still polls indio_dev->trig as it must run the pollfunc on whichever trigger the device is using.
This removes one dependency on the trig field of struct iio_dev, which is to become private to the IIO core.
--- drivers/iio/adc/at91-sama5d2_adc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/at91-sama5d2_adc.c +1 -1
@@ -1711,7 +1711,7 @@ static irqreturn_t at91_adc_interrupt(int irq, void *private) (status & AT91_SAMA5D2_IER_DRDY)) {/* triggered buffer without DMA */ disable_irq_nosync (irq); -iio_trigger_poll (indio->trig); +iio_trigger_poll (st->trig); } else if (iio_buffer_enabled(indio) && st->dma_st.dma_chan) {/* triggered buffer with DMA - should not happen */ disable_irq_nosync (irq);
Signature · 1 line
2.56.0
Jonathan Cameron
maintainerPATCH RESEND 7/14 iio: light: vl6180: poll own trigger from interrupt handler
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
Poll data->trig from vl6180_threaded_irq() rather than indio_dev->trig. The poll is only reached with the buffer enabled, which is only possible with the driver's own trigger as iio_validate_own_trigger() rejects any other.
This removes a dependency on the trig field of struct iio_dev, which is to become private to the IIO core.
--- drivers/iio/light/vl6180.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/vl6180.c +1 -1
@@ -525,7 +525,7 @@ static irqreturn_t vl6180_threaded_irq(int irq, void *priv)struct vl6180_data *data =iio_priv (indio_dev);if (iio_buffer_enabled (indio_dev)) -iio_trigger_poll_nested (indio_dev->trig); +iio_trigger_poll_nested (data->trig);else complete (&data->completion);
Signature · 1 line
2.56.0
Jonathan Cameron
maintainerPATCH RESEND 8/14 iio: proximity: vl53l0x-i2c: poll own trigger from interrupt handler
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
Poll data->trig from vl53l0x_threaded_irq() rather than indio_dev->trig. vl53l0x_validate_trigger() only accepts the driver's own trigger, so with the buffer enabled that is the trigger in use.
This removes a dependency on the trig field of struct iio_dev, which is to become private to the IIO core.
--- drivers/iio/proximity/vl53l0x-i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/proximity/vl53l0x-i2c.c +1 -1
@@ -107,7 +107,7 @@ static irqreturn_t vl53l0x_threaded_irq(int irq, void *priv)struct vl53l0x_data *data =iio_priv (indio_dev);if (iio_buffer_enabled (indio_dev)) -iio_trigger_poll_nested (indio_dev->trig); +iio_trigger_poll_nested (data->trig);else complete (&data->completion);
Signature · 1 line
2.56.0
Jonathan Cameron
maintainerPATCH RESEND 9/14 iio: adc: ad4691: poll own trigger from interrupt handler
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
Keep a pointer to the CNV burst trigger in struct ad4691_state and poll that from ad4691_irq() rather than indio_dev->trig. The interrupt is only enabled for CNV burst mode with the buffer enabled, and the iio_info used in that mode only accepts the driver's own trigger via iio_validate_own_trigger(), so this is the same trigger.
This removes a dependency on the trig field of struct iio_dev, which is to become private to the IIO core.
--- drivers/iio/adc/ad4691.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/adc/ad4691.c +3 -1
@@ -441,6 +441,7 @@ struct ad4691_state {struct spi_device *spi;struct pwm_device *conv_trigger; +struct iio_trigger *trig;int irq;int vref_uV;u32 cnv_period_ns;
@@ -1563,7 +1564,7 @@ static irqreturn_t ad4691_irq(int irq, void *private)* the IRQ. */ disable_irq_nosync (st->irq); -iio_trigger_poll (indio_dev->trig); +iio_trigger_poll (st->trig);return IRQ_HANDLED ; }
@@ -1861,6 +1862,7 @@ static int ad4691_setup_triggered_buffer(struct iio_dev *indio_dev,if (!trig)return -ENOMEM ; + st->trig = trig; trig->ops = &ad4691_trigger_ops;iio_trigger_set_drvdata (trig, st);
Signature · 1 line
2.56.0
Jonathan Cameron
maintainerPATCH RESEND 10/14 iio: chemical: scd30: poll own trigger from interrupt handler
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
Keep a pointer to the driver's trigger in struct scd30_state and poll that from scd30_irq_handler() rather than indio_dev->trig. With the buffer enabled, the interrupt is only enabled by the trigger's set_trigger_state() callback, so it is the driver's own trigger that is in use.
This removes a dependency on the trig field of struct iio_dev, which is to become private to the IIO core.
--- drivers/iio/chemical/scd30.h | 2 ++ drivers/iio/chemical/scd30_core.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/iio/chemical/scd30.h +2 -0
@@ -9,6 +9,7 @@#include <linux/regulator/consumer.h> #include <linux/types.h> +struct iio_trigger ;struct scd30_state ;enum scd30_cmd {
@@ -57,6 +58,7 @@ struct scd30_state {*/ void *priv;int irq; +struct iio_trigger *trig;/* * no way to retrieve current ambient pressure compensation value from * the sensor so keep one around
drivers/iio/chemical/scd30_core.c +3 -1
@@ -573,9 +573,10 @@ static void scd30_disable_regulator(void *data)static irqreturn_t scd30_irq_handler (int irq,void *priv) {struct iio_dev *indio_dev = priv; +struct scd30_state *state =iio_priv (indio_dev);if (iio_buffer_enabled (indio_dev)) { -iio_trigger_poll (indio_dev->trig); +iio_trigger_poll (state->trig);return IRQ_HANDLED ; }
@@ -666,6 +667,7 @@ static int scd30_setup_trigger(struct iio_dev *indio_dev)if (!trig)return -ENOMEM ; + state->trig = trig; trig->ops = &scd30_trigger_ops;iio_trigger_set_drvdata (trig, indio_dev);
Signature · 1 line
2.56.0
Jonathan Cameron
maintainerPATCH RESEND 11/14 iio: proximity: vl53l1x-i2c: poll own trigger from interrupt handler
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
Keep a pointer to the driver's trigger in struct vl53l1x_data and poll that from vl53l1x_irq_handler() rather than indio_dev->trig. Only the driver's own trigger is accepted, via iio_validate_own_trigger(), so with the buffer enabled that is the trigger in use.
This removes a dependency on the trig field of struct iio_dev, which is to become private to the IIO core.
--- drivers/iio/proximity/vl53l1x-i2c.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/proximity/vl53l1x-i2c.c +3 -1
@@ -102,6 +102,7 @@ struct vl53l1x_data {enum vl53l1x_distance_mode distance_mode;u8 gpio_polarity;int irq; +struct iio_trigger *trig; };static const struct regmap_range vl53l1x_volatile_ranges[] = {
@@ -587,7 +588,7 @@ static irqreturn_t vl53l1x_irq_handler(int irq, void *priv)struct vl53l1x_data *data =iio_priv (indio_dev);if (iio_buffer_enabled (indio_dev)) -iio_trigger_poll (indio_dev->trig); +iio_trigger_poll (data->trig);else complete (&data->completion);
@@ -707,6 +708,7 @@ static int vl53l1x_probe(struct i2c_client *client)if (!trig)return -ENOMEM ; + data->trig = trig; trig->ops = &vl53l1x_trigger_ops;iio_trigger_set_drvdata (trig, indio_dev); ret =devm_iio_trigger_register (dev, trig);
Signature · 1 line
2.56.0
Re: [RESEND PATCH 11/14] iio: proximity: vl53l1x-i2c: poll own trigger from interrupt handler
Quoted 20 lines · On Mon, 9 Nov 2026 04:28:48 +0000 Jonathan Cameron <[email protected]> wrote:
From: Jonathan Cameron <[email protected]>
Keep a pointer to the driver's trigger in struct
vl53l1x_dataand poll that fromvl53l1x_irq_handler()rather thanindio_dev->trig. Only the driver's own trigger is accepted, viaiio_validate_own_trigger(), so with the buffer enabled that is the trigger in use.This removes a dependency on the trig field of struct
iio_dev, which is to become private to the IIO core.Signed-off-by Jonathan Cameron <[email protected]>--- drivers/iio/proximity/vl53l1x-i2c.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/iio/proximity/vl53l1x-i2c.c +0
-0
drivers/iio/proximity/vl53l1x-i2c.c struct vl53l1x_data { · line 105
Quoted 4 lines
drivers/iio/proximity/vl53l1x-i2c.c +1
-0@@ -102,6 +102,7 @@ struct vl53l1x_data {enum vl53l1x_distance_mode distance_mode;u8 gpio_polarity;int irq; +struct iio_trigger *trig;
Pahole reports a 4 byte hole between irq and trig. Reordering like this yields a better result:
struct regmap * regmap; /* 0 8 */
struct completion completion __attribute__((__aligned__(8))); /* 8 32 */
/* XXX last struct has 1 hole */
struct reset_control * xshut_reset; /* 40 8 */ struct iio_trigger * trig; /* 48 8 */ enum vl53l1x_distance_mode distance_mode; /* 56 4 */ int irq; /* 60 4 */
/* --- cacheline 1 boundary (64 bytes) --- */
u8 gpio_polarity; /* 64 1 */
Signature · 2 lines
Kind regards, Joshua Crofts
Jonathan Cameron
maintainerRe: [RESEND PATCH 11/14] iio: proximity: vl53l1x-i2c: poll own trigger from interrupt handler
Quoted 34 lines · On Mon, 9 Nov 2026 09:42:02 +0100 Joshua Crofts <[email protected]> wrote:
Quoted 20 lines · On Mon, 9 Nov 2026 04:28:48 +0000 Jonathan Cameron <[email protected]> wrote:
From: Jonathan Cameron <[email protected]>
Keep a pointer to the driver's trigger in struct
vl53l1x_dataand poll that fromvl53l1x_irq_handler()rather thanindio_dev->trig. Only the driver's own trigger is accepted, viaiio_validate_own_trigger(), so with the buffer enabled that is the trigger in use.This removes a dependency on the trig field of struct
iio_dev, which is to become private to the IIO core.Signed-off-by Jonathan Cameron <[email protected]>--- drivers/iio/proximity/vl53l1x-i2c.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/iio/proximity/vl53l1x-i2c.c +0
-0drivers/iio/proximity/vl53l1x-i2c.c struct vl53l1x_data { · line 105
Quoted 4 lines
drivers/iio/proximity/vl53l1x-i2c.c +1
-0@@ -102,6 +102,7 @@ struct vl53l1x_data {enum vl53l1x_distance_mode distance_mode;u8 gpio_polarity;int irq; +struct iio_trigger *trig;Pahole reports a 4 byte hole between irq and trig. Reordering like this yields a better result:
struct regmap * regmap; /* 0 8 */
struct completion completion __attribute__((__aligned__(8))); /* 8 32 */
Quoted 9 lines
/* XXX last struct has 1 hole */
struct reset_control * xshut_reset; /* 40 8 */ struct iio_trigger * trig; /* 48 8 */ enum vl53l1x_distance_mode distance_mode; /* 56 4 */ int irq; /* 60 4 *//* --- cacheline 1 boundary (64 bytes) --- */
u8gpio_polarity; /* 64 1 */
Good point. I guess I need to poke my llm to take this into account.
tweaked whilst applying.
Thanks,
Jonathan
Jonathan Cameron
maintainerPATCH RESEND 12/14 iio: proximity: irsd200: poll own trigger from interrupt handler
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
Keep a pointer to the driver's trigger in struct irsd200_data and poll that from irsd200_irq_thread() rather than indio_dev->trig. The data interrupt source is only enabled by the trigger's set_trigger_state() callback, so it is the driver's own trigger that is in use whenever this path is reached.
This removes a dependency on the trig field of struct iio_dev, which is to become private to the IIO core.
--- drivers/iio/proximity/irsd200.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/proximity/irsd200.c +3 -1
@@ -122,6 +122,7 @@ struct irsd200_data {struct regmap *regmap;struct regmap_field *regfields[IRS_REGF_MAX ];struct device *dev; +struct iio_trigger *trig; };static int irsd200_setup (struct irsd200_data *data)
@@ -698,7 +699,7 @@ static irqreturn_t irsd200_irq_thread(int irq, void *dev_id) }if (status &BIT (IRS_INTR_DATA ) &&iio_buffer_enabled (indio_dev)) { -iio_trigger_poll_nested (indio_dev->trig); +iio_trigger_poll_nested (data->trig); clear |=BIT (IRS_INTR_DATA ); }
@@ -917,6 +918,7 @@ static int irsd200_probe(struct i2c_client *client)if (!trigger)return -ENOMEM ; + data->trig = trigger; trigger->ops = &irsd200_trigger_ops;iio_trigger_set_drvdata (trigger, data);
Signature · 1 line
2.56.0
Jonathan Cameron
maintainerPATCH RESEND 13/14 iio: light: vcnl4000: poll own trigger from interrupt handler
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
Keep a pointer to the driver's trigger in struct vcnl4000_data and poll that from vcnl4010_irq_thread() on a data ready interrupt rather than indio_dev->trig.
With the driver's own trigger in use this is the same trigger. The driver does not restrict which trigger may be used and the data ready interrupt is enabled whenever the buffer is enabled, so with another trigger in use the data ready interrupt previously also polled that trigger, running its consumers in addition to when it fired itself. Now samples are only captured when the selected trigger fires, with the trigger handler clearing the data ready status as before.
This removes a dependency on the trig field of struct iio_dev, which is to become private to the IIO core.
--- drivers/iio/light/vcnl4000.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/light/vcnl4000.c +3 -1
@@ -206,6 +206,7 @@ struct vcnl4000_data {struct vcnl4200_channel vcnl4200_al;struct vcnl4200_channel vcnl4200_ps;uint32_t near_level; +struct iio_trigger *trig; };struct vcnl4000_chip_spec {
@@ -1547,7 +1548,7 @@ static irqreturn_t vcnl4010_irq_thread(int irq, void *p) }if (isr &VCNL4010_INT_DRDY &&iio_buffer_enabled (indio_dev)) -iio_trigger_poll_nested (indio_dev->trig); +iio_trigger_poll_nested (data->trig); end:return IRQ_HANDLED ;
@@ -1893,6 +1894,7 @@ static int vcnl4010_probe_trigger(struct iio_dev *indio_dev)if (!trigger)return -ENOMEM ; + data->trig = trigger; trigger->ops = &vcnl4010_trigger_ops;iio_trigger_set_drvdata (trigger, indio_dev);
Signature · 1 line
2.56.0
Re: [RESEND PATCH 13/14] iio: light: vcnl4000: poll own trigger from interrupt handler
Quoted 27 lines · On Mon, 9 Nov 2026 04:28:50 +0000 Jonathan Cameron <[email protected]> wrote:
From: Jonathan Cameron <[email protected]>
Keep a pointer to the driver's trigger in struct
vcnl4000_dataand poll that fromvcnl4010_irq_thread()on a data ready interrupt rather thanindio_dev->trig.With the driver's own trigger in use this is the same trigger. The driver does not restrict which trigger may be used and the data ready interrupt is enabled whenever the buffer is enabled, so with another trigger in use the data ready interrupt previously also polled that trigger, running its consumers in addition to when it fired itself. Now samples are only captured when the selected trigger fires, with the trigger handler clearing the data ready status as before.
This removes a dependency on the trig field of struct
iio_dev, which is to become private to the IIO core.Signed-off-by Jonathan Cameron <[email protected]>--- drivers/iio/light/vcnl4000.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/iio/light/vcnl4000.c +0
-0
drivers/iio/light/vcnl4000.c struct vcnl4000_data { · line 209
Quoted 4 lines
drivers/iio/light/vcnl4000.c +1
-0@@ -206,6 +206,7 @@ struct vcnl4000_data {struct vcnl4200_channel vcnl4200_al;struct vcnl4200_channel vcnl4200_ps;uint32_t near_level; +struct iio_trigger *trig;
Just swap near_level and trig and you'll eliminate a 4 byte hole.
Signature · 2 lines
Kind regards, Joshua Crofts
Jonathan Cameron
maintainerRe: [RESEND PATCH 13/14] iio: light: vcnl4000: poll own trigger from interrupt handler
Quoted 25 lines · On Mon, 9 Nov 2026 09:46:32 +0100 Joshua Crofts <[email protected]> wrote:
Quoted 22 lines · On Mon, 9 Nov 2026 04:28:50 +0000 Jonathan Cameron <[email protected]> wrote:
From: Jonathan Cameron <[email protected]>
Keep a pointer to the driver's trigger in struct
vcnl4000_dataand poll that fromvcnl4010_irq_thread()on a data ready interrupt rather thanindio_dev->trig.With the driver's own trigger in use this is the same trigger. The driver does not restrict which trigger may be used and the data ready interrupt is enabled whenever the buffer is enabled, so with another trigger in use the data ready interrupt previously also polled that trigger, running its consumers in addition to when it fired itself. Now samples are only captured when the selected trigger fires, with the trigger handler clearing the data ready status as before.
This removes a dependency on the trig field of struct
iio_dev, which is to become private to the IIO core.Signed-off-by Jonathan Cameron <[email protected]>--- drivers/iio/light/vcnl4000.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 12 lines
drivers/iio/light/vcnl4000.c struct vcnl4000_data { · line 209
Quoted 9 lines
drivers/iio/light/vcnl4000.c +1
-0@@ -206,6 +206,7 @@ struct vcnl4000_data {struct vcnl4200_channel vcnl4200_al;struct vcnl4200_channel vcnl4200_ps;uint32_t near_level; +struct iio_trigger *trig;Just swap
near_leveland trig and you'll eliminate a 4 byte hole.
tweaked.
Jonathan Cameron
maintainerPATCH RESEND 14/14 iio: adc: at91_adc: poll the enabled trigger from interrupt handler
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
The driver registers several hardware triggers, any of which may be selected. The end of conversion interrupt is only enabled for buffered capture by the set_trigger_state() callback of the trigger being enabled, and handle_adc_eoc_trigger() then polls indio_dev->trig.
Record the trigger in at91_adc_configure_trigger() before enabling the interrupt and poll that instead. It is not cleared on disable so that an interrupt still in flight polls the same trigger as before rather than dereferencing NULL.
Also use the trigger passed to at91_adc_configure_trigger() to look up its configuration rather than indio_dev->trig, which is the same trigger.
This removes the driver's dependencies on the trig field of struct iio_dev, which is to become private to the IIO core.
--- drivers/iio/adc/at91_adc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/iio/adc/at91_adc.c +4 -2
@@ -229,6 +229,7 @@ struct at91_adc_state {u8 sample_hold_time;bool sleep_mode;struct iio_trigger **trig; +struct iio_trigger *cur_trig;/* last enabled of trig[] */ bool use_external;u32 vref_mv;u32 res;/* resolution used for conversions */
@@ -294,7 +295,7 @@ static void handle_adc_eoc_trigger(int irq, struct iio_dev *idev)if (iio_buffer_enabled (idev)) {disable_irq_nosync (irq); -iio_trigger_poll (idev->trig); +iio_trigger_poll (st->cur_trig); }else { st->last_value =at91_adc_readl (st,AT91_ADC_CHAN (st, st->chnb));/* Needed to ACK the DRDY interruption */
@@ -562,7 +563,7 @@ static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state) value =at91_adc_get_trigger_value_by_name (idev, st->caps->triggers, - idev->trig->name); + trig->name);if (value <0 )return value;
@@ -581,6 +582,7 @@ static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state) AT91_ADC_CH(chan->channel)); } + st->cur_trig = trig;at91_adc_writel (st,AT91_ADC_IER , reg->drdy_mask); }else {
Signature · 1 line
2.56.0
Quoted 13 lines · On Mon, 9 Nov 2026 04:28:37 +0000 Jonathan Cameron <[email protected]> wrote:
From: Jonathan Cameron <[email protected]>
Resend due to wrong linux-iio email address. Sorry for the noise!
LLM used to help pull this fairly straight forward series together.
The primary aim here is to ensure a clean layering between the two sides of the trigger / pollfunc (push to buffers) divide. The caller of
iio_trigger_poll()andiio_trigger_poll_nested()should be using data relevant to the trigger, notiio_dev->trigwhich is thecurrent_triggerfor the device. Most drivers got this layering right, but not this set!
Quoted 5 lines
This is also step 1 in a plan to make
iio_dev->trigopaque allowing more control of how it is assigned and avoiding traps around lifetimes.Includes one precursor fix that has been broken long enough I think we can just merge it via the slow path along with the rest of these.
Patch 3 doesn't apply on iio/togreg (I see you're missing a base commit).
I only have a few pahole nits, otherwise LGTM.
Signature · 2 lines
Kind regards, Joshua Crofts
Quoted 35 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Resend due to wrong linux-iio email address. Sorry for the noise!
LLM used to help pull this fairly straight forward series together.
The primary aim here is to ensure a clean layering between the two sides of the trigger / pollfunc (push to buffers) divide. The caller of
iio_trigger_poll()andiio_trigger_poll_nested()should be using data relevant to the trigger, notiio_dev->trigwhich is thecurrent_triggerfor the device. Most drivers got this layering right, but not this set!This is also step 1 in a plan to make
iio_dev->trigopaque allowing more control of how it is assigned and avoiding traps around lifetimes.Includes one precursor fix that has been broken long enough I think we can just merge it via the slow path along with the rest of these.
Jonathan Cameron (14):
iio: accel: mma8452: unregister own trigger rather than current one
iio: accel: mma8452: poll own trigger from interrupt handler
iio: adc: max1027: poll own trigger from interrupt handler
iio: adc: ti-ads1119: poll own trigger from interrupt handler
iio: adc: mxs-lradc-adc: poll own trigger from interrupt handler
iio: adc: at91-sama5d2: poll own trigger on data ready interrupt
iio: light: vl6180: poll own trigger from interrupt handler
iio: proximity: vl53l0x-i2c: poll own trigger from interrupt handler
iio: adc: ad4691: poll own trigger from interrupt handler
iio: chemical: scd30: poll own trigger from interrupt handler
iio: proximity: vl53l1x-i2c: poll own trigger from interrupt handler
iio: proximity: irsd200: poll own trigger from interrupt handler
iio: light: vcnl4000: poll own trigger from interrupt handler
iio: adc:at91_adc: poll the enabled trigger from interrupt handler
Quoted 19 lines
drivers/iio/accel/mma8452.c | 11 ++++++++--- drivers/iio/adc/ad4691.c | 4 +++- drivers/iio/adc/at91-sama5d2_adc.c | 2 +- drivers/iio/adc/at91_adc.c | 6 ++++-- drivers/iio/adc/max1027.c | 2 +- drivers/iio/adc/mxs-lradc-adc.c | 2 +- drivers/iio/adc/ti-ads1119.c | 2 +- drivers/iio/chemical/scd30.h | 2 ++ drivers/iio/chemical/scd30_core.c | 4 +++- drivers/iio/light/vcnl4000.c | 4 +++- drivers/iio/light/vl6180.c | 2 +- drivers/iio/proximity/irsd200.c | 4 +++- drivers/iio/proximity/vl53l0x-i2c.c | 2 +- drivers/iio/proximity/vl53l1x-i2c.c | 4 +++- 14 files changed, 35 insertions(+), 16 deletions(-)Signature · 1 line
2.56.0
LGTM
Quoted 13 lines · On Mon, Nov 09, 2026 at 04:28 +0000 Jonathan Cameron <[email protected]> wrote:
From: Jonathan Cameron <[email protected]>
Resend due to wrong linux-iio email address. Sorry for the noise!
LLM used to help pull this fairly straight forward series together.
The primary aim here is to ensure a clean layering between the two sides of the trigger / pollfunc (push to buffers) divide. The caller of
iio_trigger_poll()andiio_trigger_poll_nested()should be using data relevant to the trigger, notiio_dev->trigwhich is thecurrent_triggerfor the device. Most drivers got this layering right, but not this set!
Quoted 5 lines
This is also step 1 in a plan to make
iio_dev->trigopaque allowing more control of how it is assigned and avoiding traps around lifetimes.Includes one precursor fix that has been broken long enough I think we can just merge it via the slow path along with the rest of these.
I had the same comments as Joshua about packing the structs (pahole reports a lot of holes in at91_adc_state in patch 14, but that's nothing new that was introduced in this patch series, and should probably be addressed separately...). Other than that: