All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers: base: power: fix memory leak with using debugfs_lookup()
@ 2023-02-02 14:15 Greg Kroah-Hartman
  2023-02-02 14:23 ` Rafael J. Wysocki
  2023-02-02 14:45 ` Ulf Hansson
  0 siblings, 2 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2023-02-02 14:15 UTC (permalink / raw)
  To: rafael
  Cc: Greg Kroah-Hartman, Kevin Hilman, Ulf Hansson, Pavel Machek,
	Len Brown, linux-pm, 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: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Kevin Hilman <khilman@kernel.org>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Len Brown <len.brown@intel.com>
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/base/power/domain.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index 967bcf9d415e..6097644ebdc5 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -220,13 +220,10 @@ static void genpd_debug_add(struct generic_pm_domain *genpd);
 
 static void genpd_debug_remove(struct generic_pm_domain *genpd)
 {
-	struct dentry *d;
-
 	if (!genpd_debugfs_dir)
 		return;
 
-	d = debugfs_lookup(genpd->name, genpd_debugfs_dir);
-	debugfs_remove(d);
+	debugfs_lookup_and_remove(genpd->name, genpd_debugfs_dir);
 }
 
 static void genpd_update_accounting(struct generic_pm_domain *genpd)
-- 
2.39.1


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

* Re: [PATCH] drivers: base: power: fix memory leak with using debugfs_lookup()
  2023-02-02 14:15 [PATCH] drivers: base: power: fix memory leak with using debugfs_lookup() Greg Kroah-Hartman
@ 2023-02-02 14:23 ` Rafael J. Wysocki
  2023-02-02 15:09   ` Greg Kroah-Hartman
  2023-02-02 14:45 ` Ulf Hansson
  1 sibling, 1 reply; 5+ messages in thread
From: Rafael J. Wysocki @ 2023-02-02 14:23 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: rafael, Kevin Hilman, Ulf Hansson, Pavel Machek, Len Brown,
	linux-pm, linux-kernel

On Thu, Feb 2, 2023 at 3:15 PM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> 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: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Kevin Hilman <khilman@kernel.org>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: Pavel Machek <pavel@ucw.cz>
> Cc: Len Brown <len.brown@intel.com>
> Cc: linux-pm@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>  drivers/base/power/domain.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> index 967bcf9d415e..6097644ebdc5 100644
> --- a/drivers/base/power/domain.c
> +++ b/drivers/base/power/domain.c
> @@ -220,13 +220,10 @@ static void genpd_debug_add(struct generic_pm_domain *genpd);
>
>  static void genpd_debug_remove(struct generic_pm_domain *genpd)
>  {
> -       struct dentry *d;
> -
>         if (!genpd_debugfs_dir)
>                 return;
>
> -       d = debugfs_lookup(genpd->name, genpd_debugfs_dir);
> -       debugfs_remove(d);
> +       debugfs_lookup_and_remove(genpd->name, genpd_debugfs_dir);
>  }
>
>  static void genpd_update_accounting(struct generic_pm_domain *genpd)
> --

Does this depend on anything in your tree, or can I apply it?

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

* Re: [PATCH] drivers: base: power: fix memory leak with using debugfs_lookup()
  2023-02-02 14:15 [PATCH] drivers: base: power: fix memory leak with using debugfs_lookup() Greg Kroah-Hartman
  2023-02-02 14:23 ` Rafael J. Wysocki
@ 2023-02-02 14:45 ` Ulf Hansson
  1 sibling, 0 replies; 5+ messages in thread
From: Ulf Hansson @ 2023-02-02 14:45 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: rafael, Kevin Hilman, Pavel Machek, Len Brown, linux-pm, linux-kernel

On Thu, 2 Feb 2023 at 15:15, Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> 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: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Kevin Hilman <khilman@kernel.org>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: Pavel Machek <pavel@ucw.cz>
> Cc: Len Brown <len.brown@intel.com>
> Cc: linux-pm@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>

Kind regards
Uffe

> ---
>  drivers/base/power/domain.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> index 967bcf9d415e..6097644ebdc5 100644
> --- a/drivers/base/power/domain.c
> +++ b/drivers/base/power/domain.c
> @@ -220,13 +220,10 @@ static void genpd_debug_add(struct generic_pm_domain *genpd);
>
>  static void genpd_debug_remove(struct generic_pm_domain *genpd)
>  {
> -       struct dentry *d;
> -
>         if (!genpd_debugfs_dir)
>                 return;
>
> -       d = debugfs_lookup(genpd->name, genpd_debugfs_dir);
> -       debugfs_remove(d);
> +       debugfs_lookup_and_remove(genpd->name, genpd_debugfs_dir);
>  }
>
>  static void genpd_update_accounting(struct generic_pm_domain *genpd)
> --
> 2.39.1
>

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

* Re: [PATCH] drivers: base: power: fix memory leak with using debugfs_lookup()
  2023-02-02 14:23 ` Rafael J. Wysocki
@ 2023-02-02 15:09   ` Greg Kroah-Hartman
  2023-02-09 19:34     ` Rafael J. Wysocki
  0 siblings, 1 reply; 5+ messages in thread
From: Greg Kroah-Hartman @ 2023-02-02 15:09 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Kevin Hilman, Ulf Hansson, Pavel Machek, Len Brown, linux-pm,
	linux-kernel

On Thu, Feb 02, 2023 at 03:23:46PM +0100, Rafael J. Wysocki wrote:
> On Thu, Feb 2, 2023 at 3:15 PM Greg Kroah-Hartman
> <gregkh@linuxfoundation.org> wrote:
> >
> > 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: "Rafael J. Wysocki" <rafael@kernel.org>
> > Cc: Kevin Hilman <khilman@kernel.org>
> > Cc: Ulf Hansson <ulf.hansson@linaro.org>
> > Cc: Pavel Machek <pavel@ucw.cz>
> > Cc: Len Brown <len.brown@intel.com>
> > Cc: linux-pm@vger.kernel.org
> > Cc: linux-kernel@vger.kernel.org
> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > ---
> >  drivers/base/power/domain.c | 5 +----
> >  1 file changed, 1 insertion(+), 4 deletions(-)
> >
> > diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> > index 967bcf9d415e..6097644ebdc5 100644
> > --- a/drivers/base/power/domain.c
> > +++ b/drivers/base/power/domain.c
> > @@ -220,13 +220,10 @@ static void genpd_debug_add(struct generic_pm_domain *genpd);
> >
> >  static void genpd_debug_remove(struct generic_pm_domain *genpd)
> >  {
> > -       struct dentry *d;
> > -
> >         if (!genpd_debugfs_dir)
> >                 return;
> >
> > -       d = debugfs_lookup(genpd->name, genpd_debugfs_dir);
> > -       debugfs_remove(d);
> > +       debugfs_lookup_and_remove(genpd->name, genpd_debugfs_dir);
> >  }
> >
> >  static void genpd_update_accounting(struct generic_pm_domain *genpd)
> > --
> 
> Does this depend on anything in your tree, or can I apply it?

It does not depend on anything in any of my trees, it's made against
Linus's tree right now so please take it through yours.

thanks!

greg k-h

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

* Re: [PATCH] drivers: base: power: fix memory leak with using debugfs_lookup()
  2023-02-02 15:09   ` Greg Kroah-Hartman
@ 2023-02-09 19:34     ` Rafael J. Wysocki
  0 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2023-02-09 19:34 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Rafael J. Wysocki, Kevin Hilman, Ulf Hansson, Pavel Machek,
	Len Brown, linux-pm, linux-kernel

On Thu, Feb 2, 2023 at 4:09 PM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> On Thu, Feb 02, 2023 at 03:23:46PM +0100, Rafael J. Wysocki wrote:
> > On Thu, Feb 2, 2023 at 3:15 PM Greg Kroah-Hartman
> > <gregkh@linuxfoundation.org> wrote:
> > >
> > > 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: "Rafael J. Wysocki" <rafael@kernel.org>
> > > Cc: Kevin Hilman <khilman@kernel.org>
> > > Cc: Ulf Hansson <ulf.hansson@linaro.org>
> > > Cc: Pavel Machek <pavel@ucw.cz>
> > > Cc: Len Brown <len.brown@intel.com>
> > > Cc: linux-pm@vger.kernel.org
> > > Cc: linux-kernel@vger.kernel.org
> > > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > > ---
> > >  drivers/base/power/domain.c | 5 +----
> > >  1 file changed, 1 insertion(+), 4 deletions(-)
> > >
> > > diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> > > index 967bcf9d415e..6097644ebdc5 100644
> > > --- a/drivers/base/power/domain.c
> > > +++ b/drivers/base/power/domain.c
> > > @@ -220,13 +220,10 @@ static void genpd_debug_add(struct generic_pm_domain *genpd);
> > >
> > >  static void genpd_debug_remove(struct generic_pm_domain *genpd)
> > >  {
> > > -       struct dentry *d;
> > > -
> > >         if (!genpd_debugfs_dir)
> > >                 return;
> > >
> > > -       d = debugfs_lookup(genpd->name, genpd_debugfs_dir);
> > > -       debugfs_remove(d);
> > > +       debugfs_lookup_and_remove(genpd->name, genpd_debugfs_dir);
> > >  }
> > >
> > >  static void genpd_update_accounting(struct generic_pm_domain *genpd)
> > > --
> >
> > Does this depend on anything in your tree, or can I apply it?
>
> It does not depend on anything in any of my trees, it's made against
> Linus's tree right now so please take it through yours.

Applied for 6.3 now, thanks!

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

end of thread, other threads:[~2023-02-09 19:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-02 14:15 [PATCH] drivers: base: power: fix memory leak with using debugfs_lookup() Greg Kroah-Hartman
2023-02-02 14:23 ` Rafael J. Wysocki
2023-02-02 15:09   ` Greg Kroah-Hartman
2023-02-09 19:34     ` Rafael J. Wysocki
2023-02-02 14:45 ` Ulf Hansson

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.