diff options
| author | Guenter Roeck <linux@roeck-us.net> | 2026-10-27 09:03:52 -0700 |
|---|---|---|
| committer | Guenter Roeck <linux@roeck-us.net> | 2026-11-16 13:26:12 -0800 |
| commit | e1d91be1ec2e68458d4e4eef33b0401016c54e26 (patch) | |
| tree | 79656426da8acd8d2ed6f2e479e8c90082007516 | |
| parent | 9208893253e755b3acf2bc1af038d5c973cc3b45 (diff) | |
watchdog: core: Fix unbalanced module_put() in watchdog_open()
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.
Reported-by: SashikoSashiko <sashiko@sashiko.dev>
Link: https://sashiko.dev/#/bug/linux-64bd788f-a53c-4792-96ca-43b6c69c5fab
Fixes: ee142889e32f ("watchdog: Introduce WDOG_HW_RUNNING flag")
Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Link: https://patch.msgid.link/20261027160353.2519323-2-linux@roeck-us.net
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
| -rw-r--r-- | drivers/watchdog/watchdog_dev.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c index ef2254188f7f..7c80d3753252 100644 --- a/drivers/watchdog/watchdog_dev.c +++ b/drivers/watchdog/watchdog_dev.c @@ -936,7 +936,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); |
