All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] watchdog: renesas_wdt: avoid sleeping clock calls in restart handler
@ 2026-11-17  2:05 Luo Yifan
  2026-11-17  2:20 ` sashiko-bot
  0 siblings, 1 reply; 3+ messages in thread
From: Luo Yifan @ 2026-11-17  2:05 UTC (permalink / raw)
  To: Wim Van Sebroeck, Guenter Roeck, linux-watchdog; +Cc: linux-kernel

rwdt_restart() runs in atomic context, as the comment above the function
points out, but it calls clk_prepare_enable().  clk_prepare() may sleep on
the clock mutex, which is not allowed from a restart handler.

Prepare the clock once in the probe function and only call clk_enable()
from the restart handler.  clk_enable() does not sleep, so the restart
path stays atomic.  Unprepare the clock in the probe error path and in
rwdt_remove().

Signed-off-by: Luo Yifan <luoyifan@cmss.chinamobile.com>
---
 drivers/watchdog/renesas_wdt.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/watchdog/renesas_wdt.c b/drivers/watchdog/renesas_wdt.c
index d9760f2a3b..9630d05686 100644
--- a/drivers/watchdog/renesas_wdt.c
+++ b/drivers/watchdog/renesas_wdt.c
@@ -135,7 +135,7 @@ static int rwdt_restart(struct watchdog_device *wdev, unsigned long action,
 	struct rwdt_priv *priv = watchdog_get_drvdata(wdev);
 	u8 val;
 
-	clk_prepare_enable(priv->clk);
+	clk_enable(priv->clk);
 
 	/* Stop the timer before we modify any register */
 	val = readb_relaxed(priv->base + RWTCSRA) & ~RWTCSRA_TME;
@@ -233,6 +233,14 @@ static int rwdt_probe(struct platform_device *pdev)
 	if (IS_ERR(priv->clk))
 		return PTR_ERR(priv->clk);
 
+	/*
+	 * The restart handler runs in atomic context and can only enable the
+	 * clock, so prepare it here.
+	 */
+	ret = clk_prepare(priv->clk);
+	if (ret)
+		return ret;
+
 	pm_runtime_enable(dev);
 	pm_runtime_get_sync(dev);
 	priv->clk_rate = clk_get_rate(priv->clk);
@@ -290,6 +298,7 @@ static int rwdt_probe(struct platform_device *pdev)
 
  out_pm_disable:
 	pm_runtime_disable(dev);
+	clk_unprepare(priv->clk);
 	return ret;
 }
 
@@ -299,6 +308,7 @@ static void rwdt_remove(struct platform_device *pdev)
 
 	watchdog_unregister_device(&priv->wdev);
 	pm_runtime_disable(&pdev->dev);
+	clk_unprepare(priv->clk);
 }
 
 static int rwdt_suspend(struct device *dev)
-- 
2.24.4




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

end of thread, other threads:[~2026-11-18  1:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17  2:05 [PATCH] watchdog: renesas_wdt: avoid sleeping clock calls in restart handler Luo Yifan
2026-11-17  2:20 ` sashiko-bot
2026-11-18  1:58   ` Guenter Roeck

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.