Skip to content

Commit

Permalink
ext4: avoid dividing by 0 in mb_update_avg_fragment_size() when block…
Browse files Browse the repository at this point in the history
… bitmap corrupt

[ Upstream commit 993bf0f ]

Determine if bb_fragments is 0 instead of determining bb_free to eliminate
the risk of dividing by zero when the block bitmap is corrupted.

Signed-off-by: Baokun Li <libaokun1@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20240104142040.2835097-6-libaokun1@huawei.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Baokun Li authored and gregkh committed Mar 1, 2024
1 parent 720751b commit f32d2a7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion fs/ext4/mballoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ mb_update_avg_fragment_size(struct super_block *sb, struct ext4_group_info *grp)
struct ext4_sb_info *sbi = EXT4_SB(sb);
int new_order;

if (!test_opt2(sb, MB_OPTIMIZE_SCAN) || grp->bb_free == 0)
if (!test_opt2(sb, MB_OPTIMIZE_SCAN) || grp->bb_fragments == 0)
return;

new_order = mb_avg_fragment_size_order(sb,
Expand Down

0 comments on commit f32d2a7

Please sign in to comment.