watchdog: Fix memleak in watchdog_cdev_register
authorDinghao Liu <dinghao.liu@zju.edu.cn>
Mon, 24 Aug 2020 02:40:01 +0000 (10:40 +0800)
committerWim Van Sebroeck <wim@linux-watchdog.org>
Wed, 14 Oct 2020 13:02:23 +0000 (15:02 +0200)
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 <dinghao.liu@zju.edu.cn>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Link: https://lore.kernel.org/r/20200824024001.25474-1-dinghao.liu@zju.edu.cn
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
drivers/watchdog/watchdog_dev.c

index 6798add..785270e 100644 (file)
@@ -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);