Skip to contentSkip to conversation

watchdog: fix memory leak in error path

PATCH In review Pavel Machek 2 participants 2 messages Sep 20, 2020 Watchdog device drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 watchdog: fix memory leak in error path

Fix memory leak in error path.

drivers/watchdog/watchdog_dev.c +3 -1
index 6798addabd5a..785270ee337c 100644
@@ -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);
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#1 lore raw

Pavel Machek <[email protected]> a écrit :

Quoted 9 lines

Fix memory leak in error path.

drivers/watchdog/watchdog_dev.c +0 -0
index 6798addabd5a..785270ee337c 100644

drivers/watchdog/watchdog_dev.c static int watchdog_cdev_register(struct · line 998

Quoted 5 lines
drivers/watchdog/watchdog_dev.c +0 -1
@@ -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))

Maybe it would be better to move this check before the kzalloc as the wd_data is not needed for doing that check.

Christophe

Quoted 11 lines
drivers/watchdog/watchdog_dev.c +3 -0
+	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);

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html