diff mbox series

[v2] ext4: Fix incorrect group count in ext4_fill_super error message

Message ID 28c22b1845796e52b5fe2832432e859af023ee1b.1585438486.git.josh@joshtriplett.org
State Rejected
Headers show
Series [v2] ext4: Fix incorrect group count in ext4_fill_super error message | expand

Commit Message

Josh Triplett March 28, 2020, 11:43 p.m. UTC
ext4_fill_super doublechecks the number of groups before mounting; if
that check fails, the resulting error message prints the group count
from the ext4_sb_info sbi, which hasn't been set yet. Move the
assignment to sbi->s_groups_count above its use in the error message.

Signed-off-by: Josh Triplett <josh@joshtriplett.org>
Fixes: 4ec1102813798 ("ext4: Add sanity checks for the superblock before mounting the filesystem")
---
v2: Rather than using the computed group count value in blocks_count,
move the assignment to sbi->s_groups_count up and keep using that. That
makes the code, and the patch, simpler to read and understand.

 fs/ext4/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andreas Dilger March 29, 2020, 12:11 a.m. UTC | #1
> On Mar 28, 2020, at 5:43 PM, Josh Triplett <josh@joshtriplett.org> wrote:
> 
> ext4_fill_super doublechecks the number of groups before mounting; if
> that check fails, the resulting error message prints the group count
> from the ext4_sb_info sbi, which hasn't been set yet. Move the
> assignment to sbi->s_groups_count above its use in the error message.
> 
> Signed-off-by: Josh Triplett <josh@joshtriplett.org>
> Fixes: 4ec1102813798 ("ext4: Add sanity checks for the superblock before mounting the filesystem")

Much better, thanks.

Reviewed-by: Andreas Dilger <adilger@dilger.ca>

> ---
> v2: Rather than using the computed group count value in blocks_count,
> move the assignment to sbi->s_groups_count up and keep using that. That
> makes the code, and the patch, simpler to read and understand.
> 
> fs/ext4/super.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 0c7c4adb664e..6692bc48520a 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -4285,6 +4285,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
> 			le32_to_cpu(es->s_first_data_block) +
> 			EXT4_BLOCKS_PER_GROUP(sb) - 1);
> 	do_div(blocks_count, EXT4_BLOCKS_PER_GROUP(sb));
> +	sbi->s_groups_count = blocks_count;
> 	if (blocks_count > ((uint64_t)1<<32) - EXT4_DESC_PER_BLOCK(sb)) {
> 		ext4_msg(sb, KERN_WARNING, "groups count too large: %u "
> 		       "(block count %llu, first data block %u, "
> @@ -4294,7 +4295,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
> 		       EXT4_BLOCKS_PER_GROUP(sb));
> 		goto failed_mount;
> 	}
> -	sbi->s_groups_count = blocks_count;
> 	sbi->s_blockfile_groups = min_t(ext4_group_t, sbi->s_groups_count,
> 			(EXT4_MAX_BLOCK_FILE_PHYS / EXT4_BLOCKS_PER_GROUP(sb)));
> 	if (((u64)sbi->s_groups_count * sbi->s_inodes_per_group) !=
> --
> 2.26.0
> 


Cheers, Andreas
diff mbox series

Patch

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 0c7c4adb664e..6692bc48520a 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -4285,6 +4285,7 @@  static int ext4_fill_super(struct super_block *sb, void *data, int silent)
 			le32_to_cpu(es->s_first_data_block) +
 			EXT4_BLOCKS_PER_GROUP(sb) - 1);
 	do_div(blocks_count, EXT4_BLOCKS_PER_GROUP(sb));
+	sbi->s_groups_count = blocks_count;
 	if (blocks_count > ((uint64_t)1<<32) - EXT4_DESC_PER_BLOCK(sb)) {
 		ext4_msg(sb, KERN_WARNING, "groups count too large: %u "
 		       "(block count %llu, first data block %u, "
@@ -4294,7 +4295,6 @@  static int ext4_fill_super(struct super_block *sb, void *data, int silent)
 		       EXT4_BLOCKS_PER_GROUP(sb));
 		goto failed_mount;
 	}
-	sbi->s_groups_count = blocks_count;
 	sbi->s_blockfile_groups = min_t(ext4_group_t, sbi->s_groups_count,
 			(EXT4_MAX_BLOCK_FILE_PHYS / EXT4_BLOCKS_PER_GROUP(sb)));
 	if (((u64)sbi->s_groups_count * sbi->s_inodes_per_group) !=