mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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: [PATCHv3 1/2] watchdog: pika_wdt: fix timer lifecycle bugs
Date: Mon,  8 Jun 2026 14:04:01 -0700	[thread overview]
Message-ID: <20260608210402.31545-2-rosenp@gmail.com> (raw)
In-Reply-To: <20260608210402.31545-1-rosenp@gmail.com>

Two timer lifecycle bugs in the PIKA watchdog driver:

1. pikawdt_release() clears the open bit before stopping the timer,
   allowing a concurrent pikawdt_open() to start a new timer that
   is then immediately deleted.  Move clear_bit after the timer
   stop.  Use timer_shutdown_sync() so the handler cannot re-arm
   after the call returns.  Add timer_setup() in pikawdt_open()
   to re-initialize the timer for the next open.

2. pikawdt_exit() unmaps FPGA IO memory without first stopping the
   ping timer.  If the timer handler fires after iounmap(), it
   executes pikawdt_ping() on freed memory.  Use timer_shutdown_sync()
   which permanently prevents re-arming.

Assisted-by: opencode:big-pickle
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/watchdog/pika_wdt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/watchdog/pika_wdt.c b/drivers/watchdog/pika_wdt.c
index 87b8988d2520..d567103ec5e4 100644
--- a/drivers/watchdog/pika_wdt.c
+++ b/drivers/watchdog/pika_wdt.c
@@ -117,6 +117,7 @@ static int pikawdt_open(struct inode *inode, struct file *file)
 	if (test_and_set_bit(0, &pikawdt_private.open))
 		return -EBUSY;

+	timer_setup(&pikawdt_private.timer, pikawdt_ping, 0);
 	pikawdt_start();

 	return stream_open(inode, file);
@@ -129,7 +130,7 @@ static int pikawdt_release(struct inode *inode, struct file *file)
 {
 	/* stop internal ping */
 	if (!pikawdt_private.expect_close)
-		timer_delete(&pikawdt_private.timer);
+		timer_shutdown_sync(&pikawdt_private.timer);

 	clear_bit(0, &pikawdt_private.open);
 	pikawdt_private.expect_close = 0;
@@ -291,6 +292,7 @@ static void __exit pikawdt_exit(void)
 {
 	misc_deregister(&pikawdt_miscdev);

+	timer_shutdown_sync(&pikawdt_private.timer);
 	iounmap(pikawdt_private.fpga);
 }

--
2.54.0


  reply	other threads:[~2026-06-08 21:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-08 21:04 [PATCHv3 0/2] watchdog: pika_wdt: portability and timer lifecycle fixes Rosen Penev
2026-06-08 21:04 ` Rosen Penev [this message]
2026-06-08 22:52   ` [PATCHv3 1/2] watchdog: pika_wdt: fix timer lifecycle bugs Guenter Roeck
2026-06-08 21:04 ` [PATCHv3 2/2] watchdog: pika_wdt: enable COMPILE_TEST builds Rosen Penev
2026-06-08 22:55   ` Guenter Roeck
2026-06-08 23:46     ` Rosen Penev
2026-06-09  3:09       ` Guenter Roeck

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=20260608210402.31545-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

Powered by JetHome