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: ad4030: check scan_type for error

Check scan_type for error ad4030_get_chan_scale(). Currently, this
should never fail, but it is good practice to always check for errors
in case of future changes.

Calling iio_get_current_scan_type() is moved out of the if statement
also to avoid potential issues with future changes instead of assuming
that the non-differential case does not use extended scan_type.

Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/r/202503040954.n6MhjSsV-lkp@intel.com/
Signed-off-by: David Lechner <dlechner@baylibre.com>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Link: https://patch.msgid.link/20250310-iio-adc-ad4030-check-scan-type-err-v1-1-589e4ebd9711@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

David Lechner and committed by
Jonathan Cameron
de67f28a 9f7140bf

+5 -3
+5 -3
drivers/iio/adc/ad4030.c
··· 390 390 struct ad4030_state *st = iio_priv(indio_dev); 391 391 const struct iio_scan_type *scan_type; 392 392 393 + scan_type = iio_get_current_scan_type(indio_dev, st->chip->channels); 394 + if (IS_ERR(scan_type)) 395 + return PTR_ERR(scan_type); 396 + 393 397 if (chan->differential) { 394 - scan_type = iio_get_current_scan_type(indio_dev, 395 - st->chip->channels); 396 398 *val = (st->vref_uv * 2) / MILLI; 397 399 *val2 = scan_type->realbits; 398 400 return IIO_VAL_FRACTIONAL_LOG2; 399 401 } 400 402 401 403 *val = st->vref_uv / MILLI; 402 - *val2 = chan->scan_type.realbits; 404 + *val2 = scan_type->realbits; 403 405 return IIO_VAL_FRACTIONAL_LOG2; 404 406 } 405 407