All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] parisc: pdc_stable: Fix memory leak in pdcs_register_pathentries
@ 2022-01-20 12:18 Miaoqian Lin
  2022-01-20 17:27 ` Helge Deller
  0 siblings, 1 reply; 2+ messages in thread
From: Miaoqian Lin @ 2022-01-20 12:18 UTC (permalink / raw)
  To: James E.J. Bottomley, Helge Deller, Greg Kroah-Hartman,
	linux-parisc, linux-kernel
  Cc: linmq006

kobject_init_and_add() takes reference even when it fails.
According to the doc of kobject_init_and_add():

   If this function returns an error, kobject_put() must be called to
   properly clean up the memory associated with the object.

Fix memory leak by calling kobject_put().

Fixes: 73f368cf679b ("Kobject: change drivers/parisc/pdc_stable.c to use kobject_init_and_add")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 drivers/parisc/pdc_stable.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
index 9513c39719d1..d9e51036a4fa 100644
--- a/drivers/parisc/pdc_stable.c
+++ b/drivers/parisc/pdc_stable.c
@@ -980,8 +980,10 @@ pdcs_register_pathentries(void)
 		entry->kobj.kset = paths_kset;
 		err = kobject_init_and_add(&entry->kobj, &ktype_pdcspath, NULL,
 					   "%s", entry->name);
-		if (err)
+		if (err) {
+			kobject_put(&entry->kobj);
 			return err;
+		}
 
 		/* kobject is now registered */
 		write_lock(&entry->rw_lock);
-- 
2.17.1


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

* Re: [PATCH] parisc: pdc_stable: Fix memory leak in pdcs_register_pathentries
  2022-01-20 12:18 [PATCH] parisc: pdc_stable: Fix memory leak in pdcs_register_pathentries Miaoqian Lin
@ 2022-01-20 17:27 ` Helge Deller
  0 siblings, 0 replies; 2+ messages in thread
From: Helge Deller @ 2022-01-20 17:27 UTC (permalink / raw)
  To: Miaoqian Lin, James E.J. Bottomley, Greg Kroah-Hartman,
	linux-parisc, linux-kernel

On 1/20/22 13:18, Miaoqian Lin wrote:
> kobject_init_and_add() takes reference even when it fails.
> According to the doc of kobject_init_and_add():
>
>    If this function returns an error, kobject_put() must be called to
>    properly clean up the memory associated with the object.
>
> Fix memory leak by calling kobject_put().
>
> Fixes: 73f368cf679b ("Kobject: change drivers/parisc/pdc_stable.c to use kobject_init_and_add")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>

applied.
Thanks!
Helge


> ---
>  drivers/parisc/pdc_stable.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
> index 9513c39719d1..d9e51036a4fa 100644
> --- a/drivers/parisc/pdc_stable.c
> +++ b/drivers/parisc/pdc_stable.c
> @@ -980,8 +980,10 @@ pdcs_register_pathentries(void)
>  		entry->kobj.kset = paths_kset;
>  		err = kobject_init_and_add(&entry->kobj, &ktype_pdcspath, NULL,
>  					   "%s", entry->name);
> -		if (err)
> +		if (err) {
> +			kobject_put(&entry->kobj);
>  			return err;
> +		}
>
>  		/* kobject is now registered */
>  		write_lock(&entry->rw_lock);
>


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

end of thread, other threads:[~2022-01-20 17:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-20 12:18 [PATCH] parisc: pdc_stable: Fix memory leak in pdcs_register_pathentries Miaoqian Lin
2022-01-20 17:27 ` Helge Deller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.