linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: work around false-positive -Wsometimes-uninitialized warning
@ 2019-03-22 14:07 Arnd Bergmann
  2019-03-22 14:11 ` Nikolay Borisov
  0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2019-03-22 14:07 UTC (permalink / raw)
  To: Chris Mason, Josef Bacik, David Sterba
  Cc: clang-built-linux, Nick Desaulniers, Nathan Chancellor,
	Arnd Bergmann, Nikolay Borisov, Lu Fengqi, Anand Jain,
	linux-btrfs, linux-kernel

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.

Link: https://bugs.llvm.org/show_bug.cgi?id=41197
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 fs/btrfs/uuid-tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/uuid-tree.c b/fs/btrfs/uuid-tree.c
index 3b2ae342e649..c1cc9a5c0024 100644
--- a/fs/btrfs/uuid-tree.c
+++ b/fs/btrfs/uuid-tree.c
@@ -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.20.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: work around false-positive -Wsometimes-uninitialized warning
  2019-03-22 14:07 [PATCH] btrfs: work around false-positive -Wsometimes-uninitialized warning Arnd Bergmann
@ 2019-03-22 14:11 ` Nikolay Borisov
  2019-03-22 14:25   ` David Sterba
  0 siblings, 1 reply; 3+ messages in thread
From: Nikolay Borisov @ 2019-03-22 14:11 UTC (permalink / raw)
  To: Arnd Bergmann, Chris Mason, Josef Bacik, David Sterba
  Cc: clang-built-linux, Nick Desaulniers, Nathan Chancellor,
	Lu Fengqi, Anand Jain, linux-btrfs, linux-kernel



On 22.03.19 г. 16:07 ч., Arnd Bergmann wrote:
> 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.
> 
> Link: https://bugs.llvm.org/show_bug.cgi?id=41197
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

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

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



> ---
>  fs/btrfs/uuid-tree.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/uuid-tree.c b/fs/btrfs/uuid-tree.c
> index 3b2ae342e649..c1cc9a5c0024 100644
> --- a/fs/btrfs/uuid-tree.c
> +++ b/fs/btrfs/uuid-tree.c
> @@ -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,
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: work around false-positive -Wsometimes-uninitialized warning
  2019-03-22 14:11 ` Nikolay Borisov
@ 2019-03-22 14:25   ` David Sterba
  0 siblings, 0 replies; 3+ messages in thread
From: David Sterba @ 2019-03-22 14:25 UTC (permalink / raw)
  To: Nikolay Borisov
  Cc: Arnd Bergmann, Chris Mason, Josef Bacik, David Sterba,
	clang-built-linux, Nick Desaulniers, Nathan Chancellor,
	Lu Fengqi, Anand Jain, linux-btrfs, linux-kernel

On Fri, Mar 22, 2019 at 04:11:52PM +0200, Nikolay Borisov wrote:
> 
> 
> On 22.03.19 г. 16:07 ч., Arnd Bergmann wrote:
> > 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.
> > 
> > Link: https://bugs.llvm.org/show_bug.cgi?id=41197
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> 
> 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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-03-22 14:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-22 14:07 [PATCH] btrfs: work around false-positive -Wsometimes-uninitialized warning Arnd Bergmann
2019-03-22 14:11 ` Nikolay Borisov
2019-03-22 14:25   ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).