[PATCH v2] mm/shrinker: fix name consistency issue in shrinker_debugfs_rename()

Liu Ye posted 1 patch 11 months, 1 week ago
mm/shrinker_debug.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
[PATCH v2] mm/shrinker: fix name consistency issue in shrinker_debugfs_rename()
Posted by Liu Ye 11 months, 1 week ago
After calling debugfs_change_name function, the return value should be
checked and the old name restored. If debugfs_change_name fails, the new
name memory should be freed. The effect is that the shrinker->name is not
consistent with the name displayed in debugfs.

Signed-off-by: Liu Ye <liuye@kylinos.cn>
Reviewed-by: Muchun Song <muchun.song@linux.dev>
Reviewed-by:Qi Zheng <zhengqi.arch@bytedance.com>

---
V2: Modify the subject add Reviewed-by.
---
---
 mm/shrinker_debug.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/mm/shrinker_debug.c b/mm/shrinker_debug.c
index 794bd433cce0..20eaee3e97f7 100644
--- a/mm/shrinker_debug.c
+++ b/mm/shrinker_debug.c
@@ -214,10 +214,14 @@ int shrinker_debugfs_rename(struct shrinker *shrinker, const char *fmt, ...)
 	ret = debugfs_change_name(shrinker->debugfs_entry, "%s-%d",
 			shrinker->name, shrinker->debugfs_id);
 
+	if (ret) {
+		shrinker->name = old;
+		kfree_const(new);
+	} else {
+		kfree_const(old);
+	}
 	mutex_unlock(&shrinker_mutex);
 
-	kfree_const(old);
-
 	return ret;
 }
 EXPORT_SYMBOL(shrinker_debugfs_rename);
-- 
2.25.1

Re: [PATCH v2] mm/shrinker: fix name consistency issue in shrinker_debugfs_rename()
Posted by Roman Gushchin 11 months, 1 week ago
On Wed, Mar 05, 2025 at 03:17:59PM +0800, Liu Ye wrote:
> After calling debugfs_change_name function, the return value should be
> checked and the old name restored. If debugfs_change_name fails, the new
> name memory should be freed. The effect is that the shrinker->name is not
> consistent with the name displayed in debugfs.
> 
> Signed-off-by: Liu Ye <liuye@kylinos.cn>
> Reviewed-by: Muchun Song <muchun.song@linux.dev>
> Reviewed-by:Qi Zheng <zhengqi.arch@bytedance.com>

Reviewed-by: Roman Gushchin <roman.gushchin@linux.dev>

Thanks!