iio: adc: imx8qxp-adc: propagate regulator_get_voltage error
If the ADC vref regulator returns an error, for example, if CONFIG_REGULATOR is not set, the error will be used as a reference voltage. Introduce a guard for negative return values instead of unconditionally casting it to u32. Acked-by: Haibo Chen <haibo.chen@nxp.com> Signed-off-by: Martin Larsson <martin.larsson@actia.se> Reviewed-by: Fabio Estevam <festevam@gmail.com> Link: https://lore.kernel.org/r/20220720153136.3502440-1-martin.larsson@actia.se Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
9e8284501c
commit
bd1d558c9c
@ -202,7 +202,7 @@ static int imx8qxp_adc_read_raw(struct iio_dev *indio_dev,
|
||||
struct imx8qxp_adc *adc = iio_priv(indio_dev);
|
||||
struct device *dev = adc->dev;
|
||||
|
||||
u32 ctrl, vref_uv;
|
||||
u32 ctrl;
|
||||
long ret;
|
||||
|
||||
switch (mask) {
|
||||
@ -245,8 +245,10 @@ static int imx8qxp_adc_read_raw(struct iio_dev *indio_dev,
|
||||
return IIO_VAL_INT;
|
||||
|
||||
case IIO_CHAN_INFO_SCALE:
|
||||
vref_uv = regulator_get_voltage(adc->vref);
|
||||
*val = vref_uv / 1000;
|
||||
ret = regulator_get_voltage(adc->vref);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
*val = ret / 1000;
|
||||
*val2 = 12;
|
||||
return IIO_VAL_FRACTIONAL_LOG2;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user