]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mm/shrinker: fix name consistency issue in shrinker_debugfs_rename()
authorLiu Ye <liuye@kylinos.cn>
Wed, 5 Mar 2025 07:17:59 +0000 (15:17 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 17 Mar 2025 07:05:40 +0000 (00:05 -0700)
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.

Link: https://lkml.kernel.org/r/20250305071759.661055-1-liuye@kylinos.cn
Signed-off-by: Liu Ye <liuye@kylinos.cn>
Reviewed-by: Muchun Song <muchun.song@linux.dev>
Reviewed-by:Qi Zheng <zhengqi.arch@bytedance.co
Reviewed-by: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/shrinker_debug.c

index 794bd433cce0c6e249c070f42fcd18c64bcd582c..20eaee3e97f7a1bf118b8e2facc8e99d6b002e18 100644 (file)
@@ -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);