[PATCH v6 1/8] iio: adc: at91_adc: skip unpopulated triggers on teardown
From: Abdelnasser Hussein
Date: Thu Dec 03 2026 - 12:33:40 EST
at91_adc_trigger_init() and at91_adc_trigger_remove() iterate over all
st->trig entries. External trigger slots remain NULL when
"atmel,adc-use-external-triggers" is absent, so skip them in both
teardown loops.
Keep this as a minimal stable-backportable fix; the devm conversion later
in the series removes this teardown 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 | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index 0ac74ad92fca..a4b1d08e8081 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -660,6 +660,13 @@ static int at91_adc_trigger_init(struct iio_dev *idev)
error_trigger:
for (i--; i >= 0; i--) {
+ /*
+ * iio_trigger_unregister() is intentionally not NULL-aware so
+ * unregistering an unallocated trigger fails loudly.
+ */
+ if (!st->trig[i])
+ continue;
+
iio_trigger_unregister(st->trig[i]);
iio_trigger_free(st->trig[i]);
}
@@ -673,6 +680,13 @@ static void at91_adc_trigger_remove(struct iio_dev *idev)
int i;
for (i = 0; i < st->caps->trigger_number; i++) {
+ /*
+ * iio_trigger_unregister() is intentionally not NULL-aware so
+ * unregistering an unallocated trigger fails loudly.
+ */
+ if (!st->trig[i])
+ continue;
+
iio_trigger_unregister(st->trig[i]);
iio_trigger_free(st->trig[i]);
}
--
2.56.0