2018-03-01 11:33:43

by Arvind Yadav

[permalink] [raw]
Subject: [PATCH v3] net: iucv: Free memory obtained by kzalloc

Free memory by calling put_device(), if afiucv_iucv_init is not
successful.

Signed-off-by: Arvind Yadav <[email protected]>
---
changes in v2:
Calling put_device() before kfree().
changes in v3:
No need to call kfree(). So removed kfree().

net/iucv/af_iucv.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
index 1e8cc7b..9e2643a 100644
--- a/net/iucv/af_iucv.c
+++ b/net/iucv/af_iucv.c
@@ -2433,9 +2433,11 @@ static int afiucv_iucv_init(void)
af_iucv_dev->driver = &af_iucv_driver;
err = device_register(af_iucv_dev);
if (err)
- goto out_driver;
+ goto out_iucv_dev;
return 0;

+out_iucv_dev:
+ put_device(af_iucv_dev);
out_driver:
driver_unregister(&af_iucv_driver);
out_iucv:
--
1.9.1



2018-03-01 12:51:41

by Cornelia Huck

[permalink] [raw]
Subject: Re: [PATCH v3] net: iucv: Free memory obtained by kzalloc

On Thu, 1 Mar 2018 17:01:57 +0530
Arvind Yadav <[email protected]> wrote:

> Free memory by calling put_device(), if afiucv_iucv_init is not
> successful.
>
> Signed-off-by: Arvind Yadav <[email protected]>
> ---
> changes in v2:
> Calling put_device() before kfree().
> changes in v3:
> No need to call kfree(). So removed kfree().
>
> net/iucv/af_iucv.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
> index 1e8cc7b..9e2643a 100644
> --- a/net/iucv/af_iucv.c
> +++ b/net/iucv/af_iucv.c
> @@ -2433,9 +2433,11 @@ static int afiucv_iucv_init(void)
> af_iucv_dev->driver = &af_iucv_driver;
> err = device_register(af_iucv_dev);
> if (err)
> - goto out_driver;
> + goto out_iucv_dev;
> return 0;
>
> +out_iucv_dev:
> + put_device(af_iucv_dev);
> out_driver:
> driver_unregister(&af_iucv_driver);
> out_iucv:

Reviewed-by: Cornelia Huck <[email protected]>

2018-03-01 16:20:11

by Ursula Braun

[permalink] [raw]
Subject: Re: [PATCH v3] net: iucv: Free memory obtained by kzalloc



On 03/01/2018 12:31 PM, Arvind Yadav wrote:
> Free memory by calling put_device(), if afiucv_iucv_init is not
> successful.
>
> Signed-off-by: Arvind Yadav <[email protected]>
> ---
> changes in v2:
> Calling put_device() before kfree().
> changes in v3:
> No need to call kfree(). So removed kfree().
>
> net/iucv/af_iucv.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
> index 1e8cc7b..9e2643a 100644
> --- a/net/iucv/af_iucv.c
> +++ b/net/iucv/af_iucv.c
> @@ -2433,9 +2433,11 @@ static int afiucv_iucv_init(void)
> af_iucv_dev->driver = &af_iucv_driver;
> err = device_register(af_iucv_dev);
> if (err)
> - goto out_driver;
> + goto out_iucv_dev;
> return 0;
>
> +out_iucv_dev:
> + put_device(af_iucv_dev);
> out_driver:
> driver_unregister(&af_iucv_driver);
> out_iucv:
>

Thanks Arvind, I have added this patch version to our local repository; it will be part of a
coming patch submission to Dave Miller.

Regards, Ursula