Re: [PATCH v8 1/9] dax/bus: Use dax_region_put() in alloc_dax_region() error path

From: Dave Jiang

Date: Mon Mar 23 2026 - 13:32:37 EST




On 3/22/26 12:53 PM, Smita Koralahalli wrote:
> 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 <jonathan.cameron@xxxxxxxxxx>
> Signed-off-by: Smita Koralahalli <Smita.KoralahalliChannabasappa@xxxxxxx>

Reviewed-by: Dave Jiang <dave.jiang@xxxxxxxxx>

> ---
> 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;
> }
>