From: David Lechner Date: Mon, 10 Mar 2025 20:43:04 +0000 (-0500) Subject: iio: adc: ad4030: check scan_type for error X-Git-Url: http://git.monstr.eu/?a=commitdiff_plain;h=de67f28abe586fc26711389fe80c01b658020c2c;p=linux-2.6-microblaze.git 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 Reported-by: Dan Carpenter Closes: https://lore.kernel.org/r/202503040954.n6MhjSsV-lkp@intel.com/ Signed-off-by: David Lechner Reviewed-by: Nuno Sá Link: https://patch.msgid.link/20250310-iio-adc-ad4030-check-scan-type-err-v1-1-589e4ebd9711@baylibre.com Signed-off-by: Jonathan Cameron --- diff --git a/drivers/iio/adc/ad4030.c b/drivers/iio/adc/ad4030.c index 9a020680885d..af7a817e8273 100644 --- a/drivers/iio/adc/ad4030.c +++ b/drivers/iio/adc/ad4030.c @@ -390,16 +390,18 @@ static int ad4030_get_chan_scale(struct iio_dev *indio_dev, struct ad4030_state *st = iio_priv(indio_dev); const struct iio_scan_type *scan_type; + scan_type = iio_get_current_scan_type(indio_dev, st->chip->channels); + if (IS_ERR(scan_type)) + return PTR_ERR(scan_type); + if (chan->differential) { - scan_type = iio_get_current_scan_type(indio_dev, - st->chip->channels); *val = (st->vref_uv * 2) / MILLI; *val2 = scan_type->realbits; return IIO_VAL_FRACTIONAL_LOG2; } *val = st->vref_uv / MILLI; - *val2 = chan->scan_type.realbits; + *val2 = scan_type->realbits; return IIO_VAL_FRACTIONAL_LOG2; }