Linux-IIO Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 3/3] iio: adc: hx711: remove unnecessary returns
@ 2019-09-07 10:18 Andreas Klinger
  2019-09-10  0:34 ` Joe Perches
  0 siblings, 1 reply; 2+ messages in thread
From: Andreas Klinger @ 2019-09-07 10:18 UTC (permalink / raw)
  To: jic23, knaack.h, lars, pmeerw; +Cc: linux-iio, linux-kernel

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(-)

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)
-- 
2.13.3

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 3/3] iio: adc: hx711: remove unnecessary returns
  2019-09-07 10:18 [PATCH 3/3] iio: adc: hx711: remove unnecessary returns Andreas Klinger
@ 2019-09-10  0:34 ` Joe Perches
  0 siblings, 0 replies; 2+ messages in thread
From: Joe Perches @ 2019-09-10  0:34 UTC (permalink / raw)
  To: Andreas Klinger, jic23, knaack.h, lars, pmeerw; +Cc: linux-iio, linux-kernel

On Sat, 2019-09-07 at 12:18 +0200, Andreas Klinger wrote:
> Optimize use of return in hx711_set_gain_for_channel().

I believe this change is not an optimization but
this change does make the code harder to read.

> diff --git 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)


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-07 10:18 [PATCH 3/3] iio: adc: hx711: remove unnecessary returns Andreas Klinger
2019-09-10  0:34 ` Joe Perches

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org linux-iio@archiver.kernel.org
	public-inbox-index linux-iio


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/ public-inbox