[PATCH V2 09/12] nvmet: fix nvme module ref count Oops

Logan Gunthorpe logang at deltatee.com
Tue Sep 1 13:23:42 EDT 2020



On 2020-08-31 4:27 p.m., Chaitanya Kulkarni wrote:
> In the passthru controller enable path current code doesn't take the
> reference to the passthru ctrl module. Which produces following Oops :-

Seems like this change should be justifiable without passthru, simply by
 opening the char device and removing the module. The tag in the title
should certainly be nvme, not nvmet...

> We fix that by taking a module ref count in nvme_dev_open() and release
> that ref count in nvme_dev_release().
> 
> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
> ---
>  drivers/nvme/host/core.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index f82c6a283b15..c940f49a30bf 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);

Is the error print necessary? We don't print any errors in the similar
path in nvme_open()...

Logan



More information about the Linux-nvme mailing list