watchdog: sp805_wdt: re-enable the clock in the restart handler
PATCH 1/1 watchdog: sp805_wdt: re-enable the clock in the restart handler
wdt_restart() fail to reboot the system if the watchdog counter clock was previously disabled: If userspace cleanly stops the watchdog, the core calls wdt_disable() which disables wdt->clk. No reset comes.
Re-enable the clock in it as in npcm_wdt.
--- drivers/watchdog/sp805_wdt.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/watchdog/sp805_wdt.c +3 -0
@@ -138,6 +138,9 @@ wdt_restart(struct watchdog_device *wdd, unsigned long mode, void *cmd) {struct sp805_wdt *wdt =watchdog_get_drvdata (wdd); +/* For reset, we start the WDT clock and leave it running. */ +clk_prepare_enable (wdt->clk); +writel_relaxed (UNLOCK , wdt->base +WDTLOCK );writel_relaxed (0 , wdt->base +WDTCONTROL );writel_relaxed (0 , wdt->base +WDTLOAD );
Signature · 1 line
2.53.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] watchdog: sp805_wdt: sleeping clk_prepare_enable() call in wdt_restart() - [Low] watchdog…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] watchdog: sp805_wdt: sleeping clk_prepare_enable() call in wdt_restart()
- [Low] watchdog: sp805_wdt: missing Fixes trailer for wdt_restart() clock fix
--
commit 800a9ee3ac4d2d74f9b4e848c39474209c8cef7f
Author: David Yang <[email protected]>
Quoted 10 lines
watchdog:
sp805_wdt: re-enable the clock in the restart handler
wdt_restart()fail to reboot the system if the watchdog counter clock was previously disabled: If userspace cleanly stops the watchdog, the core callswdt_disable()which disableswdt->clk. No reset comes.Re-enable the clock in it as in
npcm_wdt.
[Severity: Low]
Should this bug fix include a Fixes tag for the commit that introduced wdt_restart()?
drivers/watchdog/sp805_wdt.c wdt_restart(struct watchdog_device *wdd, unsigned long mode, void *cmd) · line 142
Quoted 10 lines
drivers/watchdog/sp805_wdt.c +2
-0@@ -138,6 +138,9 @@ wdt_restart(struct watchdog_device *wdd, unsigned long mode, void *cmd) {struct sp805_wdt *wdt =watchdog_get_drvdata (wdd); +/* For reset, we start the WDT clock and leave it running. */ +clk_prepare_enable (wdt->clk);
[Severity: High]
Can wdt_restart() call clk_prepare_enable()?
do_kernel_restart() invokes restart handlers via atomic_notifier_call_chain(&restart_handler_list, ...) under rcu_read_lock() with local interrupts disabled, whereas clk_prepare() acquires the sleeping prepare_lock mutex and calls ->prepare() callbacks. When wdt->clk is unprepared (either because the watchdog was never started or because wdt_disable() called clk_disable_unprepare()), this sleeps in atomic context and can deadlock or hang system reboot.
Unlike sp805_wdt, npcm_wdt prepares its clock at probe time via devm_clk_get_optional_prepared() and uses clk_enable() / clk_disable() at runtime so that npcm_wdt_restart() only calls atomic-safe clk_enable().
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Guenter Roeck
maintainerQuoted 17 lines · David Yang
wdt_restart()fail to reboot the system if the watchdog counter clock was previously disabled: If userspace cleanly stops the watchdog, the core callswdt_disable()which disableswdt->clk. No reset comes.Re-enable the clock in it as in
npcm_wdt.Signed-off-by David Yang <[email protected]>--- drivers/watchdog/sp805_wdt.c | 3 +++ 1 file changed, 3 insertions(+)drivers/watchdog/sp805_wdt.c +0
-0
drivers/watchdog/sp805_wdt.c wdt_restart(struct watchdog_device *wdd, unsigned long mode, void *cmd) · line 146
Quoted 9 lines
drivers/watchdog/sp805_wdt.c +3
-0@@ -138,6 +138,9 @@ wdt_restart(struct watchdog_device *wdd, unsigned long mode, void *cmd) {struct sp805_wdt *wdt =watchdog_get_drvdata (wdd); +/* For reset, we start the WDT clock and leave it running. */ +clk_prepare_enable (wdt->clk); +writel_relaxed (UNLOCK , wdt->base +WDTLOCK );writel_relaxed (0 , wdt->base +WDTCONTROL );writel_relaxed (0 , wdt->base +WDTLOAD );
This probably needs a fix similar to commit 4e83ea5b2219 ("watchdog: npcm:
fix sleeping clock call in restart handler") - leave the clock prepared all the time and only enable / disable it when starting or stopping the watchdog.
Guenter