Skip to contentSkip to conversation

btrfs: fix initialiser warning in fs/btrfs/tree-checker.c

PATCH In review Russell King (Oracle) 5 participants 8 messages Sep 19, 2021 – Sep 20, 2021 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: fix initialiser warning in fs/btrfs/tree-checker.c

Debian gcc 10.2.1 complains thusly:

fs/btrfs/tree-checker.c:1071:9: warning: missing braces around initializer [-Wmissing-braces]

  struct btrfs_root_item ri = { 0 };
         ^

fs/btrfs/tree-checker.c:1071:9: warning: (near initialization for 'ri.inode') [-Wmissing-braces]

Fix it by removing the unnecessary '0' initialiser, leaving the braces.

Fixes 1465af12e254 ("btrfs: tree-checker: fix false alert caused by legacy btrfs root item")
---
 fs/btrfs/tree-checker.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/tree-checker.c +1 -1
index a8b2e0d2c025..1737b62756a6 100644
@@ -1068,7 +1068,7 @@ static int check_root_item(struct extent_buffer *leaf, struct btrfs_key *key,
 			   int slot)
 {
 	struct btrfs_fs_info *fs_info = leaf->fs_info;
-	struct btrfs_root_item ri = { 0 };
+	struct btrfs_root_item ri = { };
 	const u64 valid_root_flags = BTRFS_ROOT_SUBVOL_RDONLY |
 				     BTRFS_ROOT_SUBVOL_DEAD;
 	int ret;
Signature · 1 line
2.30.2
#1 lore raw
Quoted 10 lines · Russell King (Oracle)

Debian gcc 10.2.1 complains thusly:

fs/btrfs/tree-checker.c:1071:9: warning: missing braces around initializer [-Wmissing-braces]

   struct btrfs_root_item ri = { 0 };
          ^

fs/btrfs/tree-checker.c:1071:9: warning: (near initialization for 'ri.inode') [-Wmissing-braces]

Fix it by removing the unnecessary '0' initialiser, leaving the braces.

This should be a compiler bug.

= { 0 }; is completely fine here, in fact = { }; would be more problematic.

What's the compiler version? I haven't hit such problem for GCC 11.1.0 nor clang 12.0.1.

Thanks,
Qu

Quoted 21 lines
Fixes 1465af12e254 ("btrfs: tree-checker: fix false alert caused by legacy btrfs root item")
---
  fs/btrfs/tree-checker.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/tree-checker.c +1 -1
index a8b2e0d2c025..1737b62756a6 100644
@@ -1068,7 +1068,7 @@ static int check_root_item(struct extent_buffer *leaf, struct btrfs_key *key,
  			   int slot)
  {
  	struct btrfs_fs_info *fs_info = leaf->fs_info;
-	struct btrfs_root_item ri = { 0 };
+	struct btrfs_root_item ri = { };
  	const u64 valid_root_flags = BTRFS_ROOT_SUBVOL_RDONLY |
  				     BTRFS_ROOT_SUBVOL_DEAD;
  	int ret;
#2 lore raw
Quoted 14 lines · Qu Wenruo
Quoted 10 lines · Russell King (Oracle)

Debian gcc 10.2.1 complains thusly:

fs/btrfs/tree-checker.c:1071:9: warning: missing braces around initializer [-Wmissing-braces]

   struct btrfs_root_item ri = { 0 };
          ^

fs/btrfs/tree-checker.c:1071:9: warning: (near initialization for 'ri.inode') [-Wmissing-braces]

Fix it by removing the unnecessary '0' initialiser, leaving the braces.

Quoted 6 lines

This should be a compiler bug.

= { 0 }; is completely fine here, in fact = { }; would be more problematic.

What's the compiler version? I haven't hit such problem for GCC 11.1.0 nor clang 12.0.1.

I just realised that it's not the compiler I thought it was - It's GCC 4.9.4 used on 32-bit ARM.

= { }; is not a problem for that version of GCC. Why do you think it's problematic?

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
#3 lore raw
Quoted 17 lines · Russell King (Oracle)
Quoted 16 lines · Qu Wenruo
Quoted 10 lines · Russell King (Oracle)

Debian gcc 10.2.1 complains thusly:

fs/btrfs/tree-checker.c:1071:9: warning: missing braces around initializer [-Wmissing-braces]

   struct btrfs_root_item ri = { 0 };
          ^

fs/btrfs/tree-checker.c:1071:9: warning: (near initialization for 'ri.inode') [-Wmissing-braces]

Fix it by removing the unnecessary '0' initialiser, leaving the braces.

This should be a compiler bug.

Quoted 7 lines
Quoted 4 lines

= { 0 }; is completely fine here, in fact = { }; would be more problematic.

What's the compiler version? I haven't hit such problem for GCC 11.1.0 nor clang 12.0.1.

I just realised that it's not the compiler I thought it was - It's GCC 4.9.4 used on 32-bit ARM.

Okay, ignore this - the warning exists with 5.14, where 4.9.4 is still a valid compiler, but no longer with 5.15-rc.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
#4 lore raw
In reply to Russell King (Oracle)
Quoted 17 lines · Russell King (Oracle)
Quoted 16 lines · Qu Wenruo
Quoted 10 lines · Russell King (Oracle)

Debian gcc 10.2.1 complains thusly:

fs/btrfs/tree-checker.c:1071:9: warning: missing braces around initializer [-Wmissing-braces]

    struct btrfs_root_item ri = { 0 };
           ^

fs/btrfs/tree-checker.c:1071:9: warning: (near initialization for 'ri.inode') [-Wmissing-braces]

Fix it by removing the unnecessary '0' initialiser, leaving the braces.

This should be a compiler bug.

Quoted 7 lines
Quoted 4 lines

= { 0 }; is completely fine here, in fact = { }; would be more problematic.

What's the compiler version? I haven't hit such problem for GCC 11.1.0 nor clang 12.0.1.

I just realised that it's not the compiler I thought it was - It's GCC 4.9.4 used on 32-bit ARM.

That's bare minimal GCC version required for kernel build.

I'm not sure if that old version has all the correct backports.

Quoted 4 lines

= { }; is not a problem for that version of GCC. Why do you think it's problematic?

Isn't initialization with empty initializers against C89/90 standard?

Thanks,
Qu

#5 lore raw
In reply to Russell King (Oracle)
Quoted 22 lines · Russell King (Oracle)

Debian gcc 10.2.1 complains thusly:

fs/btrfs/tree-checker.c:1071:9: warning: missing braces around initializer [-Wmissing-braces]

  struct btrfs_root_item ri = { 0 };
         ^

fs/btrfs/tree-checker.c:1071:9: warning: (near initialization for 'ri.inode') [-Wmissing-braces]

Fix it by removing the unnecessary '0' initialiser, leaving the braces.

Fixes 1465af12e254 ("btrfs: tree-checker: fix false alert caused by legacy btrfs root item")
---
 fs/btrfs/tree-checker.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/tree-checker.c +0 -0
index a8b2e0d2c025..1737b62756a6 100644

fs/btrfs/tree-checker.c static int check_root_item(struct extent_buffer *leaf, struct btrfs_key *key, · line 1071

Quoted 5 lines
fs/btrfs/tree-checker.c +1 -1
@@ -1068,7 +1068,7 @@ static int check_root_item(struct extent_buffer *leaf, struct btrfs_key *key,
 			   int slot)
 {
 	struct btrfs_fs_info *fs_info = leaf->fs_info;
-	struct btrfs_root_item ri = { 0 };
+	struct btrfs_root_item ri = { };

Kees Cook does a tree wide unification to { } because there are some oddities with partial initialization and { 0 } so this will get fixed eventually. But again the minimum gcc version is now 5.1 so it won't matter for 4.9 anyway.

#6 lore raw
Quoted 18 lines · David Sterba
Quoted 17 lines · Russell King (Oracle)

Debian gcc 10.2.1 complains thusly:

fs/btrfs/tree-checker.c:1071:9: warning: missing braces around initializer [-Wmissing-braces]

   struct btrfs_root_item ri = { 0 };
          ^

fs/btrfs/tree-checker.c:1071:9: warning: (near initialization for 'ri.inode') [-Wmissing-braces]

Fix it by removing the unnecessary '0' initialiser, leaving the braces.

Fixes 1465af12e254 ("btrfs: tree-checker: fix false alert caused by legacy btrfs root item")
---
  fs/btrfs/tree-checker.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines

fs/btrfs/tree-checker.c static int check_root_item(struct extent_buffer *leaf, struct btrfs_key *key, · line 1071

Quoted 10 lines
fs/btrfs/tree-checker.c +1 -1
index a8b2e0d2c025..1737b62756a6 100644
@@ -1068,7 +1068,7 @@ static int check_root_item(struct extent_buffer *leaf, struct btrfs_key *key,
  			   int slot)
  {
  	struct btrfs_fs_info *fs_info = leaf->fs_info;
-	struct btrfs_root_item ri = { 0 };
+	struct btrfs_root_item ri = { };

Kees Cook does a tree wide unification to { } because there are some oddities with partial initialization and { 0 } so this will get fixed eventually.

Does this mean in the future only "= { }" is preferred?

It would looks a little weird to me as C89/C90 doesn't allow this.

And I guess checkpatch would also be updated to handle that?

Thanks,
Qu

Quoted 3 lines

But again the minimum gcc version is now 5.1 so it won't matter for 4.9 anyway.

#7 lore raw
Quoted 5 lines · Qu Wenruo
Quoted 3 lines

Kees Cook does a tree wide unification to { } because there are some oddities with partial initialization and { 0 } so this will get fixed eventually.

Does this mean in the future only "= { }" is preferred?

Yes,
https://lore.kernel.org/all/[email protected]/

Quoted 3 lines

It would looks a little weird to me as C89/C90 doesn't allow this.

And I guess checkpatch would also be updated to handle that?

I think so but we can always override what checkpatch suggests.