[PATCH 3/3] nvme-core: fix nvme module ref count Oops

Logan Gunthorpe logang at deltatee.com
Fri Sep 4 11:57:02 EDT 2020



On 2020-09-03 8:39 p.m., Chaitanya Kulkarni wrote:
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index a1707afcb710..8445293c74e3 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -3263,6 +3263,12 @@ static int nvme_dev_open(struct inode *inode, struct file *file)
>  
>  	file->private_data = ctrl;
>  	nvme_get_ctrl(ctrl);
> +	if (!try_module_get(ctrl->ops->module)) {
> +		pr_err("try_module_get failed for cntlid 0x%x\n", ctrl->cntlid);
> +		nvme_put_ctrl(ctrl);
> +		return -EINVAL;
> +	}
> +
>  	return 0;
>  }
>  
> @@ -3271,6 +3277,7 @@ static int nvme_dev_release(struct inode *inode, struct file *file)
>  	struct nvme_ctrl *ctrl =
>  		container_of(inode->i_cdev, struct nvme_ctrl, cdev);
>  
> +	module_put(ctrl->ops->module);
>  	nvme_put_ctrl(ctrl);
>  	return 0;
>  }

I'd probably just fold these changes into the previous patch. When we
get a reference to the controller we must also get a reference to the
transport module. So no sense getting the different references in
different patches.

Logan



More information about the Linux-nvme mailing list