Re: [PATCH] i3c: dw: Fix memory leak in dw_i3c_master_i3c_xfers()
From: Frank Li
Date: Thu Apr 02 2026 - 09:55:14 EST
On Thu, Apr 02, 2026 at 08:38:03PM +0800, Felix Gu wrote:
> The dw_i3c_master_i3c_xfers() function allocates memory for the xfer
> structure using dw_i3c_master_alloc_xfer(). If pm_runtime_resume_and_get()
> fails, the function returns without freeing the allocated xfer, resulting
> in a memory leak.
>
> Add a dw_i3c_master_free_xfer() call to the error path to ensure the
> allocated memory is properly freed.
>
> Fixes: 62fe9d06f570 ("i3c: dw: Add power management support")
> Signed-off-by: Felix Gu <ustc.gu@xxxxxxxxx>
> ---
> drivers/i3c/master/dw-i3c-master.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
> index d6bdb32397fb..d933db076c61 100644
> --- a/drivers/i3c/master/dw-i3c-master.c
> +++ b/drivers/i3c/master/dw-i3c-master.c
> @@ -953,6 +953,7 @@ static int dw_i3c_master_i3c_xfers(struct i3c_dev_desc *dev,
> dev_err(master->dev,
> "<%s> cannot resume i3c bus master, err: %d\n",
> __func__, ret);
> + dw_i3c_master_free_xfer(xfer);
Suggest use auto clean up to fix this problem.
struct .... * __free(dw_i3c_master_free_xfer) xfer = dw_i3c_master_alloc_xfer(master, i3c_nxfers);
Frank
> return ret;
> }
>
>
> ---
> base-commit: bd0f139e5fc11182777b81cefc3893ea508544ec
> change-id: 20260402-dw-i3c-2-8f123def99b2
>
> Best regards,
> --
> Felix Gu <ustc.gu@xxxxxxxxx>
>
>
> --
> linux-i3c mailing list
> linux-i3c@xxxxxxxxxxxxxxxxxxx
> http://lists.infradead.org/mailman/listinfo/linux-i3c