Skip to contentSkip to conversation

iio: simplify return statements

PATCH Applied Antoniu Miclaus 3 participants 6 messages Feb 20 – Feb 22

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover iio: simplify return statements

Minor cleanups across two IIO drivers to simplify return paths by removing unnecessary intermediate variable assignments before returning error codes.

Antoniu Miclaus (2):
iio: adc: ad7266: simplify error return
iio: addac: ad74413r: simplify timeout return

 drivers/iio/adc/ad7266.c     | 6 ++----
 drivers/iio/addac/ad74413r.c | 6 ++----
 2 files changed, 4 insertions(+), 8 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 iio: adc: ad7266: simplify error return

Return PTR_ERR() directly instead of assigning it to an intermediate variable first.

---
 drivers/iio/adc/ad7266.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/iio/adc/ad7266.c +2 -4
index 3364ac6c4631..0ef36c249ab8 100644
@@ -409,10 +409,8 @@ static int ad7266_probe(struct spi_device *spi)
 				st->gpios[i] = devm_gpiod_get(&spi->dev,
 						      ad7266_gpio_labels[i],
 						      GPIOD_OUT_LOW);
-				if (IS_ERR(st->gpios[i])) {
-					ret = PTR_ERR(st->gpios[i]);
-					return ret;
-				}
+				if (IS_ERR(st->gpios[i]))
+					return PTR_ERR(st->gpios[i]);
 			}
 		}
 	} else {
Signature · 1 line
2.43.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] iio: adc: ad7266: simplify error return

Quoted 2 lines · Antoniu Miclaus

Return PTR_ERR() directly instead of assigning it to an intermediate variable first.

Definitely!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Applied
#3 lore raw

Re: [PATCH 1/2] iio: adc: ad7266: simplify error return

Quoted 6 lines · On Fri, 20 Feb 2026 16:09:08 +0200 Andy Shevchenko…
Quoted 2 lines · Antoniu Miclaus

Return PTR_ERR() directly instead of assigning it to an intermediate variable first.

Definitely!

Applied.

Quoted 1 line
#4 lore raw

PATCH 2/2 iio: addac: ad74413r: simplify timeout return

In reply to Antoniu Miclaus

Return -ETIMEDOUT directly instead of assigning it to an intermediate variable first.

---
 drivers/iio/addac/ad74413r.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/iio/addac/ad74413r.c +2 -4
index a20b4d48c5f7..b1cf8a011277 100644
@@ -841,10 +841,8 @@ static int _ad74413r_get_single_adc_result(struct ad74413r_state *st,
 
 	ret = wait_for_completion_timeout(&st->adc_data_completion,
 					  msecs_to_jiffies(1000));
-	if (!ret) {
-		ret = -ETIMEDOUT;
-		return ret;
-	}
+	if (!ret)
+		return -ETIMEDOUT;
 
 	ret = regmap_read(st->regmap, AD74413R_REG_ADC_RESULT_X(channel),
 			  &uval);
Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH 2/2] iio: addac: ad74413r: simplify timeout return

Quoted 2 lines · Antoniu Miclaus

Return -ETIMEDOUT directly instead of assigning it to an intermediate variable first.

...

drivers/iio/addac/ad74413r.c static int _ad74413r_get_single_adc_result(struct ad74413r_state *st, · line 845

Quoted 8 lines
drivers/iio/addac/ad74413r.c +2 -4
 	ret = wait_for_completion_timeout(&st->adc_data_completion,
 					  msecs_to_jiffies(1000));
-	if (!ret) {
-		ret = -ETIMEDOUT;
-		return ret;
-	}
+	if (!ret)
+		return -ETIMEDOUT;

I would prefer to have just

	if (!wait_for_completion_timeout(&st->adc_data_completion,
					 msecs_to_jiffies(1000)))
		return -ETIMEDOUT;

Using ret in a different semantics might lead to subtle issues in case some code sneaks in and out of a sudden will recognize positive value as something else.

Signature · 2 lines
With Best Regards,
Andy Shevchenko