Skip to content

Commit 03504e3

Browse files
Wu BoChristoph Hellwig
authored andcommitted
nvme-loop: fix memory leak in nvme_loop_create_ctrl()
When creating loop ctrl in nvme_loop_create_ctrl(), if nvme_init_ctrl() fails, the loop ctrl should be freed before jumping to the "out" label. Fixes: 3a85a5d ("nvme-loop: add a NVMe loopback host driver") Signed-off-by: Wu Bo <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent fec356a commit 03504e3

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/nvme/target/loop.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,10 @@ static struct nvme_ctrl *nvme_loop_create_ctrl(struct device *dev,
590590

591591
ret = nvme_init_ctrl(&ctrl->ctrl, dev, &nvme_loop_ctrl_ops,
592592
0 /* no quirks, we're perfect! */);
593-
if (ret)
593+
if (ret) {
594+
kfree(ctrl);
594595
goto out;
596+
}
595597

596598
if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING))
597599
WARN_ON_ONCE(1);

0 commit comments

Comments
 (0)