Skip to contentSkip to conversation

btrfs: shut up bogus -Wmaybe-uninitialized warning

PATCH In review Arnd Bergmann 2 participants 2 messages Jun 17, 2019 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: shut up bogus -Wmaybe-uninitialized warning

gcc sometimes can't determine whether a variable has been initialized when both the initialization and the use are conditional:

fs/btrfs/props.c: In function 'inherit_props':
fs/btrfs/props.c:389:4: error: 'num_bytes' may be used uninitialized in this function [-Werror=maybe-uninitialized]

    btrfs_block_rsv_release(fs_info, trans->block_rsv,

This code is fine. Unfortunately, I cannot think of a good way to rephrase it in a way that makes gcc understand this, so I add a bogus initialization the way one should not.

Fixes d7400ee1b476 ("btrfs: use the existing reserved items for our first prop for inheritance")
---
 fs/btrfs/props.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/props.c +1 -1
index a9e2e66152ee..9d47ae1cf5b2 100644
@@ -341,7 +341,7 @@ static int inherit_props(struct btrfs_trans_handle *trans,
 	for (i = 0; i < ARRAY_SIZE(prop_handlers); i++) {
 		const struct prop_handler *h = &prop_handlers[i];
 		const char *value;
-		u64 num_bytes;
+		u64 num_bytes = 0;
 
 		if (!h->inheritable)
 			continue;
Signature · 1 line
2.20.0
#1 lore raw
Quoted 10 lines · Arnd Bergmann

gcc sometimes can't determine whether a variable has been initialized when both the initialization and the use are conditional:

fs/btrfs/props.c: In function 'inherit_props':
fs/btrfs/props.c:389:4: error: 'num_bytes' may be used uninitialized in this function [-Werror=maybe-uninitialized]

    btrfs_block_rsv_release(fs_info, trans->block_rsv,

This code is fine. Unfortunately, I cannot think of a good way to rephrase it in a way that makes gcc understand this, so I add a bogus initialization the way one should not.

Looks ok, patch added to devel queue, thanks.

Quoted 2 lines
Fixes d7400ee1b476 ("btrfs: use the existing reserved items for our first prop for inheritance")

I'd rather not add the Fixes tag here as it's just a compilation warning for some old unknown version of gcc. I've checked that 8.3.1 and 9.1.1 don't print the warning and I consider any other version to be up to the user of such environment to apply fixups as needed, but not to let the stable machinery pick it up.