fs/btrfs: Fix uninitialized variable
Subsystems (2)
The variable zone is not initialized. It
may causes a failed assertion.
Addresses-Coverity: ("Uninitialized variables")
--- fs/btrfs/zoned.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/zoned.c +1 -1
@@ -136,7 +136,7 @@ static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones,*/ static inline u32 sb_zone_number (int shift,int mirror) { -u64 zone; +u64 zone =0 ;ASSERT (mirror <BTRFS_SUPER_MIRROR_MAX );switch (mirror) {
Signature · 1 line
2.17.1
Boris Burkov
Reviewed-byQuoted 6 lines · Khaled ROMDHANI
The variable zone is not initialized. It
may causes a failed assertion.Addresses-Coverity: ("Uninitialized variables")
Signed-off-by Khaled ROMDHANI <[email protected]>
Quoted 9 lines
--- fs/btrfs/zoned.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/btrfs/zoned.c +0
-0
fs/btrfs/zoned.c static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones, · line 141
Quoted 7 lines
fs/btrfs/zoned.c +1
-1@@ -136,7 +136,7 @@ static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones,*/ static inline u32 sb_zone_number (int shift,int mirror) { -u64 zone; +u64 zone =0 ;ASSERT (mirror <BTRFS_SUPER_MIRROR_MAX );
Thanks for the fix.
I assume this was dug up by coverity static analysis rather than hitting it in a live system?
Since there is already an assert for the pre-condition 'mirror < max', I feel like it would make sense to also add one for mirror > 0.
Quoted 4 lines
fs/btrfs/zoned.c +0
-0switch (mirror) {Signature · 1 line
2.17.1
Quoted 2 lines · Khaled ROMDHANI
The variable zone is not initialized. It
may causes a failed assertion.
Failed assertion means the 2nd one checking that the result still fits to 32bit type. That would mean that none of the cases were hit, but all callers pass valid values.
It would be better to add a default: case to catch that explicitly, though hitting that is considered 'will not happen'.
Quoted 10 lines · David Sterba
Quoted 2 lines · Khaled ROMDHANI
The variable zone is not initialized. It
may causes a failed assertion.Failed assertion means the 2nd one checking that the result still fits to 32bit type. That would mean that none of the cases were hit, but all callers pass valid values.
It would be better to add a default: case to catch that explicitly, though hitting that is considered 'will not happen'.
Yes. I will send a V2.