diff mbox series

[v2,02/19] iio: adc: at91-sama5d2_adc: check return status for pressure and touch

Message ID 20220628151631.3116454-3-claudiu.beznea@microchip.com (mailing list archive)
State Accepted
Headers show
Series iio: adc: at91-sama5d2_adc: add support for temperature sensor | expand

Commit Message

Claudiu Beznea June 28, 2022, 3:16 p.m. UTC
Check return status of at91_adc_read_position() and
at91_adc_read_pressure() in at91_adc_read_info_raw().

Fixes: 6794e23fa3fe ("iio: adc: at91-sama5d2_adc: add support for oversampling resolution")
Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---
 drivers/iio/adc/at91-sama5d2_adc.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Jonathan Cameron July 16, 2022, 4:25 p.m. UTC | #1
On Tue, 28 Jun 2022 18:16:14 +0300
Claudiu Beznea <claudiu.beznea@microchip.com> wrote:

> Check return status of at91_adc_read_position() and
> at91_adc_read_pressure() in at91_adc_read_info_raw().
> 
> Fixes: 6794e23fa3fe ("iio: adc: at91-sama5d2_adc: add support for oversampling resolution")
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> ---
>  drivers/iio/adc/at91-sama5d2_adc.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c
> index 32b6f157b803..c3301c749164 100644
> --- a/drivers/iio/adc/at91-sama5d2_adc.c
> +++ b/drivers/iio/adc/at91-sama5d2_adc.c
> @@ -1544,8 +1544,10 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev,
>  		*val = tmp_val;
>  		mutex_unlock(&st->lock);
>  		iio_device_release_direct_mode(indio_dev);
Prefer to keep error path out of line.

		if (ret < 0)
			return ret;

		return at91_adc_adjust_val_osr();

Also ends up as a slightly less invasive change.

> +		if (ret > 0)
> +			ret = at91_adc_adjust_val_osr(st, val);
>  
> -		return at91_adc_adjust_val_osr(st, val);
> +		return ret;
>  	}
>  	if (chan->type == IIO_PRESSURE) {
>  		ret = iio_device_claim_direct_mode(indio_dev);
> @@ -1558,8 +1560,10 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev,
>  		*val = tmp_val;
>  		mutex_unlock(&st->lock);
>  		iio_device_release_direct_mode(indio_dev);
> +		if (ret > 0)
> +			ret = at91_adc_adjust_val_osr(st, val);
>  
> -		return at91_adc_adjust_val_osr(st, val);
As above.

> +		return ret;
>  	}
>  
>  	/* in this case we have a voltage channel */
Jonathan Cameron July 16, 2022, 4:26 p.m. UTC | #2
On Sat, 16 Jul 2022 17:25:31 +0100
Jonathan Cameron <jic23@kernel.org> wrote:

> On Tue, 28 Jun 2022 18:16:14 +0300
> Claudiu Beznea <claudiu.beznea@microchip.com> wrote:
> 
> > Check return status of at91_adc_read_position() and
> > at91_adc_read_pressure() in at91_adc_read_info_raw().
> > 
> > Fixes: 6794e23fa3fe ("iio: adc: at91-sama5d2_adc: add support for oversampling resolution")
> > Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> > ---
> >  drivers/iio/adc/at91-sama5d2_adc.c | 8 ++++++--
> >  1 file changed, 6 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c
> > index 32b6f157b803..c3301c749164 100644
> > --- a/drivers/iio/adc/at91-sama5d2_adc.c
> > +++ b/drivers/iio/adc/at91-sama5d2_adc.c
> > @@ -1544,8 +1544,10 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev,
> >  		*val = tmp_val;
> >  		mutex_unlock(&st->lock);
> >  		iio_device_release_direct_mode(indio_dev);  
> Prefer to keep error path out of line.
> 
> 		if (ret < 0)
> 			return ret;
> 
> 		return at91_adc_adjust_val_osr();
> 
> Also ends up as a slightly less invasive change.
Ah. I should have read on through the series. Ignore this.

> 
> > +		if (ret > 0)
> > +			ret = at91_adc_adjust_val_osr(st, val);
> >  
> > -		return at91_adc_adjust_val_osr(st, val);
> > +		return ret;
> >  	}
> >  	if (chan->type == IIO_PRESSURE) {
> >  		ret = iio_device_claim_direct_mode(indio_dev);
> > @@ -1558,8 +1560,10 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev,
> >  		*val = tmp_val;
> >  		mutex_unlock(&st->lock);
> >  		iio_device_release_direct_mode(indio_dev);
> > +		if (ret > 0)
> > +			ret = at91_adc_adjust_val_osr(st, val);
> >  
> > -		return at91_adc_adjust_val_osr(st, val);  
> As above.
> 
> > +		return ret;
> >  	}
> >  
> >  	/* in this case we have a voltage channel */  
>
diff mbox series

Patch

diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c
index 32b6f157b803..c3301c749164 100644
--- a/drivers/iio/adc/at91-sama5d2_adc.c
+++ b/drivers/iio/adc/at91-sama5d2_adc.c
@@ -1544,8 +1544,10 @@  static int at91_adc_read_info_raw(struct iio_dev *indio_dev,
 		*val = tmp_val;
 		mutex_unlock(&st->lock);
 		iio_device_release_direct_mode(indio_dev);
+		if (ret > 0)
+			ret = at91_adc_adjust_val_osr(st, val);
 
-		return at91_adc_adjust_val_osr(st, val);
+		return ret;
 	}
 	if (chan->type == IIO_PRESSURE) {
 		ret = iio_device_claim_direct_mode(indio_dev);
@@ -1558,8 +1560,10 @@  static int at91_adc_read_info_raw(struct iio_dev *indio_dev,
 		*val = tmp_val;
 		mutex_unlock(&st->lock);
 		iio_device_release_direct_mode(indio_dev);
+		if (ret > 0)
+			ret = at91_adc_adjust_val_osr(st, val);
 
-		return at91_adc_adjust_val_osr(st, val);
+		return ret;
 	}
 
 	/* in this case we have a voltage channel */