From patchwork Wed Aug 19 15:20:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 247981 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:522:0:0:0:0 with SMTP id h2csp561332ils; Wed, 19 Aug 2020 08:26:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwj2N0SWcUQRSywGImxKxdG5W0WmTDV8PTmcpjJiWXtWuBYpIIgiN5qy8LNU6yXcUOhUAyQ X-Received: by 2002:a17:906:248f:: with SMTP id e15mr24325264ejb.296.1597850809304; Wed, 19 Aug 2020 08:26:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597850809; cv=none; d=google.com; s=arc-20160816; b=i2yhFQlhBnhph5fuhQnXMb6bK10977fJLIo+7DmrMDpxCE8aV5/IZOd6AJZhdP5L1J VDSJ0Ssz52L0+6B0K5yyWM/PzDZWLk34PhUahFYxTHxVr1aBWQax5HMJejE8iykVwH5W Vy3iJCz5c7+QCjs0ZrLMKBknxll0IEhNO+byTpaKKGrUCyAFRLmN4EGsfeKl6joOsUp2 iYAy/ViFFzMg/LanM52yZ7hXaMla7tR5U4LYIXHqOIhldqxLc/yBY9TOHhpgFhZdbS0O wTz9lxrEruW02uAwj9HQzCuhXD9FMm1YqW++P7D9OChcFVFfGDh/5xA5Get1BIf6Hltx KlbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=j4rib+DnOW4ZSL8etEqm7hiq0Kbo+rpXDgtMAV7rCWQ=; b=IoAsHb30Llpf0i7FVcZUftr771hzVITEFbvftpb5k+mu8y4e+WGyRTLc5pZVzQQmfT +nCyRLZ3DqmwyBuWbcOTGaoYFMNDUxhdrgXIFuHR+C30aX3ci+5ZDerbKm/Tj1nQ/tux ksWK9DKCn9KNJkOfqzO3ndfODDqLMLY4PtGyb9sXU6e3wFQZjBkZy55szuN1Fosuz3dH O6QYOKCdZCSdQ2ypnTAW3sPybVJE8pViksvRkRHhpedhBk0fKgphHdLlWurGr+3mIv1a 6DefHkZj2rBZN7nuNKUAWrbMYUPGaTK4nTBpc7kkCHkyjb4kN/ePuE8Sfs/kMsTQ7bOM z/Mw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e5si15932517ejc.182.2020.08.19.08.26.49 for ; Wed, 19 Aug 2020 08:26:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728834AbgHSP0p (ORCPT ); Wed, 19 Aug 2020 11:26:45 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:38868 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726747AbgHSP0m (ORCPT ); Wed, 19 Aug 2020 11:26:42 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 73BF6DEDDFE7CC69C53B; Wed, 19 Aug 2020 23:24:58 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.487.0; Wed, 19 Aug 2020 23:24:48 +0800 From: John Garry To: , , , , , , , , , , CC: , , , , , , , , John Garry Subject: [PATCH v8 03/18] blk-mq: Free tags in blk_mq_init_tags() upon error Date: Wed, 19 Aug 2020 23:20:21 +0800 Message-ID: <1597850436-116171-4-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1597850436-116171-1-git-send-email-john.garry@huawei.com> References: <1597850436-116171-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Hannes Reinecke Since the tags are allocated in blk_mq_init_tags(), it's better practice to free in that same function upon error, rather than a callee which is to init the bitmap tags (blk_mq_init_tags()). Signed-off-by: Hannes Reinecke [jpg: Split from an earlier patch with a new commit message] Signed-off-by: John Garry --- block/blk-mq-tag.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) -- 2.26.2 diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c index 32d82e23b095..c2c9f369d777 100644 --- a/block/blk-mq-tag.c +++ b/block/blk-mq-tag.c @@ -429,24 +429,22 @@ static int bt_alloc(struct sbitmap_queue *bt, unsigned int depth, node); } -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) { unsigned int depth = tags->nr_tags - tags->nr_reserved_tags; bool round_robin = alloc_policy == BLK_TAG_ALLOC_RR; if (bt_alloc(&tags->bitmap_tags, depth, round_robin, node)) - goto free_tags; + return -ENOMEM; if (bt_alloc(&tags->breserved_tags, tags->nr_reserved_tags, round_robin, node)) goto free_bitmap_tags; - return tags; + return 0; free_bitmap_tags: sbitmap_queue_free(&tags->bitmap_tags); -free_tags: - kfree(tags); - return NULL; + return -ENOMEM; } struct blk_mq_tags *blk_mq_init_tags(unsigned int total_tags, @@ -467,7 +465,11 @@ 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) < 0) { + kfree(tags); + return NULL; + } + return tags; } void blk_mq_free_tags(struct blk_mq_tags *tags)