drivers/iio/adc/ad9467.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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.
Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
drivers/iio/adc/ad9467.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c
index f7a9f46ea0dc..70aee2666ff1 100644
--- a/drivers/iio/adc/ad9467.c
+++ b/drivers/iio/adc/ad9467.c
@@ -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);
--
2.43.0
On Thu, Aug 7, 2025 at 3:39 AM Salah Triki <salah.triki@gmail.com> wrote: > > 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() > 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? -- With Best Regards, Andy Shevchenko
On 8/6/25 8:39 PM, Salah Triki wrote: > 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. > > Signed-off-by: Salah Triki <salah.triki@gmail.com> > --- > drivers/iio/adc/ad9467.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c > index f7a9f46ea0dc..70aee2666ff1 100644 > --- a/drivers/iio/adc/ad9467.c > +++ b/drivers/iio/adc/ad9467.c > @@ -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.
© 2016 - 2025 Red Hat, Inc.