Skip to content

Commit dd6183e

Browse files
Ethan Tidmorejic23
authored andcommitted
iio: adc: ad7768-1: Fix ERR_PTR dereference in ad7768_fill_scale_tbl
The function iio_get_current_scan_type() can return an 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: ff08518 ("iio: adc: ad7768-1: add support for ADAQ776x-1 ADC Family") Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <error27@gmail.com> Closes: https://lore.kernel.org/r/202602051234.5gArzLyZ-lkp@intel.com/ Signed-off-by: Ethan Tidmore <ethantidmore06@gmail.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent c3914ce commit dd6183e

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

drivers/iio/adc/ad7768-1.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ static int ad7768_reg_access(struct iio_dev *indio_dev,
531531
return ret;
532532
}
533533

534-
static void ad7768_fill_scale_tbl(struct iio_dev *dev)
534+
static int ad7768_fill_scale_tbl(struct iio_dev *dev)
535535
{
536536
struct ad7768_state *st = iio_priv(dev);
537537
const struct iio_scan_type *scan_type;
@@ -541,6 +541,11 @@ static void ad7768_fill_scale_tbl(struct iio_dev *dev)
541541
u64 tmp2;
542542

543543
scan_type = iio_get_current_scan_type(dev, &dev->channels[0]);
544+
if (IS_ERR(scan_type)) {
545+
dev_err(&st->spi->dev, "Failed to get scan type.\n");
546+
return PTR_ERR(scan_type);
547+
}
548+
544549
if (scan_type->sign == 's')
545550
val2 = scan_type->realbits - 1;
546551
else
@@ -565,6 +570,8 @@ static void ad7768_fill_scale_tbl(struct iio_dev *dev)
565570
st->scale_tbl[i][0] = tmp0; /* Integer part */
566571
st->scale_tbl[i][1] = abs(tmp1); /* Fractional part */
567572
}
573+
574+
return 0;
568575
}
569576

570577
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,
669676
}
670677

671678
/* Update scale table: scale values vary according to the precision */
672-
ad7768_fill_scale_tbl(dev);
679+
ret = ad7768_fill_scale_tbl(dev);
680+
if (ret)
681+
return ret;
673682

674683
ad7768_fill_samp_freq_tbl(st);
675684

0 commit comments

Comments
 (0)