public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dax/hmem: Fix refcount leak in dax_hmem_probe()
@ 2022-12-03  9:58 Yongqiang Liu
  2022-12-03 20:49 ` Ira Weiny
  0 siblings, 1 reply; 8+ messages in thread
From: Yongqiang Liu @ 2022-12-03  9:58 UTC (permalink / raw)
  To: linux-kernel, nvdimm
  Cc: dan.j.williams, vishal.l.verma, dave.jiang, akpm, joao.m.martins,
	zhangxiaoxu5, liuyongqiang13

We should always call dax_region_put() whenever devm_create_dev_dax()
succeed or fail to avoid refcount leak of dax_region. Move the return
value check after dax_region_put().

Fixes: c01044cc8191 ("ACPI: HMAT: refactor hmat_register_target_device to hmem_register_device")
Signed-off-by: Yongqiang Liu <liuyongqiang13@huawei.com>
---
 drivers/dax/hmem/hmem.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/dax/hmem/hmem.c b/drivers/dax/hmem/hmem.c
index 1bf040dbc834..09f5cd7b6c8e 100644
--- a/drivers/dax/hmem/hmem.c
+++ b/drivers/dax/hmem/hmem.c
@@ -36,12 +36,11 @@ static int dax_hmem_probe(struct platform_device *pdev)
 		.size = region_idle ? 0 : resource_size(res),
 	};
 	dev_dax = devm_create_dev_dax(&data);
-	if (IS_ERR(dev_dax))
-		return PTR_ERR(dev_dax);
 
 	/* child dev_dax instances now own the lifetime of the dax_region */
 	dax_region_put(dax_region);
-	return 0;
+
+	return IS_ERR(dev_dax) ? PTR_ERR(dev_dax) : 0;
 }
 
 static int dax_hmem_remove(struct platform_device *pdev)
-- 
2.25.1


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

end of thread, other threads:[~2023-06-03  4:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-03  9:58 [PATCH] dax/hmem: Fix refcount leak in dax_hmem_probe() Yongqiang Liu
2022-12-03 20:49 ` Ira Weiny
2022-12-06  9:17   ` Yongqiang Liu
2023-06-02  2:31   ` Paul Cassella
2023-06-02 18:43     ` Ira Weiny
2023-06-02 21:11       ` Paul Cassella
2023-06-02 23:34         ` Ira Weiny
2023-06-03  4:11         ` Dan Williams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox