Skip to contentSkip to conversation

btrfs: work around false-positive -Wsometimes-uninitialized warning

PATCH In review Arnd Bergmann 3 participants 3 messages Mar 22, 2019 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: work around false-positive -Wsometimes-uninitialized warning

clang fails to see that the last 'else if() in btrfs_uuid_tree_add() is always true, so 'eb' is always initialized correctly:

fs/btrfs/uuid-tree.c:129:13: error: variable 'eb' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]

        } else if (ret < 0) {
                   ^~~~~~~
fs/btrfs/uuid-tree.c:139:22: note: uninitialized use occurs here
        write_extent_buffer(eb, &subid_le, offset, sizeof(subid_le));
                            ^~
fs/btrfs/uuid-tree.c:129:9: note: remove the 'if' if its condition is always true
        } else if (ret < 0) {
               ^~~~~~~~~~~~~
fs/btrfs/uuid-tree.c:90:26: note: initialize the variable 'eb' to silence this warning
        struct extent_buffer *eb;
                                ^
                                 = NULL

Change it into a plain 'else' to shut up that warning.

---
 fs/btrfs/uuid-tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/uuid-tree.c +1 -1
index 3b2ae342e649..c1cc9a5c0024 100644
@@ -126,7 +126,7 @@ int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, u8 *uuid, u8 type,
 		slot = path->slots[0];
 		offset = btrfs_item_ptr_offset(eb, slot);
 		offset += btrfs_item_size_nr(eb, slot) - sizeof(subid_le);
-	} else if (ret < 0) {
+	} else {
 		btrfs_warn(fs_info,
 			   "insert uuid item failed %d (0x%016llx, 0x%016llx) type %u!",
 			   ret, (unsigned long long)key.objectid,
Signature · 1 line
2.20.0
#1 lore raw
Quoted 17 lines · Arnd Bergmann

clang fails to see that the last 'else if() in btrfs_uuid_tree_add() is always true, so 'eb' is always initialized correctly:

fs/btrfs/uuid-tree.c:129:13: error: variable 'eb' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]

        } else if (ret < 0) {
                   ^~~~~~~
fs/btrfs/uuid-tree.c:139:22: note: uninitialized use occurs here
        write_extent_buffer(eb, &subid_le, offset, sizeof(subid_le));
                            ^~
fs/btrfs/uuid-tree.c:129:9: note: remove the 'if' if its condition is always true
        } else if (ret < 0) {
               ^~~~~~~~~~~~~
fs/btrfs/uuid-tree.c:90:26: note: initialize the variable 'eb' to silence this warning
        struct extent_buffer *eb;
                                ^
                                 = NULL
Quoted 4 lines

Change it into a plain 'else' to shut up that warning.

Such a patch has already been merged to misc-next:

f22898caa6a5 ("btrfs: Turn an 'else if' into an 'else' in btrfs_uuid_tree_add")

Quoted 18 lines
---
 fs/btrfs/uuid-tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/uuid-tree.c +1 -1
index 3b2ae342e649..c1cc9a5c0024 100644
@@ -126,7 +126,7 @@ int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, u8 *uuid, u8 type,
 		slot = path->slots[0];
 		offset = btrfs_item_ptr_offset(eb, slot);
 		offset += btrfs_item_size_nr(eb, slot) - sizeof(subid_le);
-	} else if (ret < 0) {
+	} else {
 		btrfs_warn(fs_info,
 			   "insert uuid item failed %d (0x%016llx, 0x%016llx) type %u!",
 			   ret, (unsigned long long)key.objectid,
#2 lore raw
Quoted 22 lines · Nikolay Borisov
Quoted 19 lines · Arnd Bergmann

clang fails to see that the last 'else if() in btrfs_uuid_tree_add() is always true, so 'eb' is always initialized correctly:

fs/btrfs/uuid-tree.c:129:13: error: variable 'eb' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]

        } else if (ret < 0) {
                   ^~~~~~~
fs/btrfs/uuid-tree.c:139:22: note: uninitialized use occurs here
        write_extent_buffer(eb, &subid_le, offset, sizeof(subid_le));
                            ^~
fs/btrfs/uuid-tree.c:129:9: note: remove the 'if' if its condition is always true
        } else if (ret < 0) {
               ^~~~~~~~~~~~~
fs/btrfs/uuid-tree.c:90:26: note: initialize the variable 'eb' to silence this warning
        struct extent_buffer *eb;
                                ^
                                 = NULL

Change it into a plain 'else' to shut up that warning.

Quoted 7 lines
Quoted 2 lines

Such a patch has already been merged to misc-next:

f22898caa6a5 ("btrfs: Turn an 'else if' into an 'else' in btrfs_uuid_tree_add")

I haven't updated for-next for a few days so the patch was not so visible outside, will push an update today.