Skip to contentSkip to conversation

iio: remove redundant else after return

PATCH In review Antoniu Miclaus 3 participants 10 messages Feb 20 – Feb 22

Subsystems (3)
lore
Share & tools
lore

Antoniu Miclaus

author maintainer
#0 lore raw

cover iio: remove redundant else after return

Remove redundant else branches after return statements across several IIO drivers (ad7298, ad7606, ad5592r, ad5758, admv8818) to simplify control flow.

Antoniu Miclaus (5):
iio: adc: ad7298: remove redundant else after return
iio: adc: ad7606: remove redundant else after return
iio: dac: ad5592r-base: remove redundant else after return
iio: dac: ad5758: remove redundant else after return
iio: filter: admv8818: remove redundant else after return

 drivers/iio/adc/ad7298.c       | 4 ++--
 drivers/iio/adc/ad7606.c       | 4 ++--
 drivers/iio/dac/ad5592r-base.c | 4 ++--
 drivers/iio/dac/ad5758.c       | 6 +++---
 drivers/iio/filter/admv8818.c  | 4 ++--
 5 files changed, 11 insertions(+), 11 deletions(-)
Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH 1/5 iio: adc: ad7298: remove redundant else after return

The else returning the internal reference voltage in ad7298_get_ref_voltage() is unnecessary since the if block for the external regulator already returns.

---
 drivers/iio/adc/ad7298.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/ad7298.c +2 -2
index 7c0538ea15c8..e775d84da333 100644
@@ -216,9 +216,9 @@ static int ad7298_get_ref_voltage(struct ad7298_state *st)
 			return vref;
 
 		return vref / 1000;
-	} else {
-		return AD7298_INTREF_mV;
 	}
+
+	return AD7298_INTREF_mV;
 }
 
 static int ad7298_read_raw(struct iio_dev *indio_dev,
Signature · 1 line
2.43.0
author maintainer
#2 lore raw

PATCH 2/5 iio: adc: ad7606: remove redundant else after return

In reply to Antoniu Miclaus

The else performing the register write in ad7606_reg_access() is unnecessary since the if block for the register read already returns.

---
 drivers/iio/adc/ad7606.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/ad7606.c +2 -2
index d9271894f091..8ef3f7b8a6a4 100644
@@ -540,9 +540,9 @@ static int ad7606_reg_access(struct iio_dev *indio_dev,
 			return ret;
 		*readval = ret;
 		return 0;
-	} else {
-		return st->bops->reg_write(st, reg, writeval);
 	}
+
+	return st->bops->reg_write(st, reg, writeval);
 }
 
 static int ad7606_pwm_set_high(struct ad7606_state *st)
Signature · 1 line
2.43.0
author maintainer
#3 lore raw

PATCH 3/5 iio: dac: ad5592r-base: remove redundant else after return

In reply to Antoniu Miclaus

The else returning the internal 2500mV fallback in ad5592r_get_vref() is unnecessary since the if block for the external regulator already returns.

---
 drivers/iio/dac/ad5592r-base.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/dac/ad5592r-base.c +2 -2
index 4720733d66b2..a8c10ca238d0 100644
@@ -179,9 +179,9 @@ static int ad5592r_get_vref(struct ad5592r_state *st)
 			return ret;
 
 		return ret / 1000;
-	} else {
-		return 2500;
 	}
+
+	return 2500;
 }
 
 static int ad5592r_set_channel_modes(struct ad5592r_state *st)
Signature · 1 line
2.43.0
author maintainer
#4 lore raw

PATCH 4/5 iio: dac: ad5758: remove redundant else after return

In reply to Antoniu Miclaus

The else falling back to software reset in ad5758_reset() is unnecessary since the if block for the GPIO hardware reset already returns.

---
 drivers/iio/dac/ad5758.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/dac/ad5758.c +3 -3
index 4ed4fda76ea9..c4424a80a35a 100644
@@ -483,10 +483,10 @@ static int ad5758_reset(struct ad5758_state *st)
 		usleep_range(100, 1000);
 
 		return 0;
-	} else {
-		/* Perform a software reset */
-		return ad5758_soft_reset(st);
 	}
+
+	/* Perform a software reset */
+	return ad5758_soft_reset(st);
 }
 
 static int ad5758_reg_access(struct iio_dev *indio_dev,
Signature · 1 line
2.43.0
author maintainer
#5 lore raw

PATCH 5/5 iio: filter: admv8818: remove redundant else after return

In reply to Antoniu Miclaus

The else in admv8818_init() is unnecessary since the if block already returns after calling admv8818_rfin_band_select() when clkin is present.

---
 drivers/iio/filter/admv8818.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/filter/admv8818.c +2 -2
index 19f823446cda..e494fd33911b 100644
@@ -695,8 +695,8 @@ static int admv8818_init(struct admv8818_state *st)
 
 	if (st->clkin)
 		return admv8818_rfin_band_select(st);
-	else
-		return 0;
+
+	return 0;
 }
 
 static int admv8818_clk_setup(struct admv8818_state *st)
Signature · 1 line
2.43.0
Reviewed-by on v1 5/5
#6 lore raw

Re: [PATCH 5/5] iio: filter: admv8818: remove redundant else after return

Quoted 2 lines · Antoniu Miclaus

The else in admv8818_init() is unnecessary since the if block already returns after calling admv8818_rfin_band_select() when clkin is present.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw
In reply to Antoniu Miclaus
Quoted 3 lines · Antoniu Miclaus

Remove redundant else branches after return statements across several IIO drivers (ad7298, ad7606, ad5592r, ad5758, admv8818) to simplify control flow.

While technically you are correct, the only patch 5 makes sense to me. The rest might be better with 'else' be present. It depends on the logic between the lines, if they are of the same semantics and it's not about returning error code vs. 0 (success), it may be better to read them if they are started on the same column.

TL;DR: I am not going to NAK, but patches 1-4 is an unneeded churn to me.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw
Quoted 5 lines · Andy Shevchenko
Quoted 3 lines · Antoniu Miclaus

Remove redundant else branches after return statements across several IIO drivers (ad7298, ad7606, ad5592r, ad5758, admv8818) to simplify control flow.

Quoted 7 lines

While technically you are correct, the only patch 5 makes sense to me. The rest might be better with 'else' be present. It depends on the logic between the lines, if they are of the same semantics and it's not about returning error code vs. 0 (success), it may be better to read them if they are started on the same column.

TL;DR: I am not going to NAK, but patches 1-4 is an unneeded churn to me.

For the record you may look at my patches in the Git history on the same matter, they do not kill all 'else':s in such cases.

git log --no-merges -p --author="Andy Shevchenko" --grep "redundant 'else'"

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#9 lore raw
In reply to Andy Shevchenko
Quoted 10 lines · On Fri, 20 Feb 2026 16:13:30 +0200 Andy Shevchenko…
Quoted 3 lines · Antoniu Miclaus

Remove redundant else branches after return statements across several IIO drivers (ad7298, ad7606, ad5592r, ad5758, admv8818) to simplify control flow.

While technically you are correct, the only patch 5 makes sense to me. The rest might be better with 'else' be present. It depends on the logic between the lines, if they are of the same semantics and it's not about returning error code vs. 0 (success), it may be better to read them if they are started on the same column.

I agree. When it's a choice between two 'good' paths and the author felt if / else made that choice aspect clear than I've always taken the view that that is reasonable.

So I've picked up patch 5 but not the others. 5 was a little stronger as it's if (A) do something else do nothing.

Quoted 3 lines

TL;DR: I am not going to NAK, but patches 1-4 is an unneeded churn to me.