iio: adc: ad9467: Replace PTR_ERR_OR_ZERO() in ad9467_reset()
Subsystems (3)
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
@@ -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
David Lechner
reviewerQuoted 14 lines · Salah Triki
PTR_ERR_OR_ZERO()returns 0 if the argument is NULL, which can hide real issues when the caller expects anERR_PTRon failure. Use a ternary expression instead to return the appropriate error code.Signed-off-by Salah Triki <[email protected]>--- drivers/iio/adc/ad9467.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/adc/ad9467.c +0
-0
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.
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 anERR_PTRon 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