Message ID | 20201005142109.502047700@linuxfoundation.org |
---|---|
State | Superseded |
Headers | show |
Series | None | expand |
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@denx.de> 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;
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; + file->private_data = ctrl; return 0; } +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; +} + static int nvme_dev_user_cmd(struct nvme_ctrl *ctrl, void __user *argp) { struct nvme_ns *ns; @@ -2669,6 +2683,7 @@ static long nvme_dev_ioctl(struct file *file, unsigned int cmd, static const struct file_operations nvme_dev_fops = { .owner = THIS_MODULE, .open = nvme_dev_open, + .release = nvme_dev_release, .unlocked_ioctl = nvme_dev_ioctl, .compat_ioctl = nvme_dev_ioctl, };