Skip to contentSkip to conversation

iio: adc: ti-ads131e08: Fix trigger reference leak in ads131e08_probe()

PATCH In review Wentao Liang 2 participants 3 messages Sep 16 – Nov 6

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

PATCH 1/1 iio: adc: ti-ads131e08: Fix trigger reference leak in ads131e08_probe()

The reference taken with iio_trigger_get() is only dropped by iio_dev_release() when INDIO_BUFFER_TRIGGERED is set. If devm_iio_triggered_buffer_setup() fails before setting that mode, the reference acquired for indio_dev->trig leaks. Move the iio_trigger_get() after the buffer setup succeeds.

Fixes d935eddd2799 ("iio: adc: Add driver for Texas Instruments ADS131E0x ADC family")
---
 drivers/iio/adc/ti-ads131e08.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/ti-ads131e08.c +2 -2
index a585621b0bc3..d976214504c3 100644
@@ -851,8 +851,6 @@ static int ads131e08_probe(struct spi_device *spi)
 		return ret;
 	}
 
-	indio_dev->trig = iio_trigger_get(st->trig);
-
 	ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev,
 		NULL, &ads131e08_trigger_handler, NULL);
 	if (ret) {
@@ -860,6 +858,8 @@ static int ads131e08_probe(struct spi_device *spi)
 		return ret;
 	}
 
+	indio_dev->trig = iio_trigger_get(st->trig);
+
 	st->vref_reg = devm_regulator_get_optional(&spi->dev, "vref");
 	if (!IS_ERR(st->vref_reg)) {
 		ret = regulator_enable(st->vref_reg);
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 9 lines · On Wed, 16 Sep 2026 16:21:14 +0000 Wentao Liang <[email protected]> wrote:

The reference taken with iio_trigger_get() is only dropped by iio_dev_release() when INDIO_BUFFER_TRIGGERED is set. If devm_iio_triggered_buffer_setup() fails before setting that mode, the reference acquired for indio_dev->trig leaks. Move the iio_trigger_get() after the buffer setup succeeds.

Fixes d935eddd2799 ("iio: adc: Add driver for Texas Instruments ADS131E0x ADC family")

Not this solution. See other threads on this.

Quoted 26 lines
---
 drivers/iio/adc/ti-ads131e08.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/ti-ads131e08.c +2 -2
index a585621b0bc3..d976214504c3 100644
@@ -851,8 +851,6 @@ static int ads131e08_probe(struct spi_device *spi)
 		return ret;
 	}
 
-	indio_dev->trig = iio_trigger_get(st->trig);
-
 	ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev,
 		NULL, &ads131e08_trigger_handler, NULL);
 	if (ret) {
@@ -860,6 +858,8 @@ static int ads131e08_probe(struct spi_device *spi)
 		return ret;
 	}
 
+	indio_dev->trig = iio_trigger_get(st->trig);
+
 	st->vref_reg = devm_regulator_get_optional(&spi->dev, "vref");
 	if (!IS_ERR(st->vref_reg)) {
 		ret = regulator_enable(st->vref_reg);
#2 lore raw

Hi Jonathan,

Sorry for the very late reply.

I understand your feedback: this fix should not depend on a subtle ordering constraint in the driver. Trigger lifetime handling needs a broader solution in the IIO core, as you explained in the bma220 thread.

Please disregard this patch; I will not resend this approach as v2. Thank you for the review.

For transparency, we use static analysis tools to identify candidates, then DeepSeek and GPT-6.1 Sol to assist with auditing and preparing fixes. I am responsible for verifying the findings and changes before submission.

Best regards,
Wentao