From d397dacbaa443b1cecb8b359e0e71089b0f70303 Mon Sep 17 00:00:00 2001 From: Chaitanya Kulkarni Date: Wed, 4 Nov 2020 15:28:19 +0800 Subject: [PATCH] nvme-core: put ctrl ref when module ref get fail stable inclusion from linux-4.19.151 commit b6df5afc3d81e34d32f0b092d59b7fe8915d824b -------------------------------- 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 Reviewed-by: Logan Gunthorpe Signed-off-by: Christoph Hellwig Signed-off-by: Greg Kroah-Hartman Signed-off-by: Yang Yingliang --- drivers/nvme/host/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 8b478e402f62..e97989e91866 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -2585,8 +2585,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; -- GitLab