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

From: Ira Weiny
Date: Fri Jun 02 2023 - 22:09:48 EST


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 <dan.j.williams@xxxxxxxxx>
Cc: linux-cxl@xxxxxxxxxxxxxxx
Signed-off-by: Ira Weiny <ira.weiny@xxxxxxxxx>

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

https://lore.kernel.org/all/20221203095858.612027-1-liuyongqiang13@xxxxxxxxxx/
---
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