Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1715654pxj; Wed, 19 May 2021 12:11:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxx6PKWyhijJnyHG8Ew3iG7bN9IESBG6ES0gEG2eVjWfoHudUJsz+DxHVnL+u7ZjBWCbgw X-Received: by 2002:a17:907:2855:: with SMTP id el21mr661722ejc.153.1621451472379; Wed, 19 May 2021 12:11:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621451472; cv=none; d=google.com; s=arc-20160816; b=Vb1ifNBZJV1jDd8uZm+q2B/yTW2I3WZbaTHEudLswPmcHbUWShSlPH294i25im76Dx h5nZISMBffMc4hMYpu7GeKFK/csaEgrop9vwro9OOs65Gyz6pg3jdaNWb6Pcv6hREb1C YBH0XNui0wq83zS+c4xZrWeR2KNx8WUgOXVsJwS0RoXtib0D8OR5LJd2NfVwLS8P7qm4 +7IqRp1eUJfC/Hfg/E7bAI4ZLJCCwDwt/7lsqLRYKsrzU5oU73Y3dj9dsHK+r+8cwS0C R3WbUV8faxMMnwAyIFnTDumD+czfoBmWLlZAokiYc3NSVD5sF4cdNRU7B7yA94ocaqrW j90Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=xilD0w6nqadGMUKyDKwGtRXRYNtwndQAyAgBdMh4yPU=; b=qHeKv6R1ey96TrzlVjaLJF9Lewv3FG7xzzc/X5jbR1lX/cTiPWrl1EKhp3/4IHzejl m1ksxYUBd+0+2Bx4UVTuZnguaIJisw6bhZuPulMiFU9MmYLU3OQh5kNiWUEVHawdYxrp G6kwp0y2YvEZIVlV6shYXuVDzNBRyaIVS8uviIwyk6r3FJcZmDPHxlbo6mJkxQFW16Ql C0GPfgQOkCRWKrBPzSBNKobhrlw3IPRQ0niCf+LztNnJSdGrmJ7vGmtc26o49gxu6/s4 vRekH7NDx1M4hIOAqbmfd55i3/X4xtO5lS07+vmiiQpEFqRr7JliAxA8xUdbk7rzP3W0 ZKxw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e7si87436edk.255.2021.05.19.12.10.48; Wed, 19 May 2021 12:11:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353317AbhESEgr (ORCPT + 99 others); Wed, 19 May 2021 00:36:47 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:3414 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243947AbhESEgk (ORCPT ); Wed, 19 May 2021 00:36:40 -0400 Received: from dggems705-chm.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FlKjF6t2zzCt01; Wed, 19 May 2021 12:32:33 +0800 (CST) Received: from dggpeml500019.china.huawei.com (7.185.36.137) by dggems705-chm.china.huawei.com (10.3.19.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 19 May 2021 12:35:20 +0800 Received: from huawei.com (10.175.124.27) by dggpeml500019.china.huawei.com (7.185.36.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 19 May 2021 12:35:19 +0800 From: Wu Bo To: , , , , , , CC: , Subject: [PATCH 2/2] nvme-loop: Fix memory leak in nvme_loop_create_ctrl() Date: Wed, 19 May 2021 13:01:10 +0800 Message-ID: <1621400470-593256-3-git-send-email-wubo40@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1621400470-593256-1-git-send-email-wubo40@huawei.com> References: <1621400470-593256-1-git-send-email-wubo40@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500019.china.huawei.com (7.185.36.137) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Form: Wu Bo When creating loop ctrl in nvme_loop_create_ctrl(), if nvme_init_ctrl() returns fails, the loop ctrl should be freed before jumps to the "out" label. Fixes: 3a85a5de29ea7 ("nvme-loop: add a NVMe loopback host driver") Signed-off-by: Wu Bo --- drivers/nvme/target/loop.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/target/loop.c b/drivers/nvme/target/loop.c index 74b3b15..cb30cb9 100644 --- a/drivers/nvme/target/loop.c +++ b/drivers/nvme/target/loop.c @@ -590,8 +590,10 @@ static struct nvme_ctrl *nvme_loop_create_ctrl(struct device *dev, ret = nvme_init_ctrl(&ctrl->ctrl, dev, &nvme_loop_ctrl_ops, 0 /* no quirks, we're perfect! */); - if (ret) + if (ret) { + kfree(ctrl); goto out; + } if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING)) WARN_ON_ONCE(1); -- 1.8.3.1