From: Rosen Penev <rosenp@gmail.com>
To: linux-watchdog@vger.kernel.org
Cc: Wim Van Sebroeck <wim@linux-watchdog.org>,
Guenter Roeck <linux@roeck-us.net>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH v2 1/2] watchdog: pika_wdt: fix timer leak and close race
Date: Tue, 2 Jun 2026 21:02:29 -0700 [thread overview]
Message-ID: <20260603040230.318998-2-rosenp@gmail.com> (raw)
In-Reply-To: <20260603040230.318998-1-rosenp@gmail.com>
Two timer lifecycle bugs in the PIKA watchdog driver:
1. pikawdt_exit() unmaps the FPGA IO memory without stopping the ping
timer. A timer tick after iounmap executes pikawdt_ping() on freed
memory. Add timer_delete_sync() before iounmap.
2. pikawdt_release() uses timer_delete() which does not synchronize with
a concurrently executing timer handler. If pikawdt_ping() runs on
another CPU after timer_delete() marks the timer as deleted but before
the open bit is cleared, it can call mod_timer() and re-arm itself.
Once the open bit is subsequently cleared, the condition
(!nowayout && !open) becomes true and the timer keeps patting the
watchdog forever, defeating the intended reset-on-unexpected-close.
Fix by clearing the open bit before calling timer_delete_sync(), which
waits for any in-flight handler to complete.
Assisted-by: opencode:big-pickle
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/watchdog/pika_wdt.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/watchdog/pika_wdt.c b/drivers/watchdog/pika_wdt.c
index 87b8988d2520..60a846cb3601 100644
--- a/drivers/watchdog/pika_wdt.c
+++ b/drivers/watchdog/pika_wdt.c
@@ -127,11 +127,12 @@ static int pikawdt_open(struct inode *inode, struct file *file)
*/
static int pikawdt_release(struct inode *inode, struct file *file)
{
+ clear_bit(0, &pikawdt_private.open);
+
/* stop internal ping */
if (!pikawdt_private.expect_close)
- timer_delete(&pikawdt_private.timer);
+ timer_delete_sync(&pikawdt_private.timer);
- clear_bit(0, &pikawdt_private.open);
pikawdt_private.expect_close = 0;
return 0;
}
@@ -291,6 +292,7 @@ static void __exit pikawdt_exit(void)
{
misc_deregister(&pikawdt_miscdev);
+ timer_delete_sync(&pikawdt_private.timer);
iounmap(pikawdt_private.fpga);
}
--
2.54.0
next prev parent reply other threads:[~2026-06-03 4:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-03 4:02 [PATCH v2 0/2] watchdog: pika_wdt: portability and timer lifecycle fixes Rosen Penev
2026-06-03 4:02 ` Rosen Penev [this message]
2026-06-03 4:02 ` [PATCH v2 2/2] watchdog: pika_wdt: replace in_be32/out_be32 with ioread32be/iowrite32be Rosen Penev
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=20260603040230.318998-2-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=wim@linux-watchdog.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
all inboxes | Powered by JetHome®