* [PATCH] iio: adc: ad7768-1: Fix ERR_PTR dereference in ad7768_fill_scale_tbl
@ 2026-02-13 3:12 Ethan Tidmore
2026-02-13 9:22 ` Andy Shevchenko
2026-02-13 16:47 ` Nuno Sá
0 siblings, 2 replies; 3+ messages in thread
From: Ethan Tidmore @ 2026-02-13 3:12 UTC (permalink / raw)
To: Jonathan Cameron, Jonathan Santos
Cc: Andy Shevchenko, linux-iio, linux-kernel, Ethan Tidmore
The function iio_get_current_scan_type() can return ERR_PTR, the return
value scan_type is not checked for this and immediately dereferenced
which can cause a kernel panic.
Add check for IS_ERR() and return early to avoid crash.
Fixes: ff085189cb17 ("iio: adc: ad7768-1: add support for ADAQ776x-1 ADC Family")
Signed-off-by: Ethan Tidmore <ethantidmore06@gmail.com>
---
drivers/iio/adc/ad7768-1.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c
index fcd8aea7152e..f45a09e39367 100644
--- a/drivers/iio/adc/ad7768-1.c
+++ b/drivers/iio/adc/ad7768-1.c
@@ -541,6 +541,11 @@ static void ad7768_fill_scale_tbl(struct iio_dev *dev)
u64 tmp2;
scan_type = iio_get_current_scan_type(dev, &dev->channels[0]);
+ if (IS_ERR(scan_type)) {
+ dev_err(&st->spi->dev, "Failed to get scan type.\n");
+ return;
+ }
+
if (scan_type->sign == 's')
val2 = scan_type->realbits - 1;
else
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: adc: ad7768-1: Fix ERR_PTR dereference in ad7768_fill_scale_tbl
2026-02-13 3:12 [PATCH] iio: adc: ad7768-1: Fix ERR_PTR dereference in ad7768_fill_scale_tbl Ethan Tidmore
@ 2026-02-13 9:22 ` Andy Shevchenko
2026-02-13 16:47 ` Nuno Sá
1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2026-02-13 9:22 UTC (permalink / raw)
To: Ethan Tidmore
Cc: Jonathan Cameron, Jonathan Santos, Andy Shevchenko, linux-iio,
linux-kernel
On Thu, Feb 12, 2026 at 09:12:07PM -0600, Ethan Tidmore wrote:
> The function iio_get_current_scan_type() can return ERR_PTR, the return
ERR_PTR --> error pointer
> value scan_type is not checked for this and immediately dereferenced
> which can cause a kernel panic.
>
> Add check for IS_ERR() and return early to avoid crash.
Also check lore.kernel.org archive, I believe there were reports from CI and
bots on this issue already (hence might need Reported-by & Closed-by tags).
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: adc: ad7768-1: Fix ERR_PTR dereference in ad7768_fill_scale_tbl
2026-02-13 3:12 [PATCH] iio: adc: ad7768-1: Fix ERR_PTR dereference in ad7768_fill_scale_tbl Ethan Tidmore
2026-02-13 9:22 ` Andy Shevchenko
@ 2026-02-13 16:47 ` Nuno Sá
1 sibling, 0 replies; 3+ messages in thread
From: Nuno Sá @ 2026-02-13 16:47 UTC (permalink / raw)
To: Ethan Tidmore, Jonathan Cameron, Jonathan Santos
Cc: Andy Shevchenko, linux-iio, linux-kernel
On Thu, 2026-02-12 at 21:12 -0600, Ethan Tidmore wrote:
> The function iio_get_current_scan_type() can return ERR_PTR, the return
> value scan_type is not checked for this and immediately dereferenced
> which can cause a kernel panic.
>
> Add check for IS_ERR() and return early to avoid crash.
>
> Fixes: ff085189cb17 ("iio: adc: ad7768-1: add support for ADAQ776x-1 ADC Family")
> Signed-off-by: Ethan Tidmore <ethantidmore06@gmail.com>
> ---
> drivers/iio/adc/ad7768-1.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c
> index fcd8aea7152e..f45a09e39367 100644
> --- a/drivers/iio/adc/ad7768-1.c
> +++ b/drivers/iio/adc/ad7768-1.c
> @@ -541,6 +541,11 @@ static void ad7768_fill_scale_tbl(struct iio_dev *dev)
> u64 tmp2;
>
> scan_type = iio_get_current_scan_type(dev, &dev->channels[0]);
> + if (IS_ERR(scan_type)) {
> + dev_err(&st->spi->dev, "Failed to get scan type.\n");
> + return;
> + }
> +
With the above, it could make sense to change the function to propagate the error back...
- Nuno Sá
> if (scan_type->sign == 's')
> val2 = scan_type->realbits - 1;
> else
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-02-13 16:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-13 3:12 [PATCH] iio: adc: ad7768-1: Fix ERR_PTR dereference in ad7768_fill_scale_tbl Ethan Tidmore
2026-02-13 9:22 ` Andy Shevchenko
2026-02-13 16:47 ` Nuno Sá
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox