Skip to contentSkip to conversation

btrfs: initialize location to fix -Wmaybe-uninitialized in btrfs_lookup_dentry()

PATCH In review David Sterba 4 participants 4 messages Jul 29, 2024 – Jul 30, 2024 Btrfs file system

lore
Share & tools
lore

David Sterba

author maintainer
#0 lore raw

PATCH 1/1 btrfs: initialize location to fix -Wmaybe-uninitialized in btrfs_lookup_dentry()

Some arch + compiler combinations report a potentially unused variable location in btrfs_lookup_dentry(). This is a false alert as the variable is passed by value and always valid or there's an error. The compilers cannot probably reason about that although btrfs_inode_by_name() is in the same file.

Quoted 1 line

+ /kisskb/src/fs/btrfs/inode.c: error: 'location.objectid' may be used

+uninitialized in this function [-Werror=maybe-uninitialized]: => 5603:9

Quoted 1 line

+ /kisskb/src/fs/btrfs/inode.c: error: 'location.type' may be used

+uninitialized in this function [-Werror=maybe-uninitialized]: => 5674:5

m68k-gcc8/m68k-allmodconfig
mips-gcc8/mips-allmodconfig
powerpc-gcc5/powerpc-all{mod,yes}config
powerpc-gcc5/ppc64_defconfig

Initialize it to zero, this should fix the warnings and won't change the behaviour as btrfs_inode_by_name() accepts only a root or inode item types, otherwise returns an error.

---
 fs/btrfs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/inode.c +1 -1
index 32010127710d..333b0e8587a2 100644
@@ -5667,7 +5667,7 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
 	struct inode *inode;
 	struct btrfs_root *root = BTRFS_I(dir)->root;
 	struct btrfs_root *sub_root = root;
-	struct btrfs_key location;
+	struct btrfs_key location = { 0 };
 	u8 di_type = 0;
 	int ret = 0;
 
Signature · 1 line
2.45.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · David Sterba

Some arch + compiler combinations report a potentially unused variable location in btrfs_lookup_dentry(). This is a false alert as the variable is passed by value and always valid or there's an error. The compilers cannot probably reason about that although btrfs_inode_by_name() is in the same file.

Quoted 1 line

+ /kisskb/src/fs/btrfs/inode.c: error: 'location.objectid' may be used

+uninitialized in this function [-Werror=maybe-uninitialized]: => 5603:9 > + /kisskb/src/fs/btrfs/inode.c: error: 'location.type' may be used +uninitialized in this function [-Werror=maybe-uninitialized]: => 5674:5

m68k-gcc8/m68k-allmodconfig
mips-gcc8/mips-allmodconfig
powerpc-gcc5/powerpc-all{mod,yes}config
powerpc-gcc5/ppc64_defconfig

Quoted 7 lines

Initialize it to zero, this should fix the warnings and won't change the behaviour as btrfs_inode_by_name() accepts only a root or inode item types, otherwise returns an error.

Although I hate to update our code for bad compilers, I guess it's unavoidable anyway.

Thanks,
Qu

Quoted 17 lines
---
  fs/btrfs/inode.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/inode.c +1 -1
index 32010127710d..333b0e8587a2 100644
@@ -5667,7 +5667,7 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
  	struct inode *inode;
  	struct btrfs_root *root = BTRFS_I(dir)->root;
  	struct btrfs_root *sub_root = root;
-	struct btrfs_key location;
+	struct btrfs_key location = { 0 };
  	u8 di_type = 0;
  	int ret = 0;
 
#2 lore raw
Quoted 23 lines · Qu Wenruo
Quoted 20 lines · David Sterba

Some arch + compiler combinations report a potentially unused variable location in btrfs_lookup_dentry(). This is a false alert as the variable is passed by value and always valid or there's an error. The compilers cannot probably reason about that although btrfs_inode_by_name() is in the same file.

Quoted 1 line

+ /kisskb/src/fs/btrfs/inode.c: error: 'location.objectid' may be used

+uninitialized in this function [-Werror=maybe-uninitialized]: => 5603:9 > + /kisskb/src/fs/btrfs/inode.c: error: 'location.type' may be used +uninitialized in this function [-Werror=maybe-uninitialized]: => 5674:5

m68k-gcc8/m68k-allmodconfig
mips-gcc8/mips-allmodconfig
powerpc-gcc5/powerpc-all{mod,yes}config
powerpc-gcc5/ppc64_defconfig

Initialize it to zero, this should fix the warnings and won't change the behaviour as btrfs_inode_by_name() accepts only a root or inode item types, otherwise returns an error.

Quoted 8 lines
Quoted 3 lines

Although I hate to update our code for bad compilers, I guess it's unavoidable anyway.

Yeah, but the number of such fixups is bearable, we have added like one per release.

Tested-by on v1 1/1
#3 lore raw
In reply to David Sterba

Hi David,

Quoted 32 lines · David Sterba

Some arch + compiler combinations report a potentially unused variable location in btrfs_lookup_dentry(). This is a false alert as the variable is passed by value and always valid or there's an error. The compilers cannot probably reason about that although btrfs_inode_by_name() is in the same file.

Quoted 1 line

+ /kisskb/src/fs/btrfs/inode.c: error: 'location.objectid' may be used

+uninitialized in this function [-Werror=maybe-uninitialized]: => 5603:9

Quoted 1 line

+ /kisskb/src/fs/btrfs/inode.c: error: 'location.type' may be used

+uninitialized in this function [-Werror=maybe-uninitialized]: => 5674:5

   m68k-gcc8/m68k-allmodconfig
   mips-gcc8/mips-allmodconfig
   powerpc-gcc5/powerpc-all{mod,yes}config
   powerpc-gcc5/ppc64_defconfig

Initialize it to zero, this should fix the warnings and won't change the behaviour as btrfs_inode_by_name() accepts only a root or inode item types, otherwise returns an error.

---
 fs/btrfs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/inode.c +0 -0
index 32010127710d..333b0e8587a2 100644

fs/btrfs/inode.c struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry) · line 5673

Quoted 8 lines
fs/btrfs/inode.c +1 -1
@@ -5667,7 +5667,7 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
        struct inode *inode;
        struct btrfs_root *root = BTRFS_I(dir)->root;
        struct btrfs_root *sub_root = root;
-       struct btrfs_key location;
+       struct btrfs_key location = { 0 };
        u8 di_type = 0;
        int ret = 0;
 

Thanks, this gets rid of the failure for m68k/allmodconfig (gcc version 8.4.0 (Ubuntu 8.4.0-3ubuntu1) and 9.5.0 (Ubuntu 9.5.0-1ubuntu1~22.04)).

On m68k, it didn't show up with gcc 10, 11, and 12. Also, enabling CONFIG_CC_OPTIMIZE_FOR_SIZE fixed it for gcc 8/9.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds