aboutsummaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
authorBart Van Assche <bvanassche@acm.org>2014-12-09 10:58:11 -0500
committerJens Axboe <axboe@fb.com>2014-12-09 11:07:14 -0500
commit9e98e9d7cf6e9d2ec1cce45e8d5ccaf3f9b386f3 (patch)
tree9bf1d9e63d5f19088be8a6bfe8e141f6ab887bb4 /block
parent45a9c9d909b24c6ad0e28a7946e7486e73010319 (diff)
blk-mq: Avoid that __bt_get_word() wraps multiple times
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 <bvanassche@acm.org> Cc: Christoph Hellwig <hch@lst.de> Cc: Robert Elliott <elliott@hp.com> Cc: Ming Lei <ming.lei@canonical.com> Cc: Alexander Gordeev <agordeev@redhat.com> Cc: <stable@vger.kernel.org> # v3.13+ Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'block')
-rw-r--r--block/blk-mq-tag.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c
index bab4bff15f42..0f5e22a7971f 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,
137static int __bt_get_word(struct blk_align_bitmap *bm, unsigned int last_tag) 137static int __bt_get_word(struct blk_align_bitmap *bm, unsigned int last_tag)
138{ 138{
139 int tag, org_last_tag, end; 139 int tag, org_last_tag, end;
140 bool wrap = last_tag != 0;
140 141
141 org_last_tag = last_tag; 142 org_last_tag = last_tag;
142 end = bm->depth; 143 end = bm->depth;
@@ -148,8 +149,9 @@ restart:
148 * We started with an offset, start from 0 to 149 * We started with an offset, start from 0 to
149 * exhaust the map. 150 * exhaust the map.
150 */ 151 */
151 if (org_last_tag && last_tag) { 152 if (wrap) {
152 end = last_tag; 153 wrap = false;
154 end = org_last_tag;
153 last_tag = 0; 155 last_tag = 0;
154 goto restart; 156 goto restart;
155 } 157 }