watchdog: sp805_wdt: fix suspend/resume handling of HW_RUNNING watchdog
PATCH 1/1 watchdog: sp805_wdt: fix suspend/resume handling of HW_RUNNING watchdog
sp805_wdt_suspend() and sp805_wdt_resume() only check watchdog_active(), when the watchdog is left running by the driver sets WDOG_HW_RUNNING in sp805_wdt_probe() but userspace never opens the device, so WDOG_ACTIVE remains cleared, the wdt_disable() will not be executed in sp805_wdt_suspend. In this case, the suspend callback is a no-op and the watchdog keeps counting during system suspend, leading to an unexpected system reset.
Check WDOG_HW_RUNNING and wdt->wdd,can fix this issue.
--- drivers/watchdog/sp805_wdt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/watchdog/sp805_wdt.c +4 -2
@@ -325,7 +325,8 @@ static int __maybe_unused sp805_wdt_suspend(struct device *dev) {struct sp805_wdt *wdt =dev_get_drvdata (dev); -if (watchdog_active (&wdt->wdd)) +if (watchdog_active (&wdt->wdd) || +watchdog_hw_running (&wdt->wdd))return wdt_disable (&wdt->wdd);return 0 ;
@@ -335,7 +336,8 @@ static int __maybe_unused sp805_wdt_resume(struct device *dev) {struct sp805_wdt *wdt =dev_get_drvdata (dev); -if (watchdog_active (&wdt->wdd)) +if (watchdog_active (&wdt->wdd) || +watchdog_hw_running (&wdt->wdd))return wdt_enable (&wdt->wdd);return 0 ;
Signature · 1 line
2.25.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] wdt_restart() fails to reboot the system if the watchdog counter clock (wdt->clk) was previously disabled. --
commit 5341b327de5a15d0411852abc081601a0f32ac49
Author: Li Jun <[email protected]>
watchdog: sp805_wdt: fix suspend/resume handling of HW_RUNNING watchdog
sp805_wdt_suspend() and sp805_wdt_resume() only check watchdog_active(), when the watchdog is left running by the driver sets WDOG_HW_RUNNING. This ensures wdt_disable() is called in suspend.
Quoted 15 lines
drivers/watchdog/sp805_wdt.c +2
-1@@ -325,7 +325,8 @@ static int __maybe_unused sp805_wdt_suspend(struct device *dev) {struct sp805_wdt *wdt =dev_get_drvdata (dev); -if (watchdog_active (&wdt->wdd)) +if (watchdog_active (&wdt->wdd) || +watchdog_hw_running (&wdt->wdd))return wdt_disable (&wdt->wdd);return 0 ;}
[ ... ]
Quoted 11 lines
drivers/watchdog/sp805_wdt.c +2
-1@@ -335,7 +336,8 @@ static int __maybe_unused sp805_wdt_resume(struct device *dev) {struct sp805_wdt *wdt =dev_get_drvdata (dev); -if (watchdog_active (&wdt->wdd)) +if (watchdog_active (&wdt->wdd) || +watchdog_hw_running (&wdt->wdd))return wdt_enable (&wdt->wdd);return 0 ;}
[Severity: High]
This isn't a bug introduced by this patch, but does 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. If a reboot command is subsequently issued, wdt_restart() writes to WDTCONTROL to assert RESET_ENABLE:
drivers/watchdog/sp805_wdt.c:wdt_restart() {
...
writel_relaxed(UNLOCK, wdt->base + WDTLOCK);
writel_relaxed(0, wdt->base + WDTCONTROL);
writel_relaxed(0, wdt->base + WDTLOAD);
writel_relaxed(INT_ENABLE | RESET_ENABLE, wdt->base + WDTCONTROL);
...
}Because the counter clock is disabled, the hardware timer will not count down, and the hardware reset signal is never generated. Since wdt_restart() returns 0 without re-enabling the clock, does the reboot silently fail and hang the system?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 10 lines · Li Jun
sp805_wdt_suspend()andsp805_wdt_resume()only checkwatchdog_active(), when the watchdog is left running by the driver setsWDOG_HW_RUNNINGinsp805_wdt_probe()but userspace never opens the device, soWDOG_ACTIVEremains cleared, thewdt_disable()will not be executed insp805_wdt_suspend. In this case, the suspend callback is a no-op and the watchdog keeps counting during system suspend, leading to an unexpected system reset.
CheckWDOG_HW_RUNNINGand wdt->wdd,can fix this issue.Signed-off-by Li Jun <[email protected]>
Applied.
Thanks,
Guenter