Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

shmem: use ramfs_kill_sb() for kill_sb method of ramfs-based tmpfs

As the ramfs-based tmpfs uses ramfs_init_fs_context() for the
init_fs_context method, which allocates fc->s_fs_info, use ramfs_kill_sb()
to free it and avoid a memory leak.

Link: https://lkml.kernel.org/r/20230607161523.2876433-1-roberto.sassu@huaweicloud.com
Fixes: c3b1b1cbf002 ("ramfs: add support for "mode=" mount option")
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Roberto Sassu and committed by
Andrew Morton
36ce9d76 91ff4d75

+3 -2
+1 -1
fs/ramfs/inode.c
··· 278 278 return 0; 279 279 } 280 280 281 - static void ramfs_kill_sb(struct super_block *sb) 281 + void ramfs_kill_sb(struct super_block *sb) 282 282 { 283 283 kfree(sb->s_fs_info); 284 284 kill_litter_super(sb);
+1
include/linux/ramfs.h
··· 7 7 struct inode *ramfs_get_inode(struct super_block *sb, const struct inode *dir, 8 8 umode_t mode, dev_t dev); 9 9 extern int ramfs_init_fs_context(struct fs_context *fc); 10 + extern void ramfs_kill_sb(struct super_block *sb); 10 11 11 12 #ifdef CONFIG_MMU 12 13 static inline int
+1 -1
mm/shmem.c
··· 4199 4199 .name = "tmpfs", 4200 4200 .init_fs_context = ramfs_init_fs_context, 4201 4201 .parameters = ramfs_fs_parameters, 4202 - .kill_sb = kill_litter_super, 4202 + .kill_sb = ramfs_kill_sb, 4203 4203 .fs_flags = FS_USERNS_MOUNT, 4204 4204 }; 4205 4205