Re: [PATCH v2] staging: media: ipu7: fix boot_config leak on queue_mem failure

From: Dan Carpenter

Date: Fri Apr 17 2026 - 04:01:43 EST


On Fri, Apr 17, 2026 at 03:39:39PM +0800, Huihui Huang wrote:
> There is a memory leak in drivers/staging/media/ipu7/ipu7-boot.c.
>
> In ipu7_boot_init_boot_config(), boot_config is allocated by
> ipu7_dma_alloc(). If the second ipu7_dma_alloc() for queue_mem fails,
> the function returns -ENOMEM without freeing the previously allocated
> boot_config.
>
> Add the missing ipu7_dma_free() call before returning on the error
> path.
>
> Signed-off-by: Huihui Huang <hhhuang@xxxxxxxxxx>
> ---
> v2: Reword commit message in imperative mood. Remove unnecessary
> NULL assignment on the error path.
> ---
> drivers/staging/media/ipu7/ipu7-boot.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/staging/media/ipu7/ipu7-boot.c b/drivers/staging/media/ipu7/ipu7-boot.c
> index d7901ff78b38..495b3e05a9b1 100644
> --- a/drivers/staging/media/ipu7/ipu7-boot.c
> +++ b/drivers/staging/media/ipu7/ipu7-boot.c
> @@ -263,6 +263,8 @@ int ipu7_boot_init_boot_config(struct ipu7_bus_device *adev,
> GFP_KERNEL, 0);
> if (!syscom->queue_mem) {
> dev_err(dev, "Failed to allocate queue memory.\n");
> + ipu7_dma_free(adev, adev->boot_config_size,
> + adev->boot_config, adev->boot_config_dma_addr, 0);
> return -ENOMEM;

Adding a free here leads to a double free. It's the same issue.
One magical cleanup function in the caller.

I haven't looked at this but I bet there are bugs in the error handling
since magical cleanup functions are always buggy.

regards,
dan carpenter