From patchwork Fri Nov 27 08:37:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minfei Huang X-Patchwork-Id: 7711741 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 56A059F1D3 for ; Fri, 27 Nov 2015 08:35:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7C66520552 for ; Fri, 27 Nov 2015 08:35:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3E6CA20494 for ; Fri, 27 Nov 2015 08:35:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753871AbbK0If5 (ORCPT ); Fri, 27 Nov 2015 03:35:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48578 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751504AbbK0If4 (ORCPT ); Fri, 27 Nov 2015 03:35:56 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id BF377571D; Fri, 27 Nov 2015 08:35:55 +0000 (UTC) Received: from localhost (unused [10.66.128.25] (may be forged)) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tAR8Zreo026111; Fri, 27 Nov 2015 03:35:54 -0500 From: Minfei Huang To: axboe@kernel.dk Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, mhuang@redhat.com, Minfei Huang Subject: [PATCH] blk-mg-tag: Make tag's codeflow more reasonably during initializing Date: Fri, 27 Nov 2015 16:37:48 +0800 Message-Id: <1448613468-11708-1-git-send-email-mhuang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Minfei Huang It might be more reasonable to cleanup all of the allocations in same function, if there is a fatal. Thus we can make function more independency to export it. For this patch, variant tag will be allocated in blk_mq_init_tags, and it will be freed in same function, if there is an error during initializing the tag. What the blk_mq_init_bitmap_tags does is to allocate bitmap. Signed-off-by: Minfei Huang --- block/blk-mq-tag.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c index a07ca34..7a1d9a8 100644 --- a/block/blk-mq-tag.c +++ b/block/blk-mq-tag.c @@ -596,23 +596,24 @@ static void bt_free(struct blk_mq_bitmap_tags *bt) kfree(bt->bs); } -static struct blk_mq_tags *blk_mq_init_bitmap_tags(struct blk_mq_tags *tags, - int node, int alloc_policy) +static int blk_mq_init_bitmap_tags(struct blk_mq_tags *tags, + int node, int alloc_policy) { + int ret = 0; unsigned int depth = tags->nr_tags - tags->nr_reserved_tags; tags->alloc_policy = alloc_policy; - if (bt_alloc(&tags->bitmap_tags, depth, node, false)) - goto enomem; - if (bt_alloc(&tags->breserved_tags, tags->nr_reserved_tags, node, true)) - goto enomem; + ret = bt_alloc(&tags->bitmap_tags, depth, node, false); + if (ret) + goto out; - return tags; -enomem: - bt_free(&tags->bitmap_tags); - kfree(tags); - return NULL; + ret = bt_alloc(&tags->breserved_tags, + tags->nr_reserved_tags, node, true); + if (ret) + bt_free(&tags->bitmap_tags); +out: + return ret; } struct blk_mq_tags *blk_mq_init_tags(unsigned int total_tags, @@ -638,7 +639,12 @@ struct blk_mq_tags *blk_mq_init_tags(unsigned int total_tags, tags->nr_tags = total_tags; tags->nr_reserved_tags = reserved_tags; - return blk_mq_init_bitmap_tags(tags, node, alloc_policy); + if (blk_mq_init_bitmap_tags(tags, node, alloc_policy)) { + kfree(tags); + return NULL; + } + + return tags; } void blk_mq_free_tags(struct blk_mq_tags *tags)