* [PATCH] nvme-core: put ctrl ref when module ref get fail
@ 2020-10-06 23:36 Chaitanya Kulkarni
2020-10-07 0:20 ` Logan Gunthorpe
0 siblings, 1 reply; 3+ messages in thread
From: Chaitanya Kulkarni @ 2020-10-06 23:36 UTC (permalink / raw)
To: linux-nvme; +Cc: kbusch, hch, Chaitanya Kulkarni, sagi
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 <chaitanya.kulkarni@wdc.com>
---
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 c20ce8eabe82..56e2a22e8a02 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3158,8 +3158,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;
--
2.22.1
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] nvme-core: put ctrl ref when module ref get fail
2020-10-06 23:36 [PATCH] nvme-core: put ctrl ref when module ref get fail Chaitanya Kulkarni
@ 2020-10-07 0:20 ` Logan Gunthorpe
2020-10-07 5:55 ` Christoph Hellwig
0 siblings, 1 reply; 3+ messages in thread
From: Logan Gunthorpe @ 2020-10-07 0:20 UTC (permalink / raw)
To: Chaitanya Kulkarni, linux-nvme; +Cc: kbusch, hch, sagi
On 2020-10-06 5:36 p.m., Chaitanya Kulkarni wrote:
> 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 <chaitanya.kulkarni@wdc.com>
I guess I missed this too in my review of that patch. Nice catch.
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
> ---
> 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 c20ce8eabe82..56e2a22e8a02 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -3158,8 +3158,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;
>
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] nvme-core: put ctrl ref when module ref get fail
2020-10-07 0:20 ` Logan Gunthorpe
@ 2020-10-07 5:55 ` Christoph Hellwig
0 siblings, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2020-10-07 5:55 UTC (permalink / raw)
To: Chaitanya Kulkarni, Logan Gunthorpe; +Cc: kbusch, hch, linux-nvme, sagi
Applied to nvme-5.9.
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-10-07 5:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-06 23:36 [PATCH] nvme-core: put ctrl ref when module ref get fail Chaitanya Kulkarni
2020-10-07 0:20 ` Logan Gunthorpe
2020-10-07 5:55 ` Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).