blk-mq: Fix memory leak in error handling
authorJes Sorensen <jsorensen@fb.com>
Fri, 19 Apr 2019 20:35:44 +0000 (16:35 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 22 Jun 2019 06:09:14 +0000 (08:09 +0200)
[ Upstream commit 41de54c64811bf087c8464fdeb43c6ad8be2686b ]

If blk_mq_init_allocated_queue() fails, make sure to free the poll
stat callback struct allocated.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
block/blk-mq.c

index 11efca3534ad36105d2fd4b9c5e7ab2076922747..00b826399228b04339e5632f74263cd12f6d0d91 100644 (file)
@@ -2846,7 +2846,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);
@@ -2907,6 +2907,9 @@ err_hctxs:
        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);