Skip to contentSkip to conversation

drivers: base: power: fix memory leak with using debugfs_lookup()

PATCH In review Greg Kroah-Hartman 3 participants 5 messages Feb 2, 2023 – Feb 9, 2023

Subsystems (4)
lore
Share & tools
lore

Greg Kroah-Hartman

author maintainer
#0 lore raw

PATCH 1/1 drivers: base: power: fix memory leak with using debugfs_lookup()

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" <[email protected]>
Cc Kevin Hilman <[email protected]>
Cc Ulf Hansson <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Len Brown <[email protected]>
---
 drivers/base/power/domain.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/base/power/domain.c +1 -4
index 967bcf9d415e..6097644ebdc5 100644
@@ -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)
Signature · 1 line
2.39.1
#1 lore raw
Quoted 29 lines · Greg Kroah-Hartman

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" <[email protected]>
Cc Kevin Hilman <[email protected]>
Cc Ulf Hansson <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Len Brown <[email protected]>
---
 drivers/base/power/domain.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/base/power/domain.c +0 -2
index 967bcf9d415e..6097644ebdc5 100644
@@ -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;
-

drivers/base/power/domain.c static void genpd_debug_add(struct generic_pm_domain *genpd);

Quoted 10 lines
drivers/base/power/domain.c +1 -3
        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?

author maintainer
#2 lore raw
Quoted 39 lines · Rafael J. Wysocki
Quoted 37 lines · Greg Kroah-Hartman

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" <[email protected]>
Cc Kevin Hilman <[email protected]>
Cc Ulf Hansson <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Len Brown <[email protected]>
---
 drivers/base/power/domain.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/base/power/domain.c +1 -4
index 967bcf9d415e..6097644ebdc5 100644
@@ -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);
 }
 
Quoted 4 lines

drivers/base/power/domain.c static void genpd_debug_add(struct generic_pm_domain *genpd);

Quoted 2 lines
drivers/base/power/domain.c +0 -1
 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

#3 lore raw
Quoted 41 lines · Greg Kroah-Hartman
Quoted 39 lines · Rafael J. Wysocki
Quoted 37 lines · Greg Kroah-Hartman

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" <[email protected]>
Cc Kevin Hilman <[email protected]>
Cc Ulf Hansson <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Len Brown <[email protected]>
---
 drivers/base/power/domain.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/base/power/domain.c +1 -4
index 967bcf9d415e..6097644ebdc5 100644
@@ -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);
 }
 
Quoted 7 lines
Quoted 4 lines

drivers/base/power/domain.c static void genpd_debug_add(struct generic_pm_domain *genpd);

Quoted 2 lines
drivers/base/power/domain.c +0 -1
 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!

Reviewed-by on v1 1/1
#4 lore raw
In reply to Greg Kroah-Hartman
Quoted 7 lines · Greg Kroah-Hartman

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.

Quoted 8 lines
Cc "Rafael J. Wysocki" <[email protected]>
Cc Kevin Hilman <[email protected]>
Cc Ulf Hansson <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Len Brown <[email protected]>

Kind regards
Uffe

Quoted 26 lines
---
 drivers/base/power/domain.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/base/power/domain.c +1 -5
index 967bcf9d415e..6097644ebdc5 100644
@@ -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