[PATCH v5 0/8] iio: adc: at91_adc: fix NULL trigger dereference and convert to devm

From: Abdelnasser Hussein

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


This series fixes a NULL pointer dereference during trigger teardown in
at91_adc and modernizes the driver to use firmware-agnostic property
APIs and device-managed (devm) resources.

When the "atmel,adc-use-external-triggers" property is omitted from the
Device Tree, at91_adc_trigger_init() leaves external trigger slots in
st->trig as NULL. Patch 1 provides a minimal fix in at91_adc for easy
backporting to stable kernels, while the subsequent patches modernize
the driver and convert it to devm_* APIs (removing the manual teardown
code and the st->trig array altogether).

Changes in v5:
- Patch 1: Keep the minimal NULL check in at91_adc instead of modifying
iio_trigger_unregister(), and explicitly note in the commit message
that it is a minimal fix for backporting before devm removal (as
requested by Jonathan Cameron).
- Patch 2: Drop the redundant dev_err_probe() message after
devm_request_irq() in a separate patch.
- Patch 3: Switch from of_device_get_match_data() to
device_get_match_data() and check for NULL in a separate patch.
- Patch 4: Convert of_property_*() calls in at91_adc_probe() and
at91_adc_probe_dt_ts() (renamed to at91_adc_probe_ts()) to
device_property_*() APIs, removing the local device_node pointer and
dropping "in the DT" from missing-property logs. Since no OF APIs
remain, replace <linux/of.h> with <linux/mod_devicetable.h>.
- Patch 5: Introduce local struct device *dev in at91_adc_probe() and
switch devm_iio_device_alloc() to sizeof(*st).
- Patch 6: Pass struct device *dev instead of struct platform_device *pdev
to at91_ts_register() in a separate patch.
- Patch 7: Replace raw 1000 with HZ_PER_KHZ from <linux/units.h>.
- Patch 8: Convert the remaining buffer, trigger, touchscreen input, and
IIO device registrations to devm_* APIs, use unsigned int for the
trigger loop index, drop the now-unused st->trig array, drop the
redundant input->dev.parent assignment, and remove at91_adc_remove().

Changes in v4:
- Split the series into 3 atomic patches: (1) standalone NULL trigger
teardown fix for stable backporting, (2) local struct device pointer
cleanup, and (3) full devm_* conversion.

Changes in v3:
- Address review feedback from Andy Shevchenko on v2 (drop redundant
-ENOMEM log, use local struct device pointer, scope loop index to the
for-loop, and convert error paths to dev_err_probe()).

Changes in v2:
- Drop the simple NULL check approach from v1 and refactor the driver to
use device-managed (devm_*) APIs as suggested by Jonathan Cameron,
removing manual cleanup functions and at91_adc_remove(), and inlining
trigger initialization into at91_adc_probe().

Abdelnasser Hussein (8):
iio: adc: at91_adc: skip unpopulated triggers on teardown
iio: adc: at91_adc: drop duplicate IRQ allocation error message
iio: adc: at91_adc: switch to device_get_match_data()
iio: adc: at91_adc: convert to device_property_*() APIs
iio: adc: at91_adc: use local struct device pointer in probe
iio: adc: at91_adc: pass struct device to at91_ts_register()
iio: adc: at91_adc: use HZ_PER_KHZ instead of raw 1000
iio: adc: at91_adc: convert to device-managed resources

drivers/iio/adc/at91_adc.c | 266 +++++++++++--------------------------
1 file changed, 77 insertions(+), 189 deletions(-)

--
2.56.0