Skip to contentSkip to conversation

iio: adc: ad9467: Replace PTR_ERR_OR_ZERO() in ad9467_reset()

PATCH In review Salah Triki 3 participants 3 messages Aug 7, 2025

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

PATCH 1/1 iio: adc: ad9467: Replace PTR_ERR_OR_ZERO() in ad9467_reset()

PTR_ERR_OR_ZERO() returns 0 if the argument is NULL, which can hide real issues when the caller expects an ERR_PTR on failure. Use a ternary expression instead to return the appropriate error code.

---
 drivers/iio/adc/ad9467.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ad9467.c +1 -1
index f7a9f46ea0dc..70aee2666ff1 100644
@@ -945,7 +945,7 @@ static int ad9467_reset(struct device *dev)
 
 	gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
 	if (IS_ERR_OR_NULL(gpio))
-		return PTR_ERR_OR_ZERO(gpio);
+		return gpio ? PTR_ERR(gpio) : -ENODEV;
 
 	fsleep(1);
 	gpiod_set_value_cansleep(gpio, 0);
Signature · 1 line
2.43.0
reviewer
#1 lore raw
Quoted 14 lines · Salah Triki

PTR_ERR_OR_ZERO() returns 0 if the argument is NULL, which can hide real issues when the caller expects an ERR_PTR on failure. Use a ternary expression instead to return the appropriate error code.

---
 drivers/iio/adc/ad9467.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ad9467.c +0 -0
index f7a9f46ea0dc..70aee2666ff1 100644

drivers/iio/adc/ad9467.c static int ad9467_reset(struct device *dev) · line 951

Quoted 8 lines
drivers/iio/adc/ad9467.c +1 -1
@@ -945,7 +945,7 @@ static int ad9467_reset(struct device *dev)
 
 	gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
 	if (IS_ERR_OR_NULL(gpio))
-		return PTR_ERR_OR_ZERO(gpio);
+		return gpio ? PTR_ERR(gpio) : -ENODEV;
 
 	fsleep(1);
 	gpiod_set_value_cansleep(gpio, 0);

The existing code looks correct to me. The reset gpio is optional so early return of 0 when there is no gpio seems fine. Changing it to return an error could break existing users since it will cause probe to fail.

Also, if the original intention was to make the gpio required, then it should just not use devm_gpiod_get_optional() and simplify the whole thing. But I don't think that was the intention.

#2 lore raw
In reply to Salah Triki
Quoted 3 lines · Salah Triki

PTR_ERR_OR_ZERO() returns 0 if the argument is NULL, which can hide real issues when the caller expects an ERR_PTR on failure. Use a ternary

ERR_PTR()

Quoted 1 line

expression instead to return the appropriate error code.

Tell us more how you got all this, please. (A new) static analyser tool? Reading the code?

Signature · 2 lines
With Best Regards,
Andy Shevchenko