Skip to contentSkip to conversation

HV: hv_balloon: fix memory leak with using debugfs_lookup()

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

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HV: hv_balloon: 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.

---
 drivers/hv/hv_balloon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hv/hv_balloon.c +1 -1
index cbe43e2567a7..64ac5bdee3a6 100644
@@ -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
Signature · 1 line
2.39.1
Reviewed-by on v1 1/1
#1 lore raw

From: Greg Kroah-Hartman <[email protected]> Sent: Thursday, February 2, 2023 6:09 AM

Quoted 6 lines

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 7 lines

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")
Quoted 9 lines
---
 drivers/hv/hv_balloon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hv/hv_balloon.c +0 -0
index cbe43e2567a7..64ac5bdee3a6 100644

drivers/hv/hv_balloon.c static void hv_balloon_debugfs_init(struct hv_dynmem_device *b) · line 1969

Quoted 8 lines
drivers/hv/hv_balloon.c +1 -1
@@ -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 lore raw
Quoted 16 lines · Michael Kelley (LINUX)

From: Greg Kroah-Hartman <[email protected]> Sent: Thursday, February 2, 2023 6:09 AM

Quoted 6 lines

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 7 lines
Quoted 4 lines

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