fs/btrfs: Fix uninitialized variable
Subsystems (2)
PATCH v2 1/1 fs/btrfs: Fix uninitialized variable
As reported by the Coverity static analysis.
The variable zone is not initialized which
may causes a failed assertion.
Addresses-Coverity: ("Uninitialized variables")
---
v2: add a default case as proposed by David Sterba
--- fs/btrfs/zoned.c | 3 +++ 1 file changed, 3 insertions(+)
fs/btrfs/zoned.c +3 -0
@@ -143,6 +143,9 @@ static inline u32 sb_zone_number(int shift, int mirror)case 0 : zone =0 ;break ;case 1 : zone =1ULL << (BTRFS_SB_LOG_FIRST_SHIFT - shift);break ;case 2 : zone =1ULL << (BTRFS_SB_LOG_SECOND_SHIFT - shift);break ; +default : + zone =0 ; +break ; }ASSERT (zone <=U32_MAX );
Signature · 1 line
2.17.1
Quoted 17 lines · Khaled ROMDHANI
As reported by the Coverity static analysis.
The variable zone is not initialized which
may causes a failed assertion.Addresses-Coverity: ("Uninitialized variables")
Signed-off-by Khaled ROMDHANI <[email protected]>---
v2: add a default case as proposed by David Sterba--- fs/btrfs/zoned.c | 3 +++ 1 file changed, 3 insertions(+)fs/btrfs/zoned.c +0
-0
fs/btrfs/zoned.c static inline u32 sb_zone_number(int shift, int mirror) · line 147
Quoted 5 lines
fs/btrfs/zoned.c +2
-0@@ -143,6 +143,9 @@ static inline u32 sb_zone_number(int shift, int mirror)case 0 : zone =0 ;break ;case 1 : zone =1ULL << (BTRFS_SB_LOG_FIRST_SHIFT - shift);break ;case 2 : zone =1ULL << (BTRFS_SB_LOG_SECOND_SHIFT - shift);break ; +default : + zone =0 ;
Well yeah but this is not a valid case at all, we'd rather catch that as an assertion failure than letting is silently continue.
Quoted 13 lines · David Sterba
Quoted 12 lines · Khaled ROMDHANI
As reported by the Coverity static analysis.
The variable zone is not initialized which
may causes a failed assertion.Addresses-Coverity: ("Uninitialized variables")
Signed-off-by Khaled ROMDHANI <[email protected]>---
v2: add a default case as proposed by David Sterba--- fs/btrfs/zoned.c | 3 +++ 1 file changed, 3 insertions(+)
Quoted 13 lines
fs/btrfs/zoned.c static inline u32 sb_zone_number(int shift, int mirror) · line 147
Quoted 10 lines
fs/btrfs/zoned.c +2
-0@@ -143,6 +143,9 @@ static inline u32 sb_zone_number(int shift, int mirror)case 0 : zone =0 ;break ;case 1 : zone =1ULL << (BTRFS_SB_LOG_FIRST_SHIFT - shift);break ;case 2 : zone =1ULL << (BTRFS_SB_LOG_SECOND_SHIFT - shift);break ; +default : + zone =0 ;Well yeah but this is not a valid case at all, we'd rather catch that as an assertion failure than letting is silently continue.
So, as all callers pass valid value. It would be
better to catch that as an assertion failure.
Quoted 17 lines · Khaled ROMDHANI
As reported by the Coverity static analysis.
The variable zone is not initialized which
may causes a failed assertion.Addresses-Coverity: ("Uninitialized variables")
Signed-off-by Khaled ROMDHANI <[email protected]>---
v2: add a default case as proposed by David Sterba--- fs/btrfs/zoned.c | 3 +++ 1 file changed, 3 insertions(+)fs/btrfs/zoned.c +0
-0
fs/btrfs/zoned.c static inline u32 sb_zone_number(int shift, int mirror) · line 145
Quoted 3 lines
fs/btrfs/zoned.c +0
-0@@ -143,6 +143,9 @@ static inline u32 sb_zone_number(int shift, int mirror)case 0 : zone =0 ;break ;case 1 : zone =1ULL << (BTRFS_SB_LOG_FIRST_SHIFT - shift);break ;case 2 : zone =1ULL << (BTRFS_SB_LOG_SECOND_SHIFT - shift);break ;
It took me a while to spot these break statements.
fs/btrfs/zoned.c static inline u32 sb_zone_number(int shift, int mirror) · line 148
Quoted 3 lines
fs/btrfs/zoned.c +3
-0+default : + zone =0 ; +break ;
This break needs to be indented one more tab.
fs/btrfs/zoned.c static inline u32 sb_zone_number(int shift, int mirror) · line 151
Quoted 3 lines
fs/btrfs/zoned.c +0
-0}ASSERT (zone <=U32_MAX );
regards,
dan carpenter
Quoted 30 lines · Dan Carpenter
Quoted 17 lines · Khaled ROMDHANI
As reported by the Coverity static analysis.
The variable zone is not initialized which
may causes a failed assertion.Addresses-Coverity: ("Uninitialized variables")
Signed-off-by Khaled ROMDHANI <[email protected]>---
v2: add a default case as proposed by David Sterba--- fs/btrfs/zoned.c | 3 +++ 1 file changed, 3 insertions(+)fs/btrfs/zoned.c +0
-0fs/btrfs/zoned.c static inline u32 sb_zone_number(int shift, int mirror) · line 145
Quoted 3 lines
fs/btrfs/zoned.c +0
-0@@ -143,6 +143,9 @@ static inline u32 sb_zone_number(int shift, int mirror)case 0 : zone =0 ;break ;case 1 : zone =1ULL << (BTRFS_SB_LOG_FIRST_SHIFT - shift);break ;case 2 : zone =1ULL << (BTRFS_SB_LOG_SECOND_SHIFT - shift);break ;It took me a while to spot these break statements.
fs/btrfs/zoned.c static inline u32 sb_zone_number(int shift, int mirror) · line 148
Quoted 3 lines
fs/btrfs/zoned.c +3
-0+default : + zone =0 ; +break ;This break needs to be indented one more tab.
Quoted 6 lines
fs/btrfs/zoned.c static inline u32 sb_zone_number(int shift, int mirror) · line 151
Quoted 3 lines
fs/btrfs/zoned.c +0
-0}ASSERT (zone <=U32_MAX );regards,
dan carpenter
Sorry, but I checked the patch using checkpatch.pl before sending it. Is that blocks some smatch parsing process?
In any cases, I will send a V3.
Thanks.