]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
nvme-core: put ctrl ref when module ref get fail
authorChaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Tue, 6 Oct 2020 23:36:47 +0000 (16:36 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 14 Oct 2020 09:55:48 +0000 (11:55 +0200)
commit 4bab69093044ca81f394bd0780be1b71c5a4d308 upstream.

When try_module_get() fails in the nvme_dev_open() it returns without
releasing the ctrl reference which was taken earlier.

Put the ctrl reference which is taken before calling the
try_module_get() in the error return code path.

Fixes: 52a3974feb1a "nvme-core: get/put ctrl and transport module in nvme_dev_open/release()"
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/nvme/host/core.c

index 69165a8f7c1f0a2db52d0c990d40b231b4ab43e6..a9d5682cdea5499159c2f38bad565aecfb9b2457 100644 (file)
@@ -3061,8 +3061,10 @@ static int nvme_dev_open(struct inode *inode, struct file *file)
        }
 
        nvme_get_ctrl(ctrl);
-       if (!try_module_get(ctrl->ops->module))
+       if (!try_module_get(ctrl->ops->module)) {
+               nvme_put_ctrl(ctrl);
                return -EINVAL;
+       }
 
        file->private_data = ctrl;
        return 0;