Skip to contentSkip to conversation

nvmet: Fix memory leak when create ctrl fails

PATCH Applied Wu Bo 3 participants 6 messages May 19, 2021

Subsystems (2)
lore
Share & tools
lore

Wu Bo

author
#0 lore raw

cover nvmet: Fix memory leak when create ctrl fails

Hi,

This series of patches to fix the issuse of memory leak when creating ctrl fails.

Wu Bo (2):
nvmet: Fix memory leak in nvmet_alloc_ctrl()
nvme-loop: Fix memory leak in nvme_loop_create_ctrl()

 drivers/nvme/target/core.c | 2 +-
 drivers/nvme/target/loop.c | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 1/2 nvmet: Fix memory leak in nvmet_alloc_ctrl()

From: Wu Bo <[email protected]>

When creating ctrl in nvmet_alloc_ctrl(), if the cntlid_min is large than cntlid_max of the subsystem, and jumps to "out_free_changed_ns_list" label, but the ctrl->sqs lack of be freed. So to fix this issuse modify jumps to "out_free_sqs" label.

Fixes 94a39d61f80f ("nvmet: make ctrl-id configurable")
Fixes 6d65aeab7bf6e ("nvmet: remove unused ctrl->cqs")
---
 drivers/nvme/target/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/core.c +1 -1
index 25cc2ee..1853db3 100644
@@ -1372,7 +1372,7 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn,
 		goto out_free_changed_ns_list;
 
 	if (subsys->cntlid_min > subsys->cntlid_max)
-		goto out_free_changed_ns_list;
+		goto out_free_sqs;
 
 	ret = ida_simple_get(&cntlid_ida,
 			     subsys->cntlid_min, subsys->cntlid_max,
Signature · 1 line
1.8.3.1
author
#3 lore raw

PATCH 2/2 nvme-loop: Fix memory leak in nvme_loop_create_ctrl()

In reply to Wu Bo

Form: Wu Bo <[email protected]>

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")
---
 drivers/nvme/target/loop.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/nvme/target/loop.c +3 -1
index 74b3b15..cb30cb9 100644
@@ -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);
Signature · 1 line
1.8.3.1
#4 lore raw

Re: [PATCH 2/2] nvme-loop: Fix memory leak in nvme_loop_create_ctrl()

Sent from my iPhone

Quoted 7 lines · 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")

Please make sure comit logs lines filled up 72 char and Commit hash is 12 digit.

See the commit logs in the tree to get the better idea.

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme