Message ID | 20220719150317.67156-1-martin.larsson@actia.se (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | iio: adc: imx8qxp-adc: propagate regulator_get_voltage error | expand |
> -----Original Message----- > From: Martin Larsson <martin.larsson@actia.se> > Sent: 2022年7月19日 23:03 > To: Cai Huoqing <cai.huoqing@linux.dev>; Jonathan Cameron > <jic23@kernel.org>; linux-iio@vger.kernel.org > Cc: Martin Larsson <martin.larsson@actia.se>; Bough Chen > <haibo.chen@nxp.com>; Lars-Peter Clausen <lars@metafoo.de>; Shawn Guo > <shawnguo@kernel.org>; Sascha Hauer <s.hauer@pengutronix.de>; > Pengutronix Kernel Team <kernel@pengutronix.de>; Fabio Estevam > <festevam@gmail.com>; dl-linux-imx <linux-imx@nxp.com>; > linux-arm-kernel@lists.infradead.org > Subject: [PATCH] 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> Regards Haibo Chen > --- > drivers/iio/adc/imx8qxp-adc.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/drivers/iio/adc/imx8qxp-adc.c b/drivers/iio/adc/imx8qxp-adc.c index > 901dd8e1b32f..8a786d73ae8e 100644 > --- a/drivers/iio/adc/imx8qxp-adc.c > +++ b/drivers/iio/adc/imx8qxp-adc.c > @@ -201,7 +201,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) { > @@ -244,8 +244,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; > > -- > 2.36.1
Hi Martin, On Tue, Jul 19, 2022 at 12:03 PM Martin Larsson <martin.larsson@actia.se> wrote: > > 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. You missed your Signed-off-by line.
diff --git a/drivers/iio/adc/imx8qxp-adc.c b/drivers/iio/adc/imx8qxp-adc.c index 901dd8e1b32f..8a786d73ae8e 100644 --- a/drivers/iio/adc/imx8qxp-adc.c +++ b/drivers/iio/adc/imx8qxp-adc.c @@ -201,7 +201,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) { @@ -244,8 +244,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;