iio: adc: ad7768-1: Fix ERR_PTR dereference in ad7768_fill_scale_tbl
Subsystems (3)
PATCH 1/1 iio: adc: ad7768-1: Fix ERR_PTR dereference in ad7768_fill_scale_tbl
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.
--- drivers/iio/adc/ad7768-1.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/iio/adc/ad7768-1.c +5 -0
@@ -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
Signature · 1 line
2.53.0
Quoted 1 line · Ethan Tidmore
The function
iio_get_current_scan_type()can returnERR_PTR, the return
ERR_PTR --> error pointer
Quoted 4 lines
value
scan_typeis 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).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 20 lines · Ethan Tidmore
The function
iio_get_current_scan_type()can returnERR_PTR, the return valuescan_typeis 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 <[email protected]>---
drivers/iio/adc/ad7768-1.c | 5 +++++1 file changed, 5 insertions(+)drivers/iio/adc/ad7768-1.c +0
-0@@ -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]);
drivers/iio/adc/ad7768-1.c static void ad7768_fill_scale_tbl(struct iio_dev *dev) · line 548
Quoted 5 lines
drivers/iio/adc/ad7768-1.c +5
-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á
Quoted 3 lines
if (
scan_type->sign== 's')
val2 =scan_type->realbits- 1;
else