From: Guenter Roeck <linux@roeck-us.net>
To: linux-watchdog@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH 7/8] watchdog: core: Fix unbalanced module_put() in watchdog_open()
Date: Tue, 29 Sep 2026 06:46:34 -0700 [thread overview]
Message-ID: <20260929134635.2567137-8-linux@roeck-us.net> (raw)
In-Reply-To: <20260929134635.2567137-1-linux@roeck-us.net>
If the hardware watchdog is running (hw_running is true), try_module_get()
is skipped. However, if watchdog_start() then fails, the code jumps to
out_mod and unconditionally calls module_put().
This can cause a premature driver module unload while hardware timers or
interrupts are active by dropping a reference that was never acquired.
Only call module_put() if the hardware watchdog is not running to fix the
problem.
Fixes: ee142889e32f ("watchdog: Introduce WDOG_HW_RUNNING flag")
Assisted-by: LLM
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/watchdog/watchdog_dev.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
index 31567ffbfc23..24488c20539a 100644
--- a/drivers/watchdog/watchdog_dev.c
+++ b/drivers/watchdog/watchdog_dev.c
@@ -937,7 +937,8 @@ static int watchdog_open(struct inode *inode, struct file *file)
return stream_open(inode, file);
out_mod:
- module_put(wd_data->wdd->ops->owner);
+ if (!hw_running)
+ module_put(wd_data->wdd->ops->owner);
out_clear:
clear_bit(_WDOG_DEV_OPEN, &wd_data->status);
mutex_unlock(&wd_data->lock);
--
2.45.2
next prev parent reply other threads:[~2026-09-29 13:46 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 13:46 [PATCH 0/8] watchdog: core: Fix locking, lifetime, suspend, and state management bugs Guenter Roeck
2026-09-29 13:46 ` [PATCH 1/8] watchdog: core: Clear wd_data pointer on errors Guenter Roeck
2026-09-30 11:53 ` Tzung-Bi Shih
2026-09-29 13:46 ` [PATCH 2/8] watchdog: core: Add missing locks Guenter Roeck
2026-09-30 11:53 ` Tzung-Bi Shih
2026-09-29 13:46 ` [PATCH 3/8] watchdog: core: Prevent ping worker from re-arming timer on suspend Guenter Roeck
2026-09-30 11:53 ` Tzung-Bi Shih
2026-09-29 13:46 ` [PATCH 4/8] watchdog: core: Stop pretimeout hrtimer " Guenter Roeck
2026-09-29 13:59 ` sashiko-bot
2026-09-30 11:54 ` Tzung-Bi Shih
2026-09-29 13:46 ` [PATCH 5/8] watchdog: core: Restore WDOG_HW_RUNNING if stopping watchdog fails Guenter Roeck
2026-09-30 11:54 ` Tzung-Bi Shih
2026-09-30 12:37 ` Guenter Roeck
2026-09-29 13:46 ` [PATCH 6/8] watchdog: core: Cancel timer if cdev_device_add() fails Guenter Roeck
2026-09-30 11:54 ` Tzung-Bi Shih
2026-09-29 13:46 ` Guenter Roeck [this message]
2026-09-30 11:54 ` [PATCH 7/8] watchdog: core: Fix unbalanced module_put() in watchdog_open() Tzung-Bi Shih
2026-09-29 13:46 ` [PATCH 8/8] watchdog: core: Update last_keepalive in watchdog_start() Guenter Roeck
2026-09-30 11:54 ` Tzung-Bi Shih
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=20260929134635.2567137-8-linux@roeck-us.net \
--to=linux@roeck-us.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-watchdog@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.