mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] watchdog: msc313e: Fix premature reset during timeout update
@ 2026-09-13  6:51 Tzung-Bi Shih
  2026-09-17  0:31 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Tzung-Bi Shih @ 2026-09-13  6:51 UTC (permalink / raw)
  To: Wim Van Sebroeck, Guenter Roeck
  Cc: Daniel Palmer, Romain Perier, linux-watchdog, linux-kernel, tzungbi

Updating the 32-bit hardware timeout requires writing to two 16-bit
registers sequentially.  If the watchdog is actively running, this
non-atomic update might trigger a premature system reset.

Clear the watchdog counter before updating the registers to prevent the
timer from timing out prematurely against an intermediate threshold.

Fixes: e9800b799464 ("watchdog: Add Mstar MSC313e WDT driver")
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
This fixes a Sashiko report [1].

[1] https://lore.kernel.org/all/20260828162210.3C2881F000E9@smtp.kernel.org
---
 drivers/watchdog/msc313e_wdt.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/watchdog/msc313e_wdt.c b/drivers/watchdog/msc313e_wdt.c
index dc7bdd5660e6..0a68be7a217b 100644
--- a/drivers/watchdog/msc313e_wdt.c
+++ b/drivers/watchdog/msc313e_wdt.c
@@ -46,6 +46,9 @@ static void msc313e_wdt_set_hw_timeout(struct msc313e_wdt_priv *priv,
 {
 	u32 t = timeout * clk_get_rate(priv->clk);
 
+	/* Clear before to prevent premature reset during non-atomic updates. */
+	writew(1, priv->base + REG_WDT_CLR);
+
 	writew(t & 0xffff, priv->base + REG_WDT_MAX_PRD_L);
 	writew((t >> 16) & 0xffff, priv->base + REG_WDT_MAX_PRD_H);
 	writew(1, priv->base + REG_WDT_CLR);
@@ -76,6 +79,9 @@ static int msc313e_wdt_stop(struct watchdog_device *wdev)
 {
 	struct msc313e_wdt_priv *priv = watchdog_get_drvdata(wdev);
 
+	/* Clear before to prevent premature reset during non-atomic updates. */
+	writew(1, priv->base + REG_WDT_CLR);
+
 	writew(0, priv->base + REG_WDT_MAX_PRD_L);
 	writew(0, priv->base + REG_WDT_MAX_PRD_H);
 	writew(0, priv->base + REG_WDT_CLR);
-- 
2.53.0


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

* Re: [PATCH] watchdog: msc313e: Fix premature reset during timeout update
  2026-09-13  6:51 [PATCH] watchdog: msc313e: Fix premature reset during timeout update Tzung-Bi Shih
@ 2026-09-17  0:31 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2026-09-17  0:31 UTC (permalink / raw)
  To: Tzung-Bi Shih
  Cc: Wim Van Sebroeck, Daniel Palmer, Romain Perier, linux-watchdog,
	linux-kernel

On Sun, Sep 13, 2026 at 02:51:26PM +0800, Tzung-Bi Shih wrote:
> Updating the 32-bit hardware timeout requires writing to two 16-bit
> registers sequentially.  If the watchdog is actively running, this
> non-atomic update might trigger a premature system reset.
> 
> Clear the watchdog counter before updating the registers to prevent the
> timer from timing out prematurely against an intermediate threshold.
> 
> Fixes: e9800b799464 ("watchdog: Add Mstar MSC313e WDT driver")
> Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>

Applied.

Thanks,
Guenter

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

end of thread, other threads:[~2026-09-17  0:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-13  6:51 [PATCH] watchdog: msc313e: Fix premature reset during timeout update Tzung-Bi Shih
2026-09-17  0:31 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®