Re: [PATCH] drivers: base: power: fix memory leak with using debugfs_lookup()

From: Rafael J. Wysocki
Date: Thu Feb 09 2023 - 14:34:50 EST


On Thu, Feb 2, 2023 at 4:09 PM Greg Kroah-Hartman
<gregkh@xxxxxxxxxxxxxxxxxxx> 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@xxxxxxxxxxxxxxxxxxx> 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@xxxxxxxxxx>
> > > Cc: Kevin Hilman <khilman@xxxxxxxxxx>
> > > Cc: Ulf Hansson <ulf.hansson@xxxxxxxxxx>
> > > Cc: Pavel Machek <pavel@xxxxxx>
> > > Cc: Len Brown <len.brown@xxxxxxxxx>
> > > Cc: linux-pm@xxxxxxxxxxxxxxx
> > > Cc: linux-kernel@xxxxxxxxxxxxxxx
> > > Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> > > ---
> > > 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!