All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] watchdog: gpio_wdt: use __udelay() to avoid recursion
@ 2022-09-27  7:45 Rasmus Villemoes
  2022-09-27  8:00 ` Stefan Roese
  2022-09-27 12:45 ` Stefan Roese
  0 siblings, 2 replies; 4+ messages in thread
From: Rasmus Villemoes @ 2022-09-27  7:45 UTC (permalink / raw)
  To: u-boot; +Cc: Paul Doelle, Stefan Roese, Rasmus Villemoes

The udelay() function in lib/time.c contains a WATCHDOG_RESET()
call. The only reason this doesn't lead to a catastrophic infinite
recursion is due to the rate-limiting in wdt-uclass.c:

		if (time_after_eq(now, priv->next_reset)) {
			priv->next_reset = now + priv->reset_period;
			wdt_reset(dev);
		}

But this would fall apart if ->next_reset was updated after calling the
device's reset method.

This is needlessly fragile, and it's easy enough to avoid that
recursion in the first place by just using __udelay() directly.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
 drivers/watchdog/gpio_wdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/watchdog/gpio_wdt.c b/drivers/watchdog/gpio_wdt.c
index fe06ec8cc9..2920c2c751 100644
--- a/drivers/watchdog/gpio_wdt.c
+++ b/drivers/watchdog/gpio_wdt.c
@@ -31,7 +31,7 @@ static int gpio_wdt_reset(struct udevice *dev)
 	case HW_ALGO_LEVEL:
 		/* Pulse */
 		dm_gpio_set_value(&priv->gpio, 1);
-		udelay(1);
+		__udelay(1);
 		dm_gpio_set_value(&priv->gpio, 0);
 		break;
 	}
-- 
2.37.2


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

* Re: [PATCH] watchdog: gpio_wdt: use __udelay() to avoid recursion
  2022-09-27  7:45 [PATCH] watchdog: gpio_wdt: use __udelay() to avoid recursion Rasmus Villemoes
@ 2022-09-27  8:00 ` Stefan Roese
  2022-09-27 10:21   ` Pali Rohár
  2022-09-27 12:45 ` Stefan Roese
  1 sibling, 1 reply; 4+ messages in thread
From: Stefan Roese @ 2022-09-27  8:00 UTC (permalink / raw)
  To: Rasmus Villemoes, u-boot; +Cc: Paul Doelle, Pali Rohár

Hi Rasmus,

(add Pali to Cc)

On 27.09.22 09:45, Rasmus Villemoes wrote:
> The udelay() function in lib/time.c contains a WATCHDOG_RESET()
> call. The only reason this doesn't lead to a catastrophic infinite
> recursion is due to the rate-limiting in wdt-uclass.c:
> 
> 		if (time_after_eq(now, priv->next_reset)) {
> 			priv->next_reset = now + priv->reset_period;
> 			wdt_reset(dev);
> 		}
> 
> But this would fall apart if ->next_reset was updated after calling the
> device's reset method.
> 
> This is needlessly fragile, and it's easy enough to avoid that
> recursion in the first place by just using __udelay() directly.
> 
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
> ---
>   drivers/watchdog/gpio_wdt.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/watchdog/gpio_wdt.c b/drivers/watchdog/gpio_wdt.c
> index fe06ec8cc9..2920c2c751 100644
> --- a/drivers/watchdog/gpio_wdt.c
> +++ b/drivers/watchdog/gpio_wdt.c
> @@ -31,7 +31,7 @@ static int gpio_wdt_reset(struct udevice *dev)
>   	case HW_ALGO_LEVEL:
>   		/* Pulse */
>   		dm_gpio_set_value(&priv->gpio, 1);
> -		udelay(1);
> +		__udelay(1);
>   		dm_gpio_set_value(&priv->gpio, 0);
>   		break;
>   	}

Yes, good catch:

Reviewed-by: Stefan Roese <sr@denx.de>

The max6370_wdt.c driver has the same problem AFAICT. Pali, could you
please take a look a this?

Thanks,
Stefan

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

* Re: [PATCH] watchdog: gpio_wdt: use __udelay() to avoid recursion
  2022-09-27  8:00 ` Stefan Roese
@ 2022-09-27 10:21   ` Pali Rohár
  0 siblings, 0 replies; 4+ messages in thread
From: Pali Rohár @ 2022-09-27 10:21 UTC (permalink / raw)
  To: Stefan Roese; +Cc: Rasmus Villemoes, u-boot, Paul Doelle

On Tuesday 27 September 2022 10:00:00 Stefan Roese wrote:
> The max6370_wdt.c driver has the same problem AFAICT. Pali, could you
> please take a look a this?

Done, here is patch:
https://patchwork.ozlabs.org/project/uboot/patch/20220927101919.6999-1-pali@kernel.org/

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

* Re: [PATCH] watchdog: gpio_wdt: use __udelay() to avoid recursion
  2022-09-27  7:45 [PATCH] watchdog: gpio_wdt: use __udelay() to avoid recursion Rasmus Villemoes
  2022-09-27  8:00 ` Stefan Roese
@ 2022-09-27 12:45 ` Stefan Roese
  1 sibling, 0 replies; 4+ messages in thread
From: Stefan Roese @ 2022-09-27 12:45 UTC (permalink / raw)
  To: Rasmus Villemoes, u-boot; +Cc: Paul Doelle

On 27.09.22 09:45, Rasmus Villemoes wrote:
> The udelay() function in lib/time.c contains a WATCHDOG_RESET()
> call. The only reason this doesn't lead to a catastrophic infinite
> recursion is due to the rate-limiting in wdt-uclass.c:
> 
> 		if (time_after_eq(now, priv->next_reset)) {
> 			priv->next_reset = now + priv->reset_period;
> 			wdt_reset(dev);
> 		}
> 
> But this would fall apart if ->next_reset was updated after calling the
> device's reset method.
> 
> This is needlessly fragile, and it's easy enough to avoid that
> recursion in the first place by just using __udelay() directly.
> 
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

Applied to u-boot-watchdog/master

Thanks,
Stefan

> ---
>   drivers/watchdog/gpio_wdt.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/watchdog/gpio_wdt.c b/drivers/watchdog/gpio_wdt.c
> index fe06ec8cc9..2920c2c751 100644
> --- a/drivers/watchdog/gpio_wdt.c
> +++ b/drivers/watchdog/gpio_wdt.c
> @@ -31,7 +31,7 @@ static int gpio_wdt_reset(struct udevice *dev)
>   	case HW_ALGO_LEVEL:
>   		/* Pulse */
>   		dm_gpio_set_value(&priv->gpio, 1);
> -		udelay(1);
> +		__udelay(1);
>   		dm_gpio_set_value(&priv->gpio, 0);
>   		break;
>   	}

Viele Grüße,
Stefan Roese

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de

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

end of thread, other threads:[~2022-09-27 12:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-27  7:45 [PATCH] watchdog: gpio_wdt: use __udelay() to avoid recursion Rasmus Villemoes
2022-09-27  8:00 ` Stefan Roese
2022-09-27 10:21   ` Pali Rohár
2022-09-27 12:45 ` Stefan Roese

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.