Skip to content

Commit

Permalink
blk-mq: Fix memory leak in error handling
Browse files Browse the repository at this point in the history
If blk_mq_init_allocated_queue() fails, make sure to free the poll
stat callback struct allocated.

Signed-off-by: Jes Sorensen <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Jes Sorensen authored and axboe committed May 29, 2019
1 parent fe20086 commit 41de54c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion block/blk-mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -2865,7 +2865,7 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
goto err_exit;

if (blk_mq_alloc_ctxs(q))
goto err_exit;
goto err_poll;

/* init q->mq_kobj and sw queues' kobjects */
blk_mq_sysfs_init(q);
Expand Down Expand Up @@ -2929,6 +2929,9 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
kfree(q->queue_hw_ctx);
err_sys_init:
blk_mq_sysfs_deinit(q);
err_poll:
blk_stat_free_callback(q->poll_cb);
q->poll_cb = NULL;
err_exit:
q->mq_ops = NULL;
return ERR_PTR(-ENOMEM);
Expand Down

0 comments on commit 41de54c

Please sign in to comment.