btrfs: use BUG() instead of BUG_ON(1)
authorArnd Bergmann <arnd@arndb.de>
Mon, 25 Mar 2019 13:02:25 +0000 (14:02 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 29 Apr 2019 17:02:28 +0000 (19:02 +0200)
BUG_ON(1) leads to bogus warnings from clang when
CONFIG_PROFILE_ANNOTATED_BRANCHES is set:

fs/btrfs/volumes.c:5041:3: error: variable 'max_chunk_size' is used uninitialized whenever 'if' condition is false
      [-Werror,-Wsometimes-uninitialized]
                BUG_ON(1);
                ^~~~~~~~~
include/asm-generic/bug.h:61:36: note: expanded from macro 'BUG_ON'
 #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
                                   ^~~~~~~~~~~~~~~~~~~
include/linux/compiler.h:48:23: note: expanded from macro 'unlikely'
 #  define unlikely(x)   (__branch_check__(x, 0, __builtin_constant_p(x)))
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fs/btrfs/volumes.c:5046:9: note: uninitialized use occurs here
                             max_chunk_size);
                             ^~~~~~~~~~~~~~
include/linux/kernel.h:860:36: note: expanded from macro 'min'
 #define min(x, y)       __careful_cmp(x, y, <)
                                         ^
include/linux/kernel.h:853:17: note: expanded from macro '__careful_cmp'
                __cmp_once(x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y), op))
                              ^
include/linux/kernel.h:847:25: note: expanded from macro '__cmp_once'
                typeof(y) unique_y = (y);               \
                                      ^
fs/btrfs/volumes.c:5041:3: note: remove the 'if' if its condition is always true
                BUG_ON(1);
                ^
include/asm-generic/bug.h:61:32: note: expanded from macro 'BUG_ON'
 #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
                               ^
fs/btrfs/volumes.c:4993:20: note: initialize the variable 'max_chunk_size' to silence this warning
        u64 max_chunk_size;
                          ^
                           = 0

Change it to BUG() so clang can see that this code path can never
continue.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/backref.c
fs/btrfs/ctree.c
fs/btrfs/extent_io.c
fs/btrfs/file.c
fs/btrfs/inode.c
fs/btrfs/volumes.c

index 11459fe84a2965f795cfe6be3f91b9805fb72354..2602072ed906b7775d41a53dd642f0934b4827d3 100644 (file)
@@ -791,7 +791,7 @@ static int add_delayed_refs(const struct btrfs_fs_info *fs_info,
                        count = node->ref_mod * -1;
                        break;
                default:
-                       BUG_ON(1);
+                       BUG();
                }
                *total_refs += count;
                switch (node->type) {
@@ -1747,7 +1747,7 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
                else if (flags & BTRFS_EXTENT_FLAG_DATA)
                        *flags_ret = BTRFS_EXTENT_FLAG_DATA;
                else
-                       BUG_ON(1);
+                       BUG();
                return 0;
        }
 
index 65b12963e72b2c3ae86cd7a05bdb4b859f1c0b7f..7b1bc25f10cb70bf16fe494b2caacf049745ec86 100644 (file)
@@ -4684,7 +4684,7 @@ void btrfs_extend_item(struct btrfs_fs_info *fs_info, struct btrfs_path *path,
                btrfs_print_leaf(leaf);
                btrfs_crit(fs_info, "slot %d too large, nritems %d",
                           slot, nritems);
-               BUG_ON(1);
+               BUG();
        }
 
        /*
@@ -4764,7 +4764,7 @@ void setup_items_for_insert(struct btrfs_root *root, struct btrfs_path *path,
                        btrfs_print_leaf(leaf);
                        btrfs_crit(fs_info, "slot %d old_data %d data_end %d",
                                   slot, old_data, data_end);
-                       BUG_ON(1);
+                       BUG();
                }
                /*
                 * item0..itemN ... dataN.offset..dataN.size .. data0.size
index 7eb7f8a30ec24fdab33f1b24a9cc644548fe49ee..66b4637b29b3f7420e525359dc2ca94d110dd9e6 100644 (file)
@@ -5786,13 +5786,13 @@ void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
                btrfs_err(fs_info,
                        "memmove bogus src_offset %lu move len %lu dst len %lu",
                         src_offset, len, dst->len);
-               BUG_ON(1);
+               BUG();
        }
        if (dst_offset + len > dst->len) {
                btrfs_err(fs_info,
                        "memmove bogus dst_offset %lu move len %lu dst len %lu",
                         dst_offset, len, dst->len);
-               BUG_ON(1);
+               BUG();
        }
 
        while (len > 0) {
@@ -5833,13 +5833,13 @@ void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
                btrfs_err(fs_info,
                          "memmove bogus src_offset %lu move len %lu len %lu",
                          src_offset, len, dst->len);
-               BUG_ON(1);
+               BUG();
        }
        if (dst_offset + len > dst->len) {
                btrfs_err(fs_info,
                          "memmove bogus dst_offset %lu move len %lu len %lu",
                          dst_offset, len, dst->len);
-               BUG_ON(1);
+               BUG();
        }
        if (dst_offset < src_offset) {
                memcpy_extent_buffer(dst, dst_offset, src_offset, len);
index 94c1c86fd18a23819e93ea56c114a1142fb928bf..5e6aee84daeef7e353d26cc9fcfcf7987e155d1b 100644 (file)
@@ -1025,7 +1025,7 @@ delete_extent_item:
                        continue;
                }
 
-               BUG_ON(1);
+               BUG();
        }
 
        if (!ret && del_nr > 0) {
index a59619631194ffb83026f06c1c4e70c967f19a8e..4706018d1f9e3c60cba6907d2513f76ed80d4ab3 100644 (file)
@@ -1451,7 +1451,7 @@ next_slot:
                        extent_end = ALIGN(extent_end,
                                           fs_info->sectorsize);
                } else {
-                       BUG_ON(1);
+                       BUG();
                }
 out_check:
                if (extent_end <= start) {
index db934ceae9c109f39eade85457a25b8ce99604ae..fcb0d3f34e0957a004c400cb44ffcf1e1413703b 100644 (file)
@@ -5038,7 +5038,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
        } else {
                btrfs_err(info, "invalid chunk type 0x%llx requested",
                       type);
-               BUG_ON(1);
+               BUG();
        }
 
        /* We don't want a chunk larger than 10% of writable space */