From: Guenter Roeck <linux@roeck-us.net>
To: linux-watchdog@vger.kernel.org
Cc: Tzung-Bi Shih <tzungbi@kernel.org>, Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH v2 8/8] watchdog: core: Update last_keepalive in watchdog_start()
Date: Tue, 27 Oct 2026 09:03:53 -0700 [thread overview]
Message-ID: <20261027160353.2519323-3-linux@roeck-us.net> (raw)
In-Reply-To: <20261027160353.2519323-1-linux@roeck-us.net>
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
Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
v2: Added Reviewed-by: tag
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 7c80d3753252..aad3f1f1b4ce 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
prev parent reply other threads:[~2026-10-27 16:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 16:03 [PATCH v2 6/8] watchdog: core: Cancel timer if cdev_device_add() fails Guenter Roeck
2026-10-27 16:03 ` [PATCH v2 7/8] watchdog: core: Fix unbalanced module_put() in watchdog_open() Guenter Roeck
2026-10-27 16:03 ` Guenter Roeck [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261027160353.2519323-3-linux@roeck-us.net \
--to=linux@roeck-us.net \
--cc=linux-watchdog@vger.kernel.org \
--cc=tzungbi@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox