watchdog: omap: Fix early_enable handling in omap_wdt_probe()
Guenter Roeck
maintainerPATCH 1/1 watchdog: omap: Fix early_enable handling in omap_wdt_probe()
Commit cd004d8299f1 ("watchdog: Fix OMAP watchdog early handling") updated omap_wdt_probe() to call omap_wdt_start() and set WDOG_HW_RUNNING before watchdog_register_device() when the early_enable module parameter is enabled, introducing two bugs:
1. During probe, omap_wdt_probe() acquires an initial runtime PM reference via pm_runtime_get_sync(), and omap_wdt_start() sets omap_wdt_users, acquires a second runtime PM reference, and enables the hardware timer. If watchdog_register_device() subsequently fails, the error path drops only the initial runtime PM reference without calling omap_wdt_stop(), leaking the second runtime PM reference and leaving the hardware timer counting down without a registered watchdog device or core keepalive worker to service it, causing an unexpected system reset.
2. The original post-registration omap_wdt_start() call was left in place, so when early_enable is enabled and registration succeeds, omap_wdt_start() is called a second time. This leaks a runtime PM reference (preventing runtime suspend even after the watchdog is stopped) and races with userspace after /dev/watchdog is exposed, potentially re-enabling the hardware timer after userspace has reconfigured or stopped it.
Stop the watchdog via omap_wdt_stop() when omap_wdt_users is set on watchdog_register_device() failure, and remove the duplicate post-registration omap_wdt_start() call.
---
Also see
https://patchwork.kernel.org/project/linux-watchdog/patch/[email protected]/
for a partial fix of the problem.
drivers/watchdog/omap_wdt.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/watchdog/omap_wdt.c +2 -3
@@ -277,6 +277,8 @@ static int omap_wdt_probe(struct platform_device *pdev) ret =watchdog_register_device (&wdev->wdog);if (ret) { +if (wdev->omap_wdt_users) +omap_wdt_stop (&wdev->wdog);pm_runtime_put (wdev->dev);pm_runtime_disable (wdev->dev);return ret;
@@ -286,9 +288,6 @@ static int omap_wdt_probe(struct platform_device *pdev)readl_relaxed (wdev->base +OMAP_WATCHDOG_REV ) &0xFF , wdev->wdog.timeout); -if (early_enable) -omap_wdt_start (&wdev->wdog); -pm_runtime_put (wdev->dev);return 0 ;
Signature · 1 line
2.45.2