All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvme: fix potential memory leaks in nvme_cdev_add
@ 2021-05-21  7:32 ` Guoqing Jiang
  2021-05-21 20:19   ` Sagi Grimberg
                     ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Guoqing Jiang @ 2021-05-21  7:32 UTC (permalink / raw)
  To: kbusch, axboe, hch, sagi, javier.gonz, minwoo.im.dev; +Cc: linux-nvme

We need to call put_device if cdev_device_add failed, otherwise
kmemleak has below report.

[<0000000024c71758>] kmem_cache_alloc_trace+0x233/0x480
[<00000000ad2813ed>] device_add+0x7ff/0xe10
[<0000000035bc54c4>] cdev_device_add+0x72/0xa0
[<000000006c9aa1e8>] nvme_cdev_add+0xa9/0xf0 [nvme_core]
[<000000003c4d492d>] nvme_mpath_set_live+0x251/0x290 [nvme_core]
[<00000000889a58da>] nvme_mpath_add_disk+0x268/0x320 [nvme_core]
[<00000000192e7161>] nvme_alloc_ns+0x669/0xac0 [nvme_core]
[<000000007a1a6041>] nvme_validate_or_alloc_ns+0x156/0x280 [nvme_core]
[<000000003a763c35>] nvme_scan_work+0x221/0x3c0 [nvme_core]
[<000000009ff10706>] process_one_work+0x5cf/0xb10
[<000000000644ee25>] worker_thread+0x7a/0x680
[<00000000285ebd2f>] kthread+0x1c6/0x210
[<00000000e297c6ea>] ret_from_fork+0x22/0x30

Fixes: 2637baed7801 ("nvme: introduce generic per-namespace chardev")
Signed-off-by: Guoqing Jiang <jiangguoqing@kylinos.cn>
---
 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 522c9b229f80..2e8da13c842c 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3485,8 +3485,10 @@ int nvme_cdev_add(struct cdev *cdev, struct device *cdev_device,
 	cdev_init(cdev, fops);
 	cdev->owner = owner;
 	ret = cdev_device_add(cdev, cdev_device);
-	if (ret)
+	if (ret) {
+		put_device(cdev_device);
 		ida_simple_remove(&nvme_ns_chr_minor_ida, minor);
+	}
 	return ret;
 }
 
-- 
2.25.1


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] nvme: fix potential memory leaks in nvme_cdev_add
  2021-05-21  7:32 ` [PATCH] nvme: fix potential memory leaks in nvme_cdev_add Guoqing Jiang
@ 2021-05-21 20:19   ` Sagi Grimberg
  2021-05-21 21:23   ` Chaitanya Kulkarni
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Sagi Grimberg @ 2021-05-21 20:19 UTC (permalink / raw)
  To: Guoqing Jiang, kbusch, axboe, hch, javier.gonz, minwoo.im.dev; +Cc: linux-nvme

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] nvme: fix potential memory leaks in nvme_cdev_add
  2021-05-21  7:32 ` [PATCH] nvme: fix potential memory leaks in nvme_cdev_add Guoqing Jiang
  2021-05-21 20:19   ` Sagi Grimberg
@ 2021-05-21 21:23   ` Chaitanya Kulkarni
  2021-05-25  7:11   ` Javier González
  2021-05-25  7:24   ` Christoph Hellwig
  3 siblings, 0 replies; 5+ messages in thread
From: Chaitanya Kulkarni @ 2021-05-21 21:23 UTC (permalink / raw)
  To: Guoqing Jiang, kbusch, axboe, hch, sagi, javier.gonz, minwoo.im.dev
  Cc: linux-nvme

On 5/21/21 00:45, Guoqing Jiang wrote:
> We need to call put_device if cdev_device_add failed, otherwise
> kmemleak has below report.
>
> [<0000000024c71758>] kmem_cache_alloc_trace+0x233/0x480
> [<00000000ad2813ed>] device_add+0x7ff/0xe10
> [<0000000035bc54c4>] cdev_device_add+0x72/0xa0
> [<000000006c9aa1e8>] nvme_cdev_add+0xa9/0xf0 [nvme_core]
> [<000000003c4d492d>] nvme_mpath_set_live+0x251/0x290 [nvme_core]
> [<00000000889a58da>] nvme_mpath_add_disk+0x268/0x320 [nvme_core]
> [<00000000192e7161>] nvme_alloc_ns+0x669/0xac0 [nvme_core]
> [<000000007a1a6041>] nvme_validate_or_alloc_ns+0x156/0x280 [nvme_core]
> [<000000003a763c35>] nvme_scan_work+0x221/0x3c0 [nvme_core]
> [<000000009ff10706>] process_one_work+0x5cf/0xb10
> [<000000000644ee25>] worker_thread+0x7a/0x680
> [<00000000285ebd2f>] kthread+0x1c6/0x210
> [<00000000e297c6ea>] ret_from_fork+0x22/0x30
>
> Fixes: 2637baed7801 ("nvme: introduce generic per-namespace chardev")
> Signed-off-by: Guoqing Jiang <jiangguoqing@kylinos.cn>
>

Looks good.

Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>



_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] nvme: fix potential memory leaks in nvme_cdev_add
  2021-05-21  7:32 ` [PATCH] nvme: fix potential memory leaks in nvme_cdev_add Guoqing Jiang
  2021-05-21 20:19   ` Sagi Grimberg
  2021-05-21 21:23   ` Chaitanya Kulkarni
@ 2021-05-25  7:11   ` Javier González
  2021-05-25  7:24   ` Christoph Hellwig
  3 siblings, 0 replies; 5+ messages in thread
From: Javier González @ 2021-05-25  7:11 UTC (permalink / raw)
  To: Guoqing Jiang; +Cc: kbusch, axboe, hch, sagi, minwoo.im.dev, linux-nvme

On 21.05.2021 15:32, Guoqing Jiang wrote:
>We need to call put_device if cdev_device_add failed, otherwise
>kmemleak has below report.
>
>[<0000000024c71758>] kmem_cache_alloc_trace+0x233/0x480
>[<00000000ad2813ed>] device_add+0x7ff/0xe10
>[<0000000035bc54c4>] cdev_device_add+0x72/0xa0
>[<000000006c9aa1e8>] nvme_cdev_add+0xa9/0xf0 [nvme_core]
>[<000000003c4d492d>] nvme_mpath_set_live+0x251/0x290 [nvme_core]
>[<00000000889a58da>] nvme_mpath_add_disk+0x268/0x320 [nvme_core]
>[<00000000192e7161>] nvme_alloc_ns+0x669/0xac0 [nvme_core]
>[<000000007a1a6041>] nvme_validate_or_alloc_ns+0x156/0x280 [nvme_core]
>[<000000003a763c35>] nvme_scan_work+0x221/0x3c0 [nvme_core]
>[<000000009ff10706>] process_one_work+0x5cf/0xb10
>[<000000000644ee25>] worker_thread+0x7a/0x680
>[<00000000285ebd2f>] kthread+0x1c6/0x210
>[<00000000e297c6ea>] ret_from_fork+0x22/0x30
>
>Fixes: 2637baed7801 ("nvme: introduce generic per-namespace chardev")
>Signed-off-by: Guoqing Jiang <jiangguoqing@kylinos.cn>
>---
> 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 522c9b229f80..2e8da13c842c 100644
>--- a/drivers/nvme/host/core.c
>+++ b/drivers/nvme/host/core.c
>@@ -3485,8 +3485,10 @@ int nvme_cdev_add(struct cdev *cdev, struct device *cdev_device,
> 	cdev_init(cdev, fops);
> 	cdev->owner = owner;
> 	ret = cdev_device_add(cdev, cdev_device);
>-	if (ret)
>+	if (ret) {
>+		put_device(cdev_device);
> 		ida_simple_remove(&nvme_ns_chr_minor_ida, minor);
>+	}
> 	return ret;
> }
>
>-- 
>2.25.1
>

Looks good.

Reviewed-by: Javier González <javier.gonz@samsung.com>

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] nvme: fix potential memory leaks in nvme_cdev_add
  2021-05-21  7:32 ` [PATCH] nvme: fix potential memory leaks in nvme_cdev_add Guoqing Jiang
                     ` (2 preceding siblings ...)
  2021-05-25  7:11   ` Javier González
@ 2021-05-25  7:24   ` Christoph Hellwig
  3 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2021-05-25  7:24 UTC (permalink / raw)
  To: Guoqing Jiang
  Cc: kbusch, axboe, hch, sagi, javier.gonz, minwoo.im.dev, linux-nvme

Thanks,

applied to nvme-5.13.

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-05-25  7:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20210521073456eucas1p297f8812fe2815b01c3ae15a2b1633409@eucas1p2.samsung.com>
2021-05-21  7:32 ` [PATCH] nvme: fix potential memory leaks in nvme_cdev_add Guoqing Jiang
2021-05-21 20:19   ` Sagi Grimberg
2021-05-21 21:23   ` Chaitanya Kulkarni
2021-05-25  7:11   ` Javier González
2021-05-25  7:24   ` Christoph Hellwig

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.