From: Jianyun Gao <[email protected]>

In __devm_create_dev_dax(), when device_add() fails, the function calls
kill_dev_dax() and put_device() but does not free dev_dax->ranges.
At this point devm_add_action_or_reset() has not been registered yet,
so unregister_dev_dax() (which calls free_dev_dax_ranges()) will never
run.  put_device() triggers dev_dax_release() which frees pgmap and
dev_dax, but not ranges -- leaking the krealloc'd array and also
leaking the regions reserved via __request_region() in
alloc_dev_dax_range().

Add free_dev_dax_ranges() to the device_add() failure path, matching
the cleanup already done in the err_pgmap error path.

Fixes: 9567da0b408a2 ("device-dax: Introduce bus + driver model")
Cc: [email protected]
Signed-off-by: Jianyun Gao <[email protected]>
---
 drivers/dax/bus.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c
index b809e1a264af..83442430dc01 100644
--- a/drivers/dax/bus.c
+++ b/drivers/dax/bus.c
@@ -1536,6 +1536,7 @@ static struct dev_dax *__devm_create_dev_dax(struct 
dev_dax_data *data)
        rc = device_add(dev);
        if (rc) {
                kill_dev_dax(dev_dax);
+               free_dev_dax_ranges(dev_dax);
                put_device(dev);
                return ERR_PTR(rc);
        }
-- 
2.34.1


Reply via email to