Thread (5 messages) 5 messages, 3 authors, 2016-09-19

Re: [PATCH] sbitmap: avoid maybe-uninitialized warning

flat view

From: Jens Axboe <axboe@kernel.dk>
Date: 2016-09-19 15:22:40
Also in: lkml

On 09/19/2016 09:14 AM, Arnd Bergmann wrote:
On Monday, September 19, 2016 8:43:12 AM CEST Jens Axboe wrote:
quoted
On 09/19/2016 06:33 AM, Arnd Bergmann wrote:
quoted
The sbitmap code that has just been turned into a library module
returns uninitialized data for sbitmap_weight(), as pointed out by
gcc when building with -Wmaybe-uninitialized:

lib/sbitmap.c: In function 'sbitmap_weight':
lib/sbitmap.c:179:9: error: 'weight' may be used uninitialized in this function [-Werror=maybe-uninitialized]

Note that the value is never initialized, we just add data on
top, so it is wrong regardless of sb->map_nr.

This adds the missing initialization.
Thanks Arnd, Colin sent the same patch and I applied it. Note that:
Ok, thanks!
quoted
quoted
Fixes: 88459642cba4 ("blk-mq: abstract tag allocation out into sbitmap library")
that isn't truly correct, that patch is just what moved the code. The
bug predates that commit.
It's not important as long as the bug is fixed now, but I think it was
correct before that move, we just lost the 'used=0' initialization,
which also triggered the warning:

-static unsigned int bt_unused_tags(struct blk_mq_bitmap_tags *bt)
-{
-       unsigned int i, used;
-
-       for (i = 0, used = 0; i < bt->map_nr; i++) {
-               struct blk_align_bitmap *bm = &bt->map[i];
-
-               used += bitmap_weight(&bm->word, bm->depth);
        }

-       return bt->depth - used;
 }
I missed that, as I generally never use double inits in for loops, but I
guess I did for this one. But you are right, the bug was introduced with
the recent move, so your Fixes was completely correct.

Omar loses a cookie.

-- 
Jens Axboe
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help