Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753585AbbFDOjZ (ORCPT ); Thu, 4 Jun 2015 10:39:25 -0400 Received: from mail-oi0-f43.google.com ([209.85.218.43]:33643 "EHLO mail-oi0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752463AbbFDOjU (ORCPT ); Thu, 4 Jun 2015 10:39:20 -0400 From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: Ming Lei , Mike Snitzer Subject: [RFC PATCH] blk-mq: fix failure case of blk_mq_init_allocated_queue Date: Thu, 4 Jun 2015 22:39:01 +0800 Message-Id: <1433428741-24931-1-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2133 Lines: 68 Generally blk_cleanup_queue() is called for cleaning up the request queue, just like what blk_mq_init_queue() does, so blk_mq_init_allocated_queue() should return failue simply in case blk_mq_init_hw_queues() fails, otherwise double-free may be triggered. Cc: Mike Snitzer Signed-off-by: Ming Lei --- Mike, DM may need to follow the rule, otherwise the request queue can't be reused after failure is returned from blk_mq_init_allocated_queue() since both wrong queue type and memory leak can be caused . Or do blk_mq_init_allocated_queue() need to recover the queue to previous state in case of failure? block/blk-mq.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 594eea0..d68b1a3 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -1732,11 +1732,8 @@ static int blk_mq_init_hw_queues(struct request_queue *q, if (i == q->nr_hw_queues) return 0; - /* - * Init failed - */ - blk_mq_exit_hw_queues(q, set, i); - + /* Let blk_cleanup_queue() handle the partial initialization */ + q->nr_hw_queues = i; return 1; } @@ -1920,6 +1917,10 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set) } EXPORT_SYMBOL(blk_mq_init_queue); +/* + * In case of failure returned from this function, + * blk_cleanup_queue() has to be called for cleanup. + */ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set, struct request_queue *q) { @@ -2004,8 +2005,9 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set, blk_mq_init_cpu_queues(q, set->nr_hw_queues); + /* blk_cleanup_queue() will handle the failure */ if (blk_mq_init_hw_queues(q, set)) - goto err_hctxs; + return ERR_PTR(-ENOMEM); mutex_lock(&all_q_mutex); list_add_tail(&q->all_q_node, &all_q_list); -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/