diff mbox series

[v2,3/3] iio: adc: hx711: remove unnecessary returns

Message ID 20190909123806.ewrxc7y5gmh5plmk@arbad (mailing list archive)
State New, archived
Headers show
Series iio: adc: hx711: fix and optimize sampling of data | expand

Commit Message

Andreas Klinger Sept. 9, 2019, 12:38 p.m. UTC
Optimize use of return in hx711_set_gain_for_channel().

Signed-off-by: Andreas Klinger <ak@it-klinger.de>
---
 drivers/iio/adc/hx711.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

Comments

Jonathan Cameron Sept. 15, 2019, 12:58 p.m. UTC | #1
On Mon, 9 Sep 2019 14:38:08 +0200
Andreas Klinger <ak@it-klinger.de> wrote:

> Optimize use of return in hx711_set_gain_for_channel().
> 
> Signed-off-by: Andreas Klinger <ak@it-klinger.de>

I agree with Joe on this.  Minor reduction in code, but hurts
readability so a no on this one.

thanks,

Jonathan

> ---
>  drivers/iio/adc/hx711.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c
> index c8686558429b..20c249f502c0 100644
> --- a/drivers/iio/adc/hx711.c
> +++ b/drivers/iio/adc/hx711.c
> @@ -213,7 +213,7 @@ static int hx711_reset(struct hx711_data *hx711_data)
>  
>  static int hx711_set_gain_for_channel(struct hx711_data *hx711_data, int chan)
>  {
> -	int ret;
> +	int ret = 0;
>  
>  	if (chan == 0) {
>  		if (hx711_data->gain_set == 32) {
> @@ -224,8 +224,6 @@ static int hx711_set_gain_for_channel(struct hx711_data *hx711_data, int chan)
>  				return ret;
>  
>  			ret = hx711_wait_for_ready(hx711_data);
> -			if (ret)
> -				return ret;
>  		}
>  	} else {
>  		if (hx711_data->gain_set != 32) {
> @@ -236,12 +234,10 @@ static int hx711_set_gain_for_channel(struct hx711_data *hx711_data, int chan)
>  				return ret;
>  
>  			ret = hx711_wait_for_ready(hx711_data);
> -			if (ret)
> -				return ret;
>  		}
>  	}
>  
> -	return 0;
> +	return ret;
>  }
>  
>  static int hx711_reset_read(struct hx711_data *hx711_data, int chan)
diff mbox series

Patch

diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c
index c8686558429b..20c249f502c0 100644
--- a/drivers/iio/adc/hx711.c
+++ b/drivers/iio/adc/hx711.c
@@ -213,7 +213,7 @@  static int hx711_reset(struct hx711_data *hx711_data)
 
 static int hx711_set_gain_for_channel(struct hx711_data *hx711_data, int chan)
 {
-	int ret;
+	int ret = 0;
 
 	if (chan == 0) {
 		if (hx711_data->gain_set == 32) {
@@ -224,8 +224,6 @@  static int hx711_set_gain_for_channel(struct hx711_data *hx711_data, int chan)
 				return ret;
 
 			ret = hx711_wait_for_ready(hx711_data);
-			if (ret)
-				return ret;
 		}
 	} else {
 		if (hx711_data->gain_set != 32) {
@@ -236,12 +234,10 @@  static int hx711_set_gain_for_channel(struct hx711_data *hx711_data, int chan)
 				return ret;
 
 			ret = hx711_wait_for_ready(hx711_data);
-			if (ret)
-				return ret;
 		}
 	}
 
-	return 0;
+	return ret;
 }
 
 static int hx711_reset_read(struct hx711_data *hx711_data, int chan)