Skip to contentSkip to conversation

fs/btrfs: Fix uninitialized variable

PATCH Superseded Khaled ROMDHANI 2 participants 3 messages Apr 27, 2021 – Apr 30, 2021

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 fs/btrfs: Fix uninitialized variable

The variable 'zone' is uninitialized which
introduce some build warning.

---
v2: catch the init as an assertion

---
 fs/btrfs/zoned.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/zoned.c +1 -1
index 432509f4b3ac..70c0b1b2ff04 100644
@@ -144,7 +144,7 @@ static inline u32 sb_zone_number(int shift, int mirror)
 	case 1: zone = 1ULL << (BTRFS_SB_LOG_FIRST_SHIFT - shift); break;
 	case 2: zone = 1ULL << (BTRFS_SB_LOG_SECOND_SHIFT - shift); break;
 	default:
-		ASSERT(zone);
+		ASSERT(zone = 0);
 		break;
 	}
 

base-commit: c05b2a58c9ed11bd753f1e64695bd89da715fbaa

Signature · 1 line
2.17.1
#1 lore raw
Quoted 16 lines · Khaled ROMDHANI

The variable 'zone' is uninitialized which
introduce some build warning.

---
v2: catch the init as an assertion

---
 fs/btrfs/zoned.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/zoned.c +0 -0
index 432509f4b3ac..70c0b1b2ff04 100644

fs/btrfs/zoned.c static inline u32 sb_zone_number(int shift, int mirror) · line 147

Quoted 5 lines
fs/btrfs/zoned.c +1 -1
@@ -144,7 +144,7 @@ static inline u32 sb_zone_number(int shift, int mirror)
 	case 1: zone = 1ULL << (BTRFS_SB_LOG_FIRST_SHIFT - shift); break;
 	case 2: zone = 1ULL << (BTRFS_SB_LOG_SECOND_SHIFT - shift); break;
 	default:
-		ASSERT(zone);
+		ASSERT(zone = 0);

I'm sorry but this doesn't make any kind of sense.

fs/btrfs/zoned.c static inline u32 sb_zone_number(int shift, int mirror) · line 149

Quoted 2 lines
fs/btrfs/zoned.c +0 -0
 		break;
 	}

regards,
dan carpenter

#2 lore raw
Quoted 25 lines · Dan Carpenter
Quoted 16 lines · Khaled ROMDHANI

The variable 'zone' is uninitialized which
introduce some build warning.

---
v2: catch the init as an assertion

---
 fs/btrfs/zoned.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/zoned.c +0 -0
index 432509f4b3ac..70c0b1b2ff04 100644

fs/btrfs/zoned.c static inline u32 sb_zone_number(int shift, int mirror) · line 147

Quoted 5 lines
fs/btrfs/zoned.c +1 -1
@@ -144,7 +144,7 @@ static inline u32 sb_zone_number(int shift, int mirror)
 	case 1: zone = 1ULL << (BTRFS_SB_LOG_FIRST_SHIFT - shift); break;
 	case 2: zone = 1ULL << (BTRFS_SB_LOG_SECOND_SHIFT - shift); break;
 	default:
-		ASSERT(zone);
+		ASSERT(zone = 0);

I'm sorry but this doesn't make any kind of sense.

Quoted 6 lines

fs/btrfs/zoned.c static inline u32 sb_zone_number(int shift, int mirror) · line 149

Quoted 2 lines
fs/btrfs/zoned.c +0 -0
 		break;
 	}

regards,
dan carpenter

The idea behind this is to force the assertion failure in default when no valid 'mirror' value was entered. But as all caller pass valid mirror values, this case will not happen. So, I just fix the warning of the uninitialized variable 'zone' as reported by the kernel test robot. Thus I guarantee the failure when 'mirror' was invalid.

If I am wrong, please clarify.

Thanks.