All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] HV: hv_balloon: fix memory leak with using debugfs_lookup()
@ 2023-02-02 14:09 Greg Kroah-Hartman
  2023-02-03  3:56 ` Michael Kelley (LINUX)
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2023-02-02 14:09 UTC (permalink / raw)
  To: linux-hyperv
  Cc: Greg Kroah-Hartman, K. Y. Srinivasan, Haiyang Zhang, Wei Liu,
	Dexuan Cui, linux-kernel

When calling debugfs_lookup() the result must have dput() called on it,
otherwise the memory will leak over time.  To make things simpler, just
call debugfs_lookup_and_remove() instead which handles all of the logic
at once.

Cc: "K. Y. Srinivasan" <kys@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Wei Liu <wei.liu@kernel.org>
Cc: Dexuan Cui <decui@microsoft.com>
Cc: linux-hyperv@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/hv/hv_balloon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
index cbe43e2567a7..64ac5bdee3a6 100644
--- a/drivers/hv/hv_balloon.c
+++ b/drivers/hv/hv_balloon.c
@@ -1963,7 +1963,7 @@ static void  hv_balloon_debugfs_init(struct hv_dynmem_device *b)
 
 static void  hv_balloon_debugfs_exit(struct hv_dynmem_device *b)
 {
-	debugfs_remove(debugfs_lookup("hv-balloon", NULL));
+	debugfs_lookup_and_remove("hv-balloon", NULL);
 }
 
 #else
-- 
2.39.1


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

* RE: [PATCH] HV: hv_balloon: fix memory leak with using debugfs_lookup()
  2023-02-02 14:09 [PATCH] HV: hv_balloon: fix memory leak with using debugfs_lookup() Greg Kroah-Hartman
@ 2023-02-03  3:56 ` Michael Kelley (LINUX)
  2023-02-03  6:44   ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Kelley (LINUX) @ 2023-02-03  3:56 UTC (permalink / raw)
  To: Greg Kroah-Hartman, linux-hyperv
  Cc: KY Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, linux-kernel

From: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Sent: Thursday, February 2, 2023 6:09 AM

> 
> When calling debugfs_lookup() the result must have dput() called on it,
> otherwise the memory will leak over time.  To make things simpler, just
> call debugfs_lookup_and_remove() instead which handles all of the logic
> at once.
> 
> Cc: "K. Y. Srinivasan" <kys@microsoft.com>
> Cc: Haiyang Zhang <haiyangz@microsoft.com>
> Cc: Wei Liu <wei.liu@kernel.org>
> Cc: Dexuan Cui <decui@microsoft.com>
> Cc: linux-hyperv@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Add a Fixes: tag?  This hv_balloon debugfs code was added in v6.0,
And I see that debugfs_lookup_and_remove() was also added in v6.0.

Fixes: d180e0a1be6c ("Drivers: hv: Create debugfs file with hyper-v balloon usage information")

> ---
>  drivers/hv/hv_balloon.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
> index cbe43e2567a7..64ac5bdee3a6 100644
> --- a/drivers/hv/hv_balloon.c
> +++ b/drivers/hv/hv_balloon.c
> @@ -1963,7 +1963,7 @@ static void  hv_balloon_debugfs_init(struct hv_dynmem_device *b)
> 
>  static void  hv_balloon_debugfs_exit(struct hv_dynmem_device *b)
>  {
> -	debugfs_remove(debugfs_lookup("hv-balloon", NULL));
> +	debugfs_lookup_and_remove("hv-balloon", NULL);
>  }
> 
>  #else

Reviewed-by: Michael Kelley <mikelley@microsoft.com>

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

* Re: [PATCH] HV: hv_balloon: fix memory leak with using debugfs_lookup()
  2023-02-03  3:56 ` Michael Kelley (LINUX)
@ 2023-02-03  6:44   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2023-02-03  6:44 UTC (permalink / raw)
  To: Michael Kelley (LINUX)
  Cc: linux-hyperv, KY Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui,
	linux-kernel

On Fri, Feb 03, 2023 at 03:56:06AM +0000, Michael Kelley (LINUX) wrote:
> From: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Sent: Thursday, February 2, 2023 6:09 AM
> 
> > 
> > When calling debugfs_lookup() the result must have dput() called on it,
> > otherwise the memory will leak over time.  To make things simpler, just
> > call debugfs_lookup_and_remove() instead which handles all of the logic
> > at once.
> > 
> > Cc: "K. Y. Srinivasan" <kys@microsoft.com>
> > Cc: Haiyang Zhang <haiyangz@microsoft.com>
> > Cc: Wei Liu <wei.liu@kernel.org>
> > Cc: Dexuan Cui <decui@microsoft.com>
> > Cc: linux-hyperv@vger.kernel.org
> > Cc: linux-kernel@vger.kernel.org
> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> 
> Add a Fixes: tag?  This hv_balloon debugfs code was added in v6.0,
> And I see that debugfs_lookup_and_remove() was also added in v6.0.
> 
> Fixes: d180e0a1be6c ("Drivers: hv: Create debugfs file with hyper-v balloon usage information")

Will do, thanks.

greg k-h

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

end of thread, other threads:[~2023-02-03  6:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-02 14:09 [PATCH] HV: hv_balloon: fix memory leak with using debugfs_lookup() Greg Kroah-Hartman
2023-02-03  3:56 ` Michael Kelley (LINUX)
2023-02-03  6:44   ` Greg Kroah-Hartman

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.