alloc_dax_region() calls kref_init() on the dax_region early in the
function, but the error path for sysfs_create_groups() failure uses
kfree() directly to free the dax_region. This bypasses the kref lifecycle.

Use dax_region_put() instead to handle kref lifecycle correctly.

Suggested-by: Jonathan Cameron <[email protected]>
Signed-off-by: Smita Koralahalli <[email protected]>
---
 drivers/dax/bus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c
index c94c09622516..299134c9b294 100644
--- a/drivers/dax/bus.c
+++ b/drivers/dax/bus.c
@@ -668,7 +668,7 @@ struct dax_region *alloc_dax_region(struct device *parent, 
int region_id,
        };
 
        if (sysfs_create_groups(&parent->kobj, dax_region_attribute_groups)) {
-               kfree(dax_region);
+               dax_region_put(dax_region);
                return NULL;
        }
 
-- 
2.17.1


Reply via email to