]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.4/bcache-avoid-clang-wunintialized-warning.patch
577f9723bf5d096a2d44a7e01d1ae2a83238a004
[thirdparty/kernel/stable-queue.git] / queue-4.4 / bcache-avoid-clang-wunintialized-warning.patch
1 From 5c20f4898dd54fb9a51d7c4e2438f099ed1e2d5d Mon Sep 17 00:00:00 2001
2 From: Arnd Bergmann <arnd@arndb.de>
3 Date: Thu, 25 Apr 2019 00:48:28 +0800
4 Subject: bcache: avoid clang -Wunintialized warning
5
6 [ Upstream commit 78d4eb8ad9e1d413449d1b7a060f50b6efa81ebd ]
7
8 clang has identified a code path in which it thinks a
9 variable may be unused:
10
11 drivers/md/bcache/alloc.c:333:4: error: variable 'bucket' is used uninitialized whenever 'if' condition is false
12 [-Werror,-Wsometimes-uninitialized]
13 fifo_pop(&ca->free_inc, bucket);
14 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 drivers/md/bcache/util.h:219:27: note: expanded from macro 'fifo_pop'
16 #define fifo_pop(fifo, i) fifo_pop_front(fifo, (i))
17 ^~~~~~~~~~~~~~~~~~~~~~~~~
18 drivers/md/bcache/util.h:189:6: note: expanded from macro 'fifo_pop_front'
19 if (_r) { \
20 ^~
21 drivers/md/bcache/alloc.c:343:46: note: uninitialized use occurs here
22 allocator_wait(ca, bch_allocator_push(ca, bucket));
23 ^~~~~~
24 drivers/md/bcache/alloc.c:287:7: note: expanded from macro 'allocator_wait'
25 if (cond) \
26 ^~~~
27 drivers/md/bcache/alloc.c:333:4: note: remove the 'if' if its condition is always true
28 fifo_pop(&ca->free_inc, bucket);
29 ^
30 drivers/md/bcache/util.h:219:27: note: expanded from macro 'fifo_pop'
31 #define fifo_pop(fifo, i) fifo_pop_front(fifo, (i))
32 ^
33 drivers/md/bcache/util.h:189:2: note: expanded from macro 'fifo_pop_front'
34 if (_r) { \
35 ^
36 drivers/md/bcache/alloc.c:331:15: note: initialize the variable 'bucket' to silence this warning
37 long bucket;
38 ^
39
40 This cannot happen in practice because we only enter the loop
41 if there is at least one element in the list.
42
43 Slightly rearranging the code makes this clearer to both the
44 reader and the compiler, which avoids the warning.
45
46 Signed-off-by: Arnd Bergmann <arnd@arndb.de>
47 Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
48 Signed-off-by: Coly Li <colyli@suse.de>
49 Signed-off-by: Jens Axboe <axboe@kernel.dk>
50 Signed-off-by: Sasha Levin <sashal@kernel.org>
51 ---
52 drivers/md/bcache/alloc.c | 5 +++--
53 1 file changed, 3 insertions(+), 2 deletions(-)
54
55 diff --git a/drivers/md/bcache/alloc.c b/drivers/md/bcache/alloc.c
56 index 16c3390e5d9f3..d82ae445c9ee3 100644
57 --- a/drivers/md/bcache/alloc.c
58 +++ b/drivers/md/bcache/alloc.c
59 @@ -324,10 +324,11 @@ static int bch_allocator_thread(void *arg)
60 * possibly issue discards to them, then we add the bucket to
61 * the free list:
62 */
63 - while (!fifo_empty(&ca->free_inc)) {
64 + while (1) {
65 long bucket;
66
67 - fifo_pop(&ca->free_inc, bucket);
68 + if (!fifo_pop(&ca->free_inc, bucket))
69 + break;
70
71 if (ca->discard) {
72 mutex_unlock(&ca->set->bucket_lock);
73 --
74 2.20.1
75