linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: adc: ad9467: Replace PTR_ERR_OR_ZERO() in ad9467_reset()
@ 2025-08-07  1:39 Salah Triki
  2025-08-07  2:07 ` David Lechner
  2025-08-07 20:38 ` Andy Shevchenko
  0 siblings, 2 replies; 3+ messages in thread
From: Salah Triki @ 2025-08-07  1:39 UTC (permalink / raw)
  To: Michael Hennerich, Nuno Sa, Lars-Peter Clausen, Jonathan Cameron,
	David Lechner, Andy Shevchenko, linux-iio, linux-kernel
  Cc: 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.

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: adc: ad9467: Replace PTR_ERR_OR_ZERO() in ad9467_reset()
  2025-08-07  1:39 [PATCH] iio: adc: ad9467: Replace PTR_ERR_OR_ZERO() in ad9467_reset() Salah Triki
@ 2025-08-07  2:07 ` David Lechner
  2025-08-07 20:38 ` Andy Shevchenko
  1 sibling, 0 replies; 3+ messages in thread
From: David Lechner @ 2025-08-07  2:07 UTC (permalink / raw)
  To: Salah Triki, Michael Hennerich, Nuno Sa, Lars-Peter Clausen,
	Jonathan Cameron, Andy Shevchenko, linux-iio, linux-kernel

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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: adc: ad9467: Replace PTR_ERR_OR_ZERO() in ad9467_reset()
  2025-08-07  1:39 [PATCH] iio: adc: ad9467: Replace PTR_ERR_OR_ZERO() in ad9467_reset() Salah Triki
  2025-08-07  2:07 ` David Lechner
@ 2025-08-07 20:38 ` Andy Shevchenko
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2025-08-07 20:38 UTC (permalink / raw)
  To: Salah Triki
  Cc: Michael Hennerich, Nuno Sa, Lars-Peter Clausen, Jonathan Cameron,
	David Lechner, Andy Shevchenko, linux-iio, linux-kernel

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-07 20:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-07  1:39 [PATCH] iio: adc: ad9467: Replace PTR_ERR_OR_ZERO() in ad9467_reset() Salah Triki
2025-08-07  2:07 ` David Lechner
2025-08-07 20:38 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).