]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
nvme-loop: fix memory leak in nvme_loop_create_ctrl()
authorWu Bo <wubo40@huawei.com>
Wed, 19 May 2021 05:01:10 +0000 (13:01 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 May 2021 10:59:04 +0000 (12:59 +0200)
[ Upstream commit 03504e3b54cc8118cc26c064e60a0b00c2308708 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/nvme/target/loop.c

index 3e189e753bcf5add622d26dad4dcf8527b08d98b..14913a4588eccc71cc7dc5bfec279d2d0bbd04ba 100644 (file)
@@ -588,8 +588,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);