diff mbox series

[v2] watchdog: Use put_device on error

Message ID 20200824031230.31050-1-dinghao.liu@zju.edu.cn (mailing list archive)
State Accepted
Headers show
Series [v2] watchdog: Use put_device on error | expand

Commit Message

Dinghao Liu Aug. 24, 2020, 3:12 a.m. UTC
We should use put_device() instead of freeing device
directly after device_initialize().

Fixes: cb36e29bb0e4b ("watchdog: initialize device before misc_register")
Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---

Changelog:

v2: - Use put_device() instead of just removing kfree.
      Move the memleak part to a separate patch.
---
 drivers/watchdog/watchdog_dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Guenter Roeck Aug. 24, 2020, 1:37 p.m. UTC | #1
On Mon, Aug 24, 2020 at 11:12:30AM +0800, Dinghao Liu wrote:
> We should use put_device() instead of freeing device
> directly after device_initialize().
> 
> Fixes: cb36e29bb0e4b ("watchdog: initialize device before misc_register")
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
> 
> Changelog:
> 
> v2: - Use put_device() instead of just removing kfree.
>       Move the memleak part to a separate patch.
> ---
>  drivers/watchdog/watchdog_dev.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
> index 6798addabd5a..b0fa7f31b1b6 100644
> --- a/drivers/watchdog/watchdog_dev.c
> +++ b/drivers/watchdog/watchdog_dev.c
> @@ -1021,7 +1021,7 @@ 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);
> +			put_device(&wd_data->dev);
>  			return err;
>  		}
>  	}
> -- 
> 2.17.1
>
diff mbox series

Patch

diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
index 6798addabd5a..b0fa7f31b1b6 100644
--- a/drivers/watchdog/watchdog_dev.c
+++ b/drivers/watchdog/watchdog_dev.c
@@ -1021,7 +1021,7 @@  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);
+			put_device(&wd_data->dev);
 			return err;
 		}
 	}