Skip to content

Commit

Permalink
blk-mq: fix dereference of rq->mq_ctx if allocation fails
Browse files Browse the repository at this point in the history
If __GFP_WAIT isn't set and we fail allocating, when we go
to drop the reference on the ctx, we will attempt to dereference
the NULL rq. Fix that.

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Jeff Moyer authored and Jens Axboe committed Dec 3, 2013
1 parent e345d76 commit 959a35f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions block/blk-mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,12 @@ static struct request *blk_mq_alloc_request_pinned(struct request_queue *q,
if (rq) {
blk_mq_rq_ctx_init(q, ctx, rq, rw);
break;
} else if (!(gfp & __GFP_WAIT))
break;
}

blk_mq_put_ctx(ctx);
if (!(gfp & __GFP_WAIT))
break;

__blk_mq_run_hw_queue(hctx);
blk_mq_wait_for_tags(hctx->tags);
} while (1);
Expand All @@ -222,7 +224,8 @@ struct request *blk_mq_alloc_request(struct request_queue *q, int rw,
return NULL;

rq = blk_mq_alloc_request_pinned(q, rw, gfp, reserved);
blk_mq_put_ctx(rq->mq_ctx);
if (rq)
blk_mq_put_ctx(rq->mq_ctx);
return rq;
}

Expand All @@ -235,7 +238,8 @@ struct request *blk_mq_alloc_reserved_request(struct request_queue *q, int rw,
return NULL;

rq = blk_mq_alloc_request_pinned(q, rw, gfp, true);
blk_mq_put_ctx(rq->mq_ctx);
if (rq)
blk_mq_put_ctx(rq->mq_ctx);
return rq;
}
EXPORT_SYMBOL(blk_mq_alloc_reserved_request);
Expand Down

0 comments on commit 959a35f

Please sign in to comment.