Skip to content

Commit

Permalink
blk-mq: Fix memory leak in blk_mq_init_allocated_queue error handling
Browse files Browse the repository at this point in the history
If blk_mq_init_allocated_queue->elevator_init_mq fails, need to release
the previously requested resources.

Fixes: d348499 ("blk-mq-sched: allow setting of default IO scheduler")
Signed-off-by: zhengbin <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
zhengbin13 authored and axboe committed Aug 12, 2019
1 parent 52f6f9d commit 73d9c8d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions block/blk-mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -2846,6 +2846,8 @@ static unsigned int nr_hw_queues(struct blk_mq_tag_set *set)
struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
struct request_queue *q)
{
int ret = -ENOMEM;

/* mark the queue as mq asap */
q->mq_ops = set->ops;

Expand Down Expand Up @@ -2907,17 +2909,18 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
blk_mq_map_swqueue(q);

if (!(set->flags & BLK_MQ_F_NO_SCHED)) {
int ret;

ret = elevator_init_mq(q);
if (ret)
return ERR_PTR(ret);
goto err_tag_set;
}

return q;

err_tag_set:
blk_mq_del_queue_tag_set(q);
err_hctxs:
kfree(q->queue_hw_ctx);
q->nr_hw_queues = 0;
err_sys_init:
blk_mq_sysfs_deinit(q);
err_poll:
Expand Down

0 comments on commit 73d9c8d

Please sign in to comment.