]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: adc: ad4062: Add missing IS_ERR() check
authorEthan Tidmore <ethantidmore06@gmail.com>
Sat, 14 Feb 2026 00:53:32 +0000 (18:53 -0600)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 23 Feb 2026 08:24:22 +0000 (08:24 +0000)
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>
drivers/iio/adc/ad4062.c

index dd4ad32aa6f53c2662a1c085a94ec54a85b8cfa2..c864de3b46bae912f5ec570c90c6898147616b83 100644 (file)
@@ -1199,11 +1199,14 @@ static int ad4062_write_event_value(struct iio_dev *indio_dev,
  * The AD4062 in burst averaging mode increases realbits from 16-bits to
  * 20-bits, increasing the storagebits from 16-bits to 32-bits.
  */
-static inline size_t ad4062_sizeof_storagebits(struct ad4062_state *st)
+static inline int ad4062_sizeof_storagebits(struct ad4062_state *st)
 {
        const struct iio_scan_type *scan_type =
                iio_get_current_scan_type(st->indio_dev, st->chip->channels);
 
+       if (IS_ERR(scan_type))
+               return PTR_ERR(scan_type);
+
        return BITS_TO_BYTES(scan_type->storagebits);
 }
 
@@ -1233,7 +1236,12 @@ static int pm_ad4062_triggered_buffer_postenable(struct ad4062_state *st)
        if (ret)
                return ret;
 
-       st->conv_sizeof = ad4062_sizeof_storagebits(st);
+       ret = ad4062_sizeof_storagebits(st);
+       if (ret < 0)
+               return ret;
+
+       st->conv_sizeof = ret;
+
        st->conv_addr = ad4062_get_conv_addr(st, st->conv_sizeof);
        /* CONV_READ requires read to trigger first sample. */
        struct i3c_xfer xfer_sample[2] = {