public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
From: Wu Bo <wubo40@huawei.com>
To: <hch@lst.de>, <sagi@grimberg.me>, <chaitanya.kulkarni@wdc.com>,
	<kbusch@kernel.org>, <amit.engel@dell.com>,
	<linux-nvme@lists.infradead.org>,  <linux-kernel@vger.kernel.org>
Cc: <linfeilong@huawei.com>, <wubo40@huawei.com>
Subject: [PATCH 2/2] nvme-loop: Fix memory leak in nvme_loop_create_ctrl()
Date: Wed, 19 May 2021 13:01:10 +0800	[thread overview]
Message-ID: <1621400470-593256-3-git-send-email-wubo40@huawei.com> (raw)
In-Reply-To: <1621400470-593256-1-git-send-email-wubo40@huawei.com>

Form: Wu Bo <wubo40@huawei.com>

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 <wubo40@huawei.com>
---
 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


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

  parent reply	other threads:[~2021-05-19  4:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-19  5:01 [PATCH 0/2] nvmet: Fix memory leak when create ctrl fails Wu Bo
2021-05-19  5:01 ` [PATCH 1/2] nvmet: Fix memory leak in nvmet_alloc_ctrl() Wu Bo
2021-05-19  4:45   ` Chaitanya Kulkarni
2021-05-19  5:01 ` Wu Bo [this message]
2021-05-19  4:48   ` [PATCH 2/2] nvme-loop: Fix memory leak in nvme_loop_create_ctrl() Chaitanya Kulkarni
2021-05-19  6:35 ` [PATCH 0/2] nvmet: Fix memory leak when create ctrl fails Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1621400470-593256-3-git-send-email-wubo40@huawei.com \
    --to=wubo40@huawei.com \
    --cc=amit.engel@dell.com \
    --cc=chaitanya.kulkarni@wdc.com \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linfeilong@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox