From: Chaitanya Kulkarni Date: Tue, 6 Oct 2020 23:36:47 +0000 (-0700) Subject: nvme-core: put ctrl ref when module ref get fail X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=4bab69093044ca81f394bd0780be1b71c5a4d308;p=linux.git nvme-core: put ctrl ref when module ref get fail 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 Reviewed-by: Logan Gunthorpe Signed-off-by: Christoph Hellwig --- diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 53c93836c7c6f..ca516d68f14fc 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -3265,8 +3265,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;