[PATCH] watchdog: renesas_wdt: avoid sleeping clock calls in restart handler

From: Luo Yifan

Date: Mon Nov 16 2026 - 21:05:37 EST


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@xxxxxxxxxxxxxxxxxxxx>
---
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