iio: adc: ad7768-1: Fix ERR_PTR dereference in ad7768_fill_scale_tbl
Subsystems (3)
PATCH v2 1/1 iio: adc: ad7768-1: Fix ERR_PTR dereference in ad7768_fill_scale_tbl
The function iio_get_current_scan_type() can return aan error pointer, 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 propagate the error back.
Fixes ff085189cb17 ("iio: adc: ad7768-1: add support for ADAQ776x-1 ADC Family")
Reported-by kernel test robot <[email protected]>
Reported-by Dan Carpenter <[email protected]>
Signed-off-by Ethan Tidmore <[email protected]>
--- drivers/iio/adc/ad7768-1.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/iio/adc/ad7768-1.c +11 -2
@@ -531,7 +531,7 @@ static int ad7768_reg_access(struct iio_dev *indio_dev,return ret; } -static void ad7768_fill_scale_tbl (struct iio_dev *dev) +static int ad7768_fill_scale_tbl (struct iio_dev *dev) {struct ad7768_state *st =iio_priv (dev);const struct iio_scan_type *scan_type;
@@ -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 PTR_ERR (scan_type); + } +if (scan_type->sign =='s' ) val2 = scan_type->realbits -1 ;else
@@ -565,6 +570,8 @@ static void ad7768_fill_scale_tbl(struct iio_dev *dev) st->scale_tbl[i][0 ] = tmp0;/* Integer part */ st->scale_tbl[i][1 ] =abs (tmp1);/* Fractional part */ } + +return 0 ; } static int ad7768_set_sinc3_dec_rate(struct ad7768_state *st,
@@ -669,7 +676,9 @@ static int ad7768_configure_dig_fil(struct iio_dev *dev, }/* Update scale table: scale values vary according to the precision */ -ad7768_fill_scale_tbl (dev); + ret =ad7768_fill_scale_tbl (dev); +if (ret) +return ret;ad7768_fill_samp_freq_tbl (st);
Signature · 1 line
2.53.0
Quoted 4 lines · Ethan Tidmore
The function
iio_get_current_scan_type()can return aan error pointer, the return valuescan_typeis not checked for this and immediately dereferenced which can cause a kernel panic.
Quoted 8 lines
Add check for
IS_ERR()and propagate the error back.Fixes ff085189cb17 ("iio: adc: ad7768-1: add support for ADAQ776x-1 ADC Family")Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Signed-off-by Ethan Tidmore <[email protected]>---
Sorry, ignore this v2. Just noticed typo "aan" and forgot changelog. Will send v3 tomorrow with these two things fixed.
Thanks,
ET