ext4: silence an uninitialized variable warning
Subsystems (2)
PATCH 1/1 ext4: silence an uninitialized variable warning
Smatch complains that "i" can be uninitialized if we don't enter the loop. I don't know if it's possible but we may as well silence this warning.
--- fs/ext4/mballoc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/mballoc.c +1 -1
@@ -5167,7 +5167,7 @@ static ext4_fsblk_t ext4_mb_new_blocks_simple(handle_t *handle,struct super_block *sb = ar->inode->i_sb;ext4_group_t group;ext4_grpblk_t blkoff; -int i; +int i =0 ;ext4_fsblk_t goal, block;struct ext4_super_block *es =EXT4_SB (sb)->s_es;
Signature · 1 line
2.28.0
Quoted 3 lines · Dan Carpenter
Smatch complains that "i" can be uninitialized if we don't enter the loop. I don't know if it's possible but we may as well silence this warning.
Thanks, applied.
I changed the patch so that i gets initialized to sb->s_blocksize instead of 0. The only way the for loop could be skipped entirely, leaving i initialized, is if the in-memory data structures, in particular the bh->b_data for the on-disk superblock has gotten corrupted enough that calculated value of group is >= to ext4_get_groups_count(sb). In that case, we want to exit immediately without allocating a block, and if i is left to sb->s_blocksize, that will cause the function to bail out right after the skipped for loop.
- Ted