Skip to content

Commit

Permalink
nvme-core: put ctrl ref when module ref get fail
Browse files Browse the repository at this point in the history
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: 52a3974 "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>
  • Loading branch information
Chaitanya Kulkarni authored and Christoph Hellwig committed Oct 7, 2020
1 parent 6d53a9f commit 4bab690
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/nvme/host/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4bab690

Please sign in to comment.