mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] watchdog: Fix memleak in watchdog_cdev_register
@ 2020-08-24  2:40 Dinghao Liu
  2020-08-24 13:37 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Dinghao Liu @ 2020-08-24  2:40 UTC (permalink / raw)
  To: dinghao.liu, kjlu
  Cc: Wim Van Sebroeck, Guenter Roeck, linux-watchdog, linux-kernel

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>
---
 drivers/watchdog/watchdog_dev.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

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);
-- 
2.17.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] watchdog: Fix memleak in watchdog_cdev_register
  2020-08-24  2:40 [PATCH] watchdog: Fix memleak in watchdog_cdev_register Dinghao Liu
@ 2020-08-24 13:37 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2020-08-24 13:37 UTC (permalink / raw)
  To: Dinghao Liu; +Cc: kjlu, Wim Van Sebroeck, linux-watchdog, linux-kernel

On Mon, Aug 24, 2020 at 10:40:01AM +0800, Dinghao Liu wrote:
> 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>

> ---
>  drivers/watchdog/watchdog_dev.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> 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);
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-24 13:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-24  2:40 [PATCH] watchdog: Fix memleak in watchdog_cdev_register Dinghao Liu
2020-08-24 13:37 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®