diff options
author | Wu Bo <wubo40@huawei.com> | 2021-05-19 08:01:10 +0300 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2021-05-19 09:33:42 +0300 |
commit | 03504e3b54cc8118cc26c064e60a0b00c2308708 (patch) | |
tree | a7981c1c11732854f82dfcb3ab23e060857f6410 /drivers/nvme | |
parent | fec356a61aa3d3a66416b4321f1279e09e0f256f (diff) | |
download | linux-03504e3b54cc8118cc26c064e60a0b00c2308708.tar.xz |
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: 3a85a5de29ea ("nvme-loop: add a NVMe loopback host driver")
Signed-off-by: Wu Bo <wubo40@huawei.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'drivers/nvme')
-rw-r--r-- | drivers/nvme/target/loop.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/nvme/target/loop.c b/drivers/nvme/target/loop.c index 74b3b150e1a5..cb30cb942e1d 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); |