Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.

Commit 75c5a52

Browse files
jankaratorvalds
authored andcommitted
vfs: Allocate anon_inode_inode in anon_inode_init()
Currently we allocated anon_inode_inode in anon_inodefs_mount. This is somewhat fragile as if that function ever gets called again, it will overwrite anon_inode_inode pointer. So move the initialization of anon_inode_inode to anon_inode_init(). Signed-off-by: Jan Kara <[email protected]> [ Further simplified on suggestion from Dave Jones ] Signed-off-by: Linus Torvalds <[email protected]>
1 parent f217c44 commit 75c5a52

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

fs/anon_inodes.c

+8-22
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,8 @@ static const struct dentry_operations anon_inodefs_dentry_operations = {
4141
static struct dentry *anon_inodefs_mount(struct file_system_type *fs_type,
4242
int flags, const char *dev_name, void *data)
4343
{
44-
struct dentry *root;
45-
root = mount_pseudo(fs_type, "anon_inode:", NULL,
44+
return mount_pseudo(fs_type, "anon_inode:", NULL,
4645
&anon_inodefs_dentry_operations, ANON_INODE_FS_MAGIC);
47-
if (!IS_ERR(root)) {
48-
struct super_block *s = root->d_sb;
49-
anon_inode_inode = alloc_anon_inode(s);
50-
if (IS_ERR(anon_inode_inode)) {
51-
dput(root);
52-
deactivate_locked_super(s);
53-
root = ERR_CAST(anon_inode_inode);
54-
}
55-
}
56-
return root;
5746
}
5847

5948
static struct file_system_type anon_inode_fs_type = {
@@ -175,18 +164,15 @@ EXPORT_SYMBOL_GPL(anon_inode_getfd);
175164

176165
static int __init anon_inode_init(void)
177166
{
178-
int error;
179-
180167
anon_inode_mnt = kern_mount(&anon_inode_fs_type);
181-
if (IS_ERR(anon_inode_mnt)) {
182-
error = PTR_ERR(anon_inode_mnt);
183-
goto err_unregister_filesystem;
184-
}
185-
return 0;
168+
if (IS_ERR(anon_inode_mnt))
169+
panic("anon_inode_init() kernel mount failed (%ld)\n", PTR_ERR(anon_inode_mnt));
186170

187-
err_unregister_filesystem:
188-
unregister_filesystem(&anon_inode_fs_type);
189-
panic(KERN_ERR "anon_inode_init() failed (%d)\n", error);
171+
anon_inode_inode = alloc_anon_inode(anon_inode_mnt->mnt_sb);
172+
if (IS_ERR(anon_inode_inode))
173+
panic("anon_inode_init() inode allocation failed (%ld)\n", PTR_ERR(anon_inode_inode));
174+
175+
return 0;
190176
}
191177

192178
fs_initcall(anon_inode_init);

0 commit comments

Comments
 (0)