From: Bart Van Assche Date: Tue, 9 Dec 2014 15:58:11 +0000 (+0100) Subject: blk-mq: Avoid that __bt_get_word() wraps multiple times X-Git-Tag: v3.18.3~102 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d04e14ab4713a186700ef70b2e4d994618cbc64a;p=platform%2Fkernel%2Flinux-stable.git blk-mq: Avoid that __bt_get_word() wraps multiple times commit 9e98e9d7cf6e9d2ec1cce45e8d5ccaf3f9b386f3 upstream. If __bt_get_word() is called with last_tag != 0, if the first find_next_zero_bit() fails, if after wrap-around the test_and_set_bit() call fails and find_next_zero_bit() succeeds, if the next test_and_set_bit() call fails and subsequently find_next_zero_bit() does not find a zero bit, then another wrap-around will occur. Avoid this by introducing an additional local variable. Signed-off-by: Bart Van Assche Cc: Christoph Hellwig Cc: Robert Elliott Cc: Ming Lei Cc: Alexander Gordeev Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c index 8317175a3009..663f5d922950 100644 --- a/block/blk-mq-tag.c +++ b/block/blk-mq-tag.c @@ -137,6 +137,7 @@ static inline bool hctx_may_queue(struct blk_mq_hw_ctx *hctx, static int __bt_get_word(struct blk_align_bitmap *bm, unsigned int last_tag) { int tag, org_last_tag, end; + bool wrap = last_tag != 0; org_last_tag = last_tag; end = bm->depth; @@ -148,8 +149,9 @@ restart: * We started with an offset, start from 0 to * exhaust the map. */ - if (org_last_tag && last_tag) { - end = last_tag; + if (wrap) { + wrap = false; + end = org_last_tag; last_tag = 0; goto restart; }