Skip to contentSkip to conversation

iio: adc: hx711: remove unnecessary returns

PATCH Superseded Andreas Klinger 2 participants 2 messages Sep 7, 2019 – Sep 10, 2019

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Andreas Klinger

author maintainer
#0 lore raw

PATCH 3/3 iio: adc: hx711: remove unnecessary returns

Optimize use of return in hx711_set_gain_for_channel().

---
 drivers/iio/adc/hx711.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/iio/adc/hx711.c +2 -6
index c8686558429b..20c249f502c0 100644
@@ -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)
Signature · 1 line
2.13.3
#1 lore raw
Quoted 1 line · Andreas Klinger

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.

drivers/iio/adc/hx711.c

Quoted 1 line
drivers/iio/adc/hx711.c +0 -0

[]

Quoted 32 lines
drivers/iio/adc/hx711.c +2 -6
@@ -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)