[PATCH v5 1/8] iio: adc: at91_adc: skip unpopulated triggers on teardown

From: Abdelnasser Hussein

Date: Mon Nov 23 2026 - 02:01:36 EST


The driver keeps an array of triggers and leaves the slots for external
triggers unpopulated (NULL) when the "atmel,adc-use-external-triggers"
property is not set. Both the error rollback path in
at91_adc_trigger_init() and at91_adc_trigger_remove() walk the whole
array and call iio_trigger_unregister() and iio_trigger_free() on every
entry, including the empty ones, which dereferences NULL.

Skip unpopulated trigger slots in both loops.

Make a minimal fix to simplify backporting. Moving over to device managed
cleanup will shortly remove this code.

Fixes: 0e589d5fb317 ("ARM: AT91: IIO: Add AT91 ADC driver.")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Abdelnasser Hussein <abdelnasserhussein11@xxxxxxxxx>
---
drivers/iio/adc/at91_adc.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index 0ac74ad92fca..9ecf8ca362f5 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -660,6 +660,9 @@ static int at91_adc_trigger_init(struct iio_dev *idev)

error_trigger:
for (i--; i >= 0; i--) {
+ if (!st->trig[i])
+ continue;
+
iio_trigger_unregister(st->trig[i]);
iio_trigger_free(st->trig[i]);
}
@@ -673,6 +676,9 @@ static void at91_adc_trigger_remove(struct iio_dev *idev)
int i;

for (i = 0; i < st->caps->trigger_number; i++) {
+ if (!st->trig[i])
+ continue;
+
iio_trigger_unregister(st->trig[i]);
iio_trigger_free(st->trig[i]);
}
--
2.56.0