add patch cond_resched-in-work-heavy-group-loops
[ext4-patch-queue.git] / use-BUG-instead-of-BUG_ON
blob24ff5ff3c324b2372d85591f75aeb14c2f8a5187
1 ext4: use BUG() instead of BUG_ON(1)
3 From: Arnd Bergmann <arnd@arndb.de>
5 BUG_ON(1) leads to bogus warnings from clang when
6 CONFIG_PROFILE_ANNOTATED_BRANCHES is set:
8  fs/ext4/inode.c:544:4: error: variable 'retval' is used uninitialized whenever 'if' condition is false
9       [-Werror,-Wsometimes-uninitialized]
10                         BUG_ON(1);
11                         ^~~~~~~~~
12  include/asm-generic/bug.h:61:36: note: expanded from macro 'BUG_ON'
13                                    ^~~~~~~~~~~~~~~~~~~
14  include/linux/compiler.h:48:23: note: expanded from macro 'unlikely'
15                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16  fs/ext4/inode.c:591:6: note: uninitialized use occurs here
17         if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) {
18             ^~~~~~
19  fs/ext4/inode.c:544:4: note: remove the 'if' if its condition is always true
20                         BUG_ON(1);
21                         ^
22  include/asm-generic/bug.h:61:32: note: expanded from macro 'BUG_ON'
23                                ^
24  fs/ext4/inode.c:502:12: note: initialize the variable 'retval' to silence this warning
26 Change it to BUG() so clang can see that this code path can never
27 continue.
29 Signed-off-by: Arnd Bergmann <arnd@arndb.de>
30 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
31 Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
32 Reviewed-by: Jan Kara <jack@suse.cz>
33 ---
34  fs/ext4/extents_status.c | 4 ++--
35  fs/ext4/inode.c          | 4 ++--
36  2 files changed, 4 insertions(+), 4 deletions(-)
38 diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
39 index 2b439afafe13..023a3eb3afa3 100644
40 --- a/fs/ext4/extents_status.c
41 +++ b/fs/ext4/extents_status.c
42 @@ -711,7 +711,7 @@ static void ext4_es_insert_extent_ind_check(struct inode *inode,
43                          * We don't need to check unwritten extent because
44                          * indirect-based file doesn't have it.
45                          */
46 -                       BUG_ON(1);
47 +                       BUG();
48                 }
49         } else if (retval == 0) {
50                 if (ext4_es_is_written(es)) {
51 @@ -780,7 +780,7 @@ static int __es_insert_extent(struct inode *inode, struct extent_status *newes)
52                         }
53                         p = &(*p)->rb_right;
54                 } else {
55 -                       BUG_ON(1);
56 +                       BUG();
57                         return -EINVAL;
58                 }
59         }
60 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
61 index b32a57bc5d5d..190f0478582a 100644
62 --- a/fs/ext4/inode.c
63 +++ b/fs/ext4/inode.c
64 @@ -541,7 +541,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
65                         map->m_len = retval;
66                         retval = 0;
67                 } else {
68 -                       BUG_ON(1);
69 +                       BUG();
70                 }
71  #ifdef ES_AGGRESSIVE_TEST
72                 ext4_map_blocks_es_recheck(handle, inode, map,
73 @@ -1876,7 +1876,7 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock,
74                 else if (ext4_es_is_unwritten(&es))
75                         map->m_flags |= EXT4_MAP_UNWRITTEN;
76                 else
77 -                       BUG_ON(1);
78 +                       BUG();
80  #ifdef ES_AGGRESSIVE_TEST
81                 ext4_map_blocks_es_recheck(NULL, inode, map, &orig_map, 0);
82 -- 
83 2.20.0