From: Salah Triki <salah.triki@gmail.com>
To: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
Salah Triki <salah.triki@gmail.com>
Subject: [PATCH] iio: lmp91000: fix probe order and cleanup paths
Date: Tue, 5 May 2026 20:46:24 +0100 [thread overview]
Message-ID: <20260505194624.98520-1-salah.triki@gmail.com> (raw)
Fix the initialization order in lmp91000_probe where the immutable trigger
is set before data->cb_buffer is initialized, which would cause a NULL
pointer dereference.
Also, correct the cleanup labels in the error path to properly unregister
the trigger before performing the triggered buffer cleanup, following the
standard LIFO (Last-In-First-Out) resource release order.
Fixes: 67e17300dc1d ("iio: potentiostat: add LMP91000 support")
Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
drivers/iio/potentiostat/lmp91000.c | 30 ++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/drivers/iio/potentiostat/lmp91000.c b/drivers/iio/potentiostat/lmp91000.c
index eccc2a34358f..b4676b5b60ae 100644
--- a/drivers/iio/potentiostat/lmp91000.c
+++ b/drivers/iio/potentiostat/lmp91000.c
@@ -330,6 +330,18 @@ static int lmp91000_probe(struct i2c_client *client)
if (ret)
return ret;
+ data->cb_buffer = iio_channel_get_all_cb(dev, &lmp91000_buffer_cb,
+ indio_dev);
+
+ if (IS_ERR(data->cb_buffer)) {
+ if (PTR_ERR(data->cb_buffer) == -ENODEV)
+ ret = -EPROBE_DEFER;
+ else
+ ret = PTR_ERR(data->cb_buffer);
+
+ goto error_unreg_buffer;
+ }
+
ret = iio_trigger_set_immutable(iio_channel_cb_get_iio_dev(data->cb_buffer),
data->trig);
if (ret) {
@@ -349,18 +361,6 @@ static int lmp91000_probe(struct i2c_client *client)
if (ret)
goto error_unreg_trigger;
- data->cb_buffer = iio_channel_get_all_cb(dev, &lmp91000_buffer_cb,
- indio_dev);
-
- if (IS_ERR(data->cb_buffer)) {
- if (PTR_ERR(data->cb_buffer) == -ENODEV)
- ret = -EPROBE_DEFER;
- else
- ret = PTR_ERR(data->cb_buffer);
-
- goto error_unreg_buffer;
- }
-
data->adc_chan = iio_channel_cb_get_channels(data->cb_buffer);
ret = iio_device_register(indio_dev);
@@ -372,12 +372,12 @@ static int lmp91000_probe(struct i2c_client *client)
error_unreg_cb_buffer:
iio_channel_release_all_cb(data->cb_buffer);
-error_unreg_buffer:
- iio_triggered_buffer_cleanup(indio_dev);
-
error_unreg_trigger:
iio_trigger_unregister(data->trig);
+error_unreg_buffer:
+ iio_triggered_buffer_cleanup(indio_dev);
+
return ret;
}
--
2.43.0
next reply other threads:[~2026-05-05 19:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-05 19:46 Salah Triki [this message]
2026-05-06 8:17 ` [PATCH] iio: lmp91000: fix probe order and cleanup paths Andy Shevchenko
2026-05-06 8:18 ` Andy Shevchenko
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=20260505194624.98520-1-salah.triki@gmail.com \
--to=salah.triki@gmail.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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