Re: [PATCH] watchdog: core: Fix module refcount imbalance when open fails
From: Guenter Roeck
Date: Mon Nov 23 2026 - 16:15:59 EST
On 11/23/26 12:46, Artur Kowalski wrote:
watchdog_open() doesn't take a module reference for a watchdog that is
running in hardware, as watchdog_cdev_register() already holds one for
it. If watchdog_start() then fails, which for such a watchdog means the
driver's ping failed, the error path drops a module reference anyway.
This drops the reference held for the running watchdog, so the module
can be unloaded while the watchdog is running and the core still uses
it. Stopping the watchdog through the core later drops the reference a
second time, underflowing the module refcount.
Only drop the module reference on the error path if it was taken.
This was found with the help of Sashiko and Claude. It can be triggered
by any modular driver whose ping can fail on a watchdog that was running
when it was registered. No in-tree driver was checked for that. The fix
was build tested only, and no reproducer was run.
Fixes: ee142889e32f ("watchdog: Introduce WDOG_HW_RUNNING flag")
Signed-off-by: Artur Kowalski <arturkow2000@xxxxxxxxx>
---
This was found while developing a Tegra20 watchdog driver. A watchdog
reset hangs Tegra20's boot ROM once the VDE power partition is off, so
the driver stops the watchdog behind the core's back when that happens.
Failing pings afterwards would trigger this bug when opening a watchdog
left running by the bootloader, so the driver keeps them succeeding
until user space has started the watchdog.
---
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 e8c1fcb53c56..9ad715d4d46d 100644
--- a/drivers/watchdog/watchdog_dev.c
+++ b/drivers/watchdog/watchdog_dev.c
@@ -913,7 +913,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);
That seems to be identical to upstream commit e1d91be1ec2e6 ("watchdog:
core: Fix unbalanced module_put() in watchdog_open()").
Id suggest to update your tree to v7.4-rc4 or later to avoid hitting
a number of other recently fixed issues in the watchdog subsystem core.
Thanks,
Guenter