2023-06-03 02:16:49

by Ira Weiny

[permalink] [raw]
Subject: [PATCH RFC 0/4] dax: Clean up dax_region references

In[*] Yongqiang Liu presented a fix to the reference counting associated
with the dax_region in hmem. At the time it was thought the patch was
unnecessary because dax_region_unregister() call would properly handle
reference counting.

Upon closer inspection Paul noted that this was not the case. In fact
Yongqiang's patch was correct but there were other issues as well.

This series includes Yongqiang's patch and breaks up additional fixes
which can be backported if necessary followed by a final patch which
simplifies the reference counting.

[*] https://lore.kernel.org/all/[email protected]/

Signed-off-by: Ira Weiny <[email protected]>
---
Ira Weiny (3):
dax/bus: Fix leaked reference in alloc_dax_region()
dax/cxl: Fix refcount leak in cxl_dax_region_probe()
dax/bus: Remove unnecessary reference in alloc_dax_region()

Yongqiang Liu (1):
dax/hmem: Fix refcount leak in dax_hmem_probe()

drivers/dax/bus.c | 6 +++++-
drivers/dax/cxl.c | 7 +------
drivers/dax/hmem/hmem.c | 7 +------
drivers/dax/pmem.c | 8 +-------
4 files changed, 8 insertions(+), 20 deletions(-)
---
base-commit: 921bdc72a0d68977092d6a64855a1b8967acc1d9
change-id: 20230602-dax-region-put-72c289137cb1

Best regards,
--
Ira Weiny <[email protected]>



2023-06-03 02:17:11

by Ira Weiny

[permalink] [raw]
Subject: [PATCH RFC 3/4] dax/cxl: Fix refcount leak in cxl_dax_region_probe()

alloc_dax_region() returns a reference protected dax_region. Regardless
of the success of the devm_create_dev_dax() the reference returned from
alloc_dax_region() needs to be released.

Drop the dax_region reference regardless of the success of dev_dax
creation. Clean up comments.

Fixes: 09d09e04d2fc ("cxl/dax: Create dax devices for CXL RAM regions")
Cc: Dan Williams <[email protected]>
Cc: [email protected]
Signed-off-by: Ira Weiny <[email protected]>

---
This work was inspired by Yongqiang Liu here:

https://lore.kernel.org/all/[email protected]/
---
drivers/dax/cxl.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/dax/cxl.c b/drivers/dax/cxl.c
index ccdf8de85bd5..bbfe71cf4325 100644
--- a/drivers/dax/cxl.c
+++ b/drivers/dax/cxl.c
@@ -29,12 +29,11 @@ static int cxl_dax_region_probe(struct device *dev)
.size = range_len(&cxlr_dax->hpa_range),
};
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 struct cxl_driver cxl_dax_region_driver = {

--
2.40.0