Re: [PATCH 4.19 17/38] nvme-core: get/put ctrl and transport module in nvme_dev_open/release()
From: Pavel Machek
Date: Mon Oct 05 2020 - 16:58:08 EST
Hi!
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 33dad9774da01..9ea3d8e611005 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -2605,10 +2605,24 @@ static int nvme_dev_open(struct inode *inode, struct file *file)
> return -EWOULDBLOCK;
> }
>
> + nvme_get_ctrl(ctrl);
> + if (!try_module_get(ctrl->ops->module))
> + return -EINVAL;
This needs to do nvme_put_ctrl(ctrl); before returning, right?
Otherwise we leak the reference.
Plus, I'm not sure EINVAL is right error return. EBUSY?
Signed-off-by: Pavel Machek (CIP) <pavel@xxxxxxx>
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 9ea3d8e61100..01c36f3dd87f 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2606,8 +2606,10 @@ static int nvme_dev_open(struct inode *inode, struct file *file)
}
nvme_get_ctrl(ctrl);
- if (!try_module_get(ctrl->ops->module))
- return -EINVAL;
+ if (!try_module_get(ctrl->ops->module)) {
+ nvme_put_ctrl(ctrl);
+ return -EBUSY;
+ }
file->private_data = ctrl;
return 0;
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Attachment:
signature.asc
Description: Digital signature