[PATCH 7/8] watchdog: core: Fix unbalanced module_put() in watchdog_open()
From: Guenter Roeck
Date: Tue Sep 29 2026 - 09:52:27 EST
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@xxxxxxxxxxxx>
---
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