Re: [PATCH v4 1/3] iio: adc: at91_adc: fix NULL pointer dereference on trigger remove
From: Andy Shevchenko
Date: Tue Nov 17 2026 - 11:44:43 EST
On Tue, Nov 17, 2026 at 04:05:08PM +0200, Abdelnasser Hussein wrote:
> When the "atmel,adc-use-external-triggers" property is not set in the
> Device Tree, at91_adc_trigger_init() skips the external trigger slots
> and leaves the corresponding entries in st->trig as NULL.
>
> In the error rollback path of at91_adc_trigger_init() and in
> at91_adc_trigger_remove(), iio_trigger_unregister() and
> iio_trigger_free() are called on every slot without checking for NULL,
> causing a NULL pointer dereference whenever an external trigger slot
> was skipped, either because of a partial allocation failure or because
> the external triggers are simply not used.
>
> Skip NULL trigger slots in both teardown loops so that only triggers
> that were actually allocated are unregistered and freed.
...
> 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]);
> }
Yes, but no. Please, rather fix the above mentioned IIO trigger APIs to be
NULL-aware.
--
With Best Regards,
Andy Shevchenko