Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: adc: ad4062: Add missing IS_ERR() check

In the function ad4062_sizeof_storagebits() iio_get_current_scan_type()
is called which can return an error pointer and is not checked for it.
Also the function ad4062_sizeof_storagebits() returns type size_t but,
is only used once and the variable assigned from it is type u8.

Add check for error pointer in ad4062_sizeof_storagebits() and change
return type to int so the error code can be properly propagated and then
checked.

Fixes: 23cc92280302d ("iio: adc: ad4062: Add IIO Trigger support")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <error27@gmail.com>
Closes: https://lore.kernel.org/r/202512280539.AholFF7m-lkp@intel.com/
Signed-off-by: Ethan Tidmore <ethantidmore06@gmail.com>
Reviewed-by: Jorge Marques <jorge.marques@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Ethan Tidmore and committed by
Jonathan Cameron
5cf5654b bc2cb236

+10 -2
+10 -2
drivers/iio/adc/ad4062.c
··· 1199 1199 * The AD4062 in burst averaging mode increases realbits from 16-bits to 1200 1200 * 20-bits, increasing the storagebits from 16-bits to 32-bits. 1201 1201 */ 1202 - static inline size_t ad4062_sizeof_storagebits(struct ad4062_state *st) 1202 + static inline int ad4062_sizeof_storagebits(struct ad4062_state *st) 1203 1203 { 1204 1204 const struct iio_scan_type *scan_type = 1205 1205 iio_get_current_scan_type(st->indio_dev, st->chip->channels); 1206 + 1207 + if (IS_ERR(scan_type)) 1208 + return PTR_ERR(scan_type); 1206 1209 1207 1210 return BITS_TO_BYTES(scan_type->storagebits); 1208 1211 } ··· 1236 1233 if (ret) 1237 1234 return ret; 1238 1235 1239 - st->conv_sizeof = ad4062_sizeof_storagebits(st); 1236 + ret = ad4062_sizeof_storagebits(st); 1237 + if (ret < 0) 1238 + return ret; 1239 + 1240 + st->conv_sizeof = ret; 1241 + 1240 1242 st->conv_addr = ad4062_get_conv_addr(st, st->conv_sizeof); 1241 1243 /* CONV_READ requires read to trigger first sample. */ 1242 1244 struct i3c_xfer xfer_sample[2] = {