Commit 07aa2ea1 authored by Lukas Czerner's avatar Lukas Czerner Committed by Theodore Ts'o

ext4: fix error handling in ext4_fill_super()

There are some places in ext4_fill_super() where we would not return
proper error code if something fails. The confusion is caused probably
due to the fact that we have two "kind-of" return variables 'ret'and
'err'.

'ret' is used to return error code from ext4_fill_super() where err is
used to store return values from other functions within ext4_fill_super().
However some places were missing the obligatory 'ret = err'. We could
put the assignment where it is missing, but we can have better "future
proof" solution. Or we could convert the code to use just one, but it
would require more rewrites.

This commit fixes the problem by returning value from 'err' variable if
it is set and 'ret' otherwise in error handling branch of the
ext4_fill_super(). The reasoning is that 'ret' value is often set to
default "-EINVAL" or explicit value, where 'err' is used to store
return value from other functions and should be otherwise zero.

https://bugzilla.kernel.org/show_bug.cgi?id=48431Signed-off-by: default avatarLukas Czerner <lczerner@redhat.com>
Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
parent 24ec19b0
......@@ -3256,7 +3256,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
unsigned int i;
int needs_recovery, has_huge_files, has_bigalloc;
__u64 blocks_count;
int err;
int err = 0;
unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
ext4_group_t first_not_zeroed;
......@@ -3282,6 +3282,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
for (cp = sb->s_id; (cp = strchr(cp, '/'));)
*cp = '!';
/* -EINVAL is default */
ret = -EINVAL;
blocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE);
if (!blocksize) {
......@@ -3659,7 +3660,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
" too large to mount safely on this system");
if (sizeof(sector_t) < 8)
ext4_msg(sb, KERN_WARNING, "CONFIG_LBDAF not enabled");
ret = err;
goto failed_mount;
}
......@@ -3767,7 +3767,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
}
if (err) {
ext4_msg(sb, KERN_ERR, "insufficient memory");
ret = err;
goto failed_mount3;
}
......@@ -3894,8 +3893,8 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
if (es->s_overhead_clusters)
sbi->s_overhead = le32_to_cpu(es->s_overhead_clusters);
else {
ret = ext4_calculate_overhead(sb);
if (ret)
err = ext4_calculate_overhead(sb);
if (err)
goto failed_mount_wq;
}
......@@ -3907,6 +3906,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
alloc_workqueue("ext4-dio-unwritten", WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
if (!EXT4_SB(sb)->dio_unwritten_wq) {
printk(KERN_ERR "EXT4-fs: failed to create DIO workqueue\n");
ret = -ENOMEM;
goto failed_mount_wq;
}
......@@ -4009,8 +4009,8 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
/* Enable quota usage during mount. */
if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_QUOTA) &&
!(sb->s_flags & MS_RDONLY)) {
ret = ext4_enable_quotas(sb);
if (ret)
err = ext4_enable_quotas(sb);
if (err)
goto failed_mount7;
}
#endif /* CONFIG_QUOTA */
......@@ -4089,7 +4089,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
kfree(sbi);
out_free_orig:
kfree(orig_data);
return ret;
return err ? err : ret;
}
/*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment