staging: erofs: fix potential double iput in erofs_read_super()
authorChengguang Xu <cgxu519@gmx.com>
Wed, 23 Jan 2019 06:12:25 +0000 (14:12 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 Jan 2019 08:52:02 +0000 (09:52 +0100)
Some error cases like failing from d_make_root() will
cause double iput because d_make_root() also does iput
in its error path.

Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Reviewed-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/erofs/super.c

index af5140eede18aa0f4ab30f67995f79b809fde2eb..176fca2af379c1d97e88a78516421c0df9b98e99 100644 (file)
@@ -421,13 +421,14 @@ static int erofs_read_super(struct super_block *sb,
                errln("rootino(nid %llu) is not a directory(i_mode %o)",
                        ROOT_NID(sbi), inode->i_mode);
                err = -EINVAL;
-               goto err_isdir;
+               iput(inode);
+               goto err_iget;
        }
 
        sb->s_root = d_make_root(inode);
        if (sb->s_root == NULL) {
                err = -ENOMEM;
-               goto err_makeroot;
+               goto err_iget;
        }
 
        /* save the device name to sbi */
@@ -453,10 +454,6 @@ static int erofs_read_super(struct super_block *sb,
         */
 err_devname:
        dput(sb->s_root);
-err_makeroot:
-err_isdir:
-       if (sb->s_root == NULL)
-               iput(inode);
 err_iget:
 #ifdef EROFS_FS_HAS_MANAGED_CACHE
        iput(sbi->managed_cache);