Re: [PATCH] staging: media: atomisp: fix memory leak of raw_black_frame

Andy Shevchenko
2026-04-16T08:07:03Z

On Thu, Apr 16, 2026 at 02:30:58PM +0800, Huihui Huang wrote:
> Our code analyzer reported a memory leak in
> drivers/staging/media/atomisp/pci/atomisp_cmd.c.
>
> In atomisp_fixed_pattern_table(), raw_black_frame is allocated by
> atomisp_v4l2_framebuffer_to_css_frame(). If sh_css_set_black_frame()
> fails, the function returns -ENOMEM directly without freeing
> raw_black_frame. The allocated memory is only freed on the success
> path.
>
> My patch adds the missing ia_css_frame_free() call before the error

s/My patch adds/Add/

> return, to free raw_black_frame when sh_css_set_black_frame() fails.

...

> if (sh_css_set_black_frame(asd->stream_env[ATOMISP_INPUT_STREAM_GENERAL].stream,
> - raw_black_frame) != 0)
> + raw_black_frame) != 0) {
> + ia_css_frame_free(raw_black_frame);
> return -ENOMEM;
> + }
>
> ia_css_frame_free(raw_black_frame);
> return ret;

This is unneeded complication. What you need to do is just replacing if
conditional completely.

ret = sh_css_set_black_frame(asd->stream_env[ATOMISP_INPUT_STREAM_GENERAL].stream,
raw_black_frame);

--
With Best Regards,
Andy Shevchenko