* [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
* Re: [PATCH] watchdog: renesas_wdt: avoid sleeping clock calls in restart handler
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
0 siblings, 1 reply; 3+ messages in thread
From: sashiko-bot @ 2026-11-17 2:20 UTC (permalink / raw)
To: Luo Yifan, linux-watchdog
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] watchdog: renesas_wdt: missing Fixes trailer for atomic sleep
fix
- [Low] watchdog: renesas_wdt: use devm_clk_get_prepared() in
rwdt_probe()
--
commit 4ed48dd9a6e0be55587f40b05e00cb1b9e5da877
Author: Luo Yifan <luoyifan@cmss.chinamobile.com>
> watchdog: renesas_wdt: avoid sleeping clock calls in restart handler
>
> 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>
[Severity: Low]
Since this fixes the sleeping clk_prepare_enable() call in rwdt_restart(),
should this include a Fixes tag?
Fixes: fa01fa70039c ("watchdog: renesas_wdt: don't sleep in atomic context")
> diff --git a/drivers/watchdog/renesas_wdt.c b/drivers/watchdog/renesas_wdt.c
> index d9760f2a3b235..9630d05686461 100644
> --- a/drivers/watchdog/renesas_wdt.c
> +++ b/drivers/watchdog/renesas_wdt.c
[ ... ]
> @@ -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);
> }
[Severity: Low]
This isn't a bug, but could rwdt_probe() use devm_clk_get_prepared() instead
of devm_clk_get()? That would prepare priv->clk on acquisition and
automatically unprepare it on probe failure or after rwdt_remove(), avoiding
the manual clk_prepare() and clk_unprepare() calls.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117020530.19973-1-luoyifan@cmss.chinamobile.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] watchdog: renesas_wdt: avoid sleeping clock calls in restart handler
2026-11-17 2:20 ` sashiko-bot
@ 2026-11-18 1:58 ` Guenter Roeck
0 siblings, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2026-11-18 1:58 UTC (permalink / raw)
To: sashiko-reviews, Luo Yifan, linux-watchdog
On 11/16/26 18:20, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issues to consider:
> - [Low] watchdog: renesas_wdt: missing Fixes trailer for atomic sleep
> fix
> - [Low] watchdog: renesas_wdt: use devm_clk_get_prepared() in
> rwdt_probe()
Please address both.
Thanks,
Guenter
> --
>
> commit 4ed48dd9a6e0be55587f40b05e00cb1b9e5da877
> Author: Luo Yifan <luoyifan@cmss.chinamobile.com>
>
>> watchdog: renesas_wdt: avoid sleeping clock calls in restart handler
>>
>> 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>
>
> [Severity: Low]
> Since this fixes the sleeping clk_prepare_enable() call in rwdt_restart(),
> should this include a Fixes tag?
>
> Fixes: fa01fa70039c ("watchdog: renesas_wdt: don't sleep in atomic context")
>
>> diff --git a/drivers/watchdog/renesas_wdt.c b/drivers/watchdog/renesas_wdt.c
>> index d9760f2a3b235..9630d05686461 100644
>> --- a/drivers/watchdog/renesas_wdt.c
>> +++ b/drivers/watchdog/renesas_wdt.c
>
> [ ... ]
>
>> @@ -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);
>> }
>
> [Severity: Low]
> This isn't a bug, but could rwdt_probe() use devm_clk_get_prepared() instead
> of devm_clk_get()? That would prepare priv->clk on acquisition and
> automatically unprepare it on probe failure or after rwdt_remove(), avoiding
> the manual clk_prepare() and clk_unprepare() calls.
>
^ permalink raw reply [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.