diff mbox

blk-mq: free callback if error occurs in blk_mq_init_allocated_queue

Message ID 728065d3-0100-514a-70b0-66b1cfe85480@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Joseph Qi June 1, 2017, 5:02 a.m. UTC
From: Joseph Qi <qijiang.qj@alibaba-inc.com>

If error occurs, we have to free the allocated callback in
blk_mq_init_allocated_queue to avoid memory leaking.

Fixes: 34dbad5d26e2 ("blk-stat: convert to callback-based statistics reporting")
Signed-off-by: Joseph Qi <qijiang.qj@alibaba-inc.com>
---
 block/blk-mq.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Omar Sandoval June 1, 2017, 7:12 p.m. UTC | #1
On Thu, Jun 01, 2017 at 01:02:40PM +0800, Joseph Qi wrote:
> From: Joseph Qi <qijiang.qj@alibaba-inc.com>
> 
> If error occurs, we have to free the allocated callback in
> blk_mq_init_allocated_queue to avoid memory leaking.

Nak. If blk_mq_init_allocated_queue() fails, we call blk_cleanup_queue()
which will do this.
diff mbox

Patch

diff --git a/block/blk-mq.c b/block/blk-mq.c
index f2224ffd..50b5d7b 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2273,7 +2273,7 @@  struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
 
 	q->queue_ctx = alloc_percpu(struct blk_mq_ctx);
 	if (!q->queue_ctx)
-		goto err_exit;
+		goto err_poll_cb;
 
 	/* init q->mq_kobj and sw queues' kobjects */
 	blk_mq_sysfs_init(q);
@@ -2346,6 +2346,8 @@  struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
 	kfree(q->queue_hw_ctx);
 err_percpu:
 	free_percpu(q->queue_ctx);
+err_poll_cb:
+	blk_stat_free_callback(q->poll_cb);
 err_exit:
 	q->mq_ops = NULL;
 	return ERR_PTR(-ENOMEM);