Re: [PATCH v2 RESEND v2 2/3] media: atomisp: consolidate statistics buffer allocation

From: Dan Carpenter

Date: Wed Jan 07 2026 - 09:31:08 EST


On Wed, Jan 07, 2026 at 07:18:43PM +0530, Karthikey D Kadati wrote:
> Refactor atomisp_alloc_css_stat_bufs() to use a new helper function
>
> atomisp_alloc_stat_bufs_list().
>
> This reduces code duplication for allocating 3A, DIS, and metadata
>
> buffers and centralizes the allocation loop logic.
>
> The helper returns -ENOMEM on failure, triggering the existing
>
> cleanup path in the caller which correctly frees any partially
>
> allocated lists.
>
> Signed-off-by: Karthikey D Kadati <karthikey3608@xxxxxxxxx>
> ---
> .../staging/media/atomisp/pci/atomisp_ioctl.c | 123 ++++++++++++------
> 1 file changed, 81 insertions(+), 42 deletions(-)
>
> diff --git a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
> index 5c0a1d92b..9e572b3e6 100644
> --- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
> +++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
> @@ -678,13 +678,78 @@ static int atomisp_g_fmt_cap(struct file *file, void *fh,
> return atomisp_try_fmt_cap(file, fh, f);
> }
>
> +static int atomisp_alloc_stat_bufs_list(struct atomisp_sub_device *asd,
> + u16 stream_id,
> + struct list_head *buf_list,
> + int count,
> + enum ia_css_buffer_type type)
> +{
> + struct atomisp_s3a_buf *s3a_buf;
> + struct atomisp_dis_buf *dis_buf;
> + struct atomisp_metadata_buf *md_buf;
> +
> + while (count--) {
> + switch (type) {
> + case IA_CSS_BUFFER_TYPE_3A_STATISTICS:
> + s3a_buf = kzalloc(sizeof(*s3a_buf), GFP_KERNEL);
> + if (!s3a_buf)
> + return -ENOMEM;
> +
> + if (atomisp_css_allocate_stat_buffers(asd,
> + stream_id,
> + s3a_buf,
> + NULL,
> + NULL)) {
> + kfree(s3a_buf);
> + return -ENOMEM;
> + }

The caller doesn't propogate the error code either so this doesn't
affect runtime, but generally we should propogate error codes.

ret = atomisp_css_allocate_stat_buffers();
if (ret) {
kfree(s3a_buf);
return ret;
}

Same later as well...

regards,
dan carpenter