2014-07-25 04:55:57

by Chao Yu

[permalink] [raw]
Subject: [f2fs-dev][PATCH 2/2] f2fs: fix to put root inode in error path of fill_super

We should put root inode correctly in error path of fill_super, otherwise we
may encounter a leak case of inode resource.

Signed-off-by: Chao Yu <[email protected]>
---
fs/f2fs/super.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 870fe19..34649aa 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -1033,8 +1033,9 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
goto free_node_inode;
}
if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
+ iput(root);
err = -EINVAL;
- goto free_root_inode;
+ goto free_node_inode;
}

sb->s_root = d_make_root(root); /* allocate root dentry */
--
2.0.1.474.g72c7794


2014-07-25 06:11:11

by Gu Zheng

[permalink] [raw]
Subject: Re: [f2fs-dev][PATCH 2/2] f2fs: fix to put root inode in error path of fill_super

On 07/25/2014 12:55 PM, Chao Yu wrote:

> We should put root inode correctly in error path of fill_super, otherwise we
> may encounter a leak case of inode resource.

Good catch, and it also fixed the incorrect 'goto'.

>
> Signed-off-by: Chao Yu <[email protected]>

Reviewed-by: Gu Zheng <[email protected]>

> ---
> fs/f2fs/super.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> index 870fe19..34649aa 100644
> --- a/fs/f2fs/super.c
> +++ b/fs/f2fs/super.c
> @@ -1033,8 +1033,9 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
> goto free_node_inode;
> }
> if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
> + iput(root);
> err = -EINVAL;
> - goto free_root_inode;
> + goto free_node_inode;
> }
>
> sb->s_root = d_make_root(root); /* allocate root dentry */