[PATCH 8/8] watchdog: core: Update last_keepalive in watchdog_start()

From: Guenter Roeck

Date: Tue Sep 29 2026 - 09:52:30 EST


When starting a watchdog whose hardware is already running,
watchdog_start() calls __watchdog_ping() before marking the watchdog
active, and fails to update wd_data->last_keepalive. As a result:

1. wd_data->last_keepalive remains 0, causing watchdog_get_timeleft() to
calculate the elapsed time since the epoch and return 0 time left.
2. watchdog_update_worker() inside __watchdog_ping() evaluates
watchdog_need_worker() and watchdog_next_keepalive() while WDOG_ACTIVE
is still clear, using wd_data->open_deadline instead of
wd_data->last_keepalive. If open_deadline has expired, the background
keepalive timer is not armed; conversely, if the active watchdog does
not need a worker, the boot keepalive timer is not canceled.

Set WDOG_ACTIVE and wd_data->last_keepalive to started_at before calling
__watchdog_ping(), and revert WDOG_ACTIVE and update the worker if
__watchdog_ping() fails.

Fixes: fbbe35dfcf94 ("watchdog: use __watchdog_ping in startup")
Assisted-by: LLM
Signed-off-by: Guenter Roeck <linux@xxxxxxxxxxxx>
---
drivers/watchdog/watchdog_dev.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
index 24488c20539a..b9979f9957b8 100644
--- a/drivers/watchdog/watchdog_dev.c
+++ b/drivers/watchdog/watchdog_dev.c
@@ -264,10 +264,14 @@ static int watchdog_start(struct watchdog_device *wdd)

started_at = ktime_get();
if (watchdog_hw_running(wdd) && wdd->ops->ping) {
+ set_bit(WDOG_ACTIVE, &wdd->status);
+ wd_data->last_keepalive = started_at;
err = __watchdog_ping(wdd);
if (err == 0) {
- set_bit(WDOG_ACTIVE, &wdd->status);
watchdog_hrtimer_pretimeout_start(wdd);
+ } else {
+ clear_bit(WDOG_ACTIVE, &wdd->status);
+ watchdog_update_worker(wdd);
}
} else {
err = wdd->ops->start(wdd);
--
2.45.2