[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200823071338.15209-1-dinghao.liu@zju.edu.cn>
Date: Sun, 23 Aug 2020 15:13:38 +0800
From: Dinghao Liu <dinghao.liu@....edu.cn>
To: dinghao.liu@....edu.cn, kjlu@....edu
Cc: Wim Van Sebroeck <wim@...ux-watchdog.org>,
Guenter Roeck <linux@...ck-us.net>,
Alexander Sverdlin <alexander.sverdlin@...ia.com>,
Krzysztof Sobota <krzysztof.sobota@...ia.com>,
linux-watchdog@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH] watchdog: Fix double-free in watchdog_cdev_register
When misc_register() fails, wd_data will be released by the
release callback function watchdog_core_data_release(), so
we don't need to free it again. But when watchdog_kworker is
NULL, we should free wd_data to prevent memleak.
Fixes: cb36e29bb0e4b ("watchdog: initialize device before misc_register")
Signed-off-by: Dinghao Liu <dinghao.liu@....edu.cn>
---
drivers/watchdog/watchdog_dev.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
index 6798addabd5a..8ee78e26feb1 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);
@@ -1021,7 +1023,6 @@ static int watchdog_cdev_register(struct watchdog_device *wdd)
pr_err("%s: a legacy watchdog module is probably present.\n",
wdd->info->identity);
old_wd_data = NULL;
- kfree(wd_data);
return err;
}
}
--
2.17.1
Powered by blists - more mailing lists