aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDinghao Liu <[email protected]>2020-08-24 10:40:01 +0800
committerWim Van Sebroeck <[email protected]>2020-10-14 15:02:23 +0200
commit5afb6d203d0293512aa2c6ae098274a2a4f6ed02 (patch)
tree7ab616f89b31593965ffcdec9ff8ba9c0327c475
parent743949466e55732ae7eef038abf291b9b39d3307 (diff)
watchdog: Fix memleak in watchdog_cdev_register
When watchdog_kworker is NULL, we should free wd_data before the function returns to prevent memleak. Fixes: 664a39236e718 ("watchdog: Introduce hardware maximum heartbeat in watchdog core") Signed-off-by: Dinghao Liu <[email protected]> Reviewed-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guenter Roeck <[email protected]> Signed-off-by: Wim Van Sebroeck <[email protected]>
-rw-r--r--drivers/watchdog/watchdog_dev.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
index 6798addabd5a..785270ee337c 100644
--- a/drivers/watchdog/watchdog_dev.c
+++ b/drivers/watchdog/watchdog_dev.c
@@ -994,8 +994,10 @@ static int watchdog_cdev_register(struct watchdog_device *wdd)
wd_data->wdd = wdd;
wdd->wd_data = wd_data;
- if (IS_ERR_OR_NULL(watchdog_kworker))
+ if (IS_ERR_OR_NULL(watchdog_kworker)) {
+ kfree(wd_data);
return -ENODEV;
+ }
device_initialize(&wd_data->dev);
wd_data->dev.devt = MKDEV(MAJOR(watchdog_devt), wdd->id);