From: Jonathan Cameron <jic23@kernel.org>
To: Joshua Crofts <crofts@kernel.org>
Cc: Abdelnasser Hussein <abdelnasserhussein11@gmail.com>,
linux-iio@vger.kernel.org, dlechner@baylibre.com,
nuno.sa@analog.com, andy@kernel.org, nicolas.ferre@microchip.com,
alexandre.belloni@bootlin.com, claudiu.beznea@tuxon.dev,
mripard@kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] iio: adc: at91_adc: move to devm_* to fix NULL pointer deref
Date: Thu, 12 Nov 2026 02:26:19 +0000 [thread overview]
Message-ID: <20261112022619.5693c4f9@jic23-hlaptop> (raw)
In-Reply-To: <20261111121544.00006c23@kernel.org>
On Wed, 11 Nov 2026 12:15:44 +0100
Joshua Crofts <crofts@kernel.org> wrote:
> On Wed, 11 Nov 2026 12:13:45 +0200
> Abdelnasser Hussein <abdelnasserhussein11@gmail.com> wrote:
>
> > If 'atmel,adc-use-external-triggers' is not set in the device tree,
> > at91_adc_trigger_init() leaves the external trigger slots in st->trig
> > as NULL. The error paths and remove function unconditionally called
> > iio_trigger_unregister() and iio_trigger_free() on them, causing a
> > NULL pointer dereference.
> >
> > Instead of just checking for NULL, refactor the driver to use the
> > device-managed (devm_*) API for registration and allocation. This
> > modernizes the code, eliminates the need for manual cleanup functions
> > (at91_adc_trigger_remove, at91_adc_buffer_remove, at91_ts_unregister,
> > and at91_adc_remove), and inherently fixes the NULL pointer dereference
> > since the core handles the cleanup of properly allocated triggers.
> >
> > As part of this simplification, the remaining trigger initialization
> > logic has been inlined into at91_adc_probe().
> >
> > Suggested-by: Jonathan Cameron <jic23@kernel.org>
> > Fixes: 0e589d5fb317 ("ARM: AT91: IIO: Add AT91 ADC driver.")
> > Signed-off-by: Abdelnasser Hussein <abdelnasserhussein11@gmail.com>
> > ---
> > v3:
> > - Addressed review comments from Andy Shevchenko:
> > - Removed the redundant dev_err() after devm_input_allocate_device().
> > - Declared a local 'struct device *dev = &pdev->dev' and used it in
> > at91_adc_probe().
> > - Declared the loop iterator inside the for-loop.
> >
> > v2:
> > - Dropped the simple NULL check approach.
> > - Refactored the driver to use devm_* API as suggested by Jonathan Cameron.
> > - Removed manual cleanup functions and error paths entirely.
> > - Inlined remaining trigger initialization into probe().
> >
> > drivers/iio/adc/at91_adc.c | 185 +++++++++++--------------------------
> > 1 file changed, 52 insertions(+), 133 deletions(-)
>
> I'm not sure if this is an adequate fix. I'd imagine there would be two patches,
> one that just adds the simple null check so it can be backported and this patch
> that will go upstream.
>
> The commit that introduces the bug is 14 years old, so it doesn't make sense to
> me to backport an entire devm_* conversion.
>
> Jonathan, Andy, what do you think?
So, we don't have to backport what we upstream. I could take that null check (which
was v1 of this) and then apply this on top I suppose to make things a little
easier. Alternative is to ask for a backport of the simpler patch with this
referenced as unsuitable for backport.
Jonathan
>
next prev parent reply other threads:[~2026-11-12 2:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 10:13 Abdelnasser Hussein
2026-11-11 11:15 ` Joshua Crofts
2026-11-12 2:26 ` Jonathan Cameron [this message]
2026-11-12 2:25 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261112022619.5693c4f9@jic23-hlaptop \
--to=jic23@kernel.org \
--cc=abdelnasserhussein11@gmail.com \
--cc=alexandre.belloni@bootlin.com \
--cc=andy@kernel.org \
--cc=claudiu.beznea@tuxon.dev \
--cc=crofts@kernel.org \
--cc=dlechner@baylibre.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mripard@kernel.org \
--cc=nicolas.ferre@microchip.com \
--cc=nuno.sa@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®