From nobody Mon Feb 9 13:58:23 2026 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B065D30BB88 for ; Mon, 5 Jan 2026 14:58:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767625108; cv=none; b=kjHx8PNltgDwzp4VVfuhrcJMEGpoAJfJrq+MHNRUYE+2DkxD2ki5bJyzsE3xDHoxMpz3seCsGe5oJgsL3Fy3sNcvVpydMaV3+sw429eF8d8sfsJBEESmLE9QcyWMmPaSRgoEHq1drBzw085wg1ATtPPG3yKKVV3Ywkwg2gn5Yeg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767625108; c=relaxed/simple; bh=7aFJtkTCn/RUyXBqDN5A8Rl1FrpL/MQORLd7fWn3cOI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fAxNeAi/M94DYjQVUUTKUdT29trplTRLK915zIQ1oXhAS8PbiOZsT1gulkZPFose5qrBotRHpIt6JxSaK5A3GiuFeRntdYNfbEW1K5oV3EXqUAQg+LFy4g3uu5gRJhTW2igcqodg3NrfHY5ExcQJyURItquvJiV7Hav1Tm5WiBI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MBq9/XyF; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MBq9/XyF" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-29f30233d8aso162855075ad.0 for ; Mon, 05 Jan 2026 06:58:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767625106; x=1768229906; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0L8w8zzA7n7ZIE7wj1Nj7dJ97iLU993N1NE76Z8Jakg=; b=MBq9/XyFYPKbzlnRavv9/Uv2M1u1CqjhyxbtDbJkoMBpaRUdpAB175P6Rs3omI3fbG jcNTJyDnuiWbGiMxJV+Vb2zI51PESZeYHVsbEaORHrEWVP1HA1S29Ti8O0hHOIbqckTF NxlEKIR2hXAQDaGDJN9L/fJ1kz8wBMcGBKQmx3fy872aT6x+OUDQjfKdM2VRKEVKYBvj 5nv+yStuq/rI+NSadysv10oACPTPC2M55IJU3EWjhgc7CAd5cVwRA3Z/UPD0lYr50ANm nAHrgY97j5/vqVcr9fmBD9+vs//bbszrB24aGnnnGrW2Prxx/GA39q0EVDa0oW55AZov bzBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767625106; x=1768229906; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=0L8w8zzA7n7ZIE7wj1Nj7dJ97iLU993N1NE76Z8Jakg=; b=P3a4Br70eKcl2XpbcdSDBUhPyilZeL9FgRIhkhsXoXAptei4GUS67xwrzbp4jPychY X+LOtRM4oZDZx1JaqUYt4LwV7RmyEVV+0TYCvzSJMI5vHwjFfcQpLHeDyxdGojyCMkZW glqNKJIhJ2XpqaP8WktKiPtxbWe2S5JsTMO4Jaf/sl+wqqVf1sDXaOY6jF93YDQiGPvE LZ23Xb5yomi0syqvuhk8lt15V9RKomqCnpJ7Tqqv3m+JhizGcsZODS85IKazaVD1/X4y Wg1I9hFOUMUu0t0kFlbmIdncnCAoRPs7o0/z3Pta1LPdm7OiHECfUPi3xC8/1jqJdEKZ tsaw== X-Forwarded-Encrypted: i=1; AJvYcCUytNYdj7A2hWBen82FSZdEZmbDlVbEGR88IbPFJvWRBHwFEXf4l9HdiLY9KS9nVF7OlkygTDGUJ69l1Nw=@vger.kernel.org X-Gm-Message-State: AOJu0YyUX2VaUNRhlXLj5JSYH/heQLnTur+zuEXkLJsQQU6VZt57RS/P FNfJ6y/TkeXx4qyw+ZGVt4dMtBxxU7r5ZthRLy3LchvKWlrPUro/2lo4 X-Gm-Gg: AY/fxX6W+g1g9Ngea4QjIgMl5232/SH96Q/dqS+899/jZwZLNjN4+Ktbq7ogFCWMbKy eDIw3cDzxEjFdBSoMo0LrnThAGETp3070t01pG3Gw8JumoTQtlpy9VR5+Istoy+RSeZcLpakaQa yYGcomqksjsihxe6iHxKfVa158YijqV58R9JoI3FbLtMdw8Y2jBcAxhXeh1by6ajNNddWmN0NAZ czJSA6WVTPN9PkrmPf/VJx0q0vP3XDc613EnWGsFE+NN9tQmrevRV7ylQs6S7HQ7LmomxEi4dgp /Xhw4JxOwffJsOdvv7Rl3ITsiGC/jKrzw29gHcmaePxNyDazeQ+c/Am/Sbt+mjCijXKjRZMo1FZ F6+DusOEARH4/2j30/nmh8QD37PQ6xwVu1IB1kSuE69bccTXDpi1oEBK5IFO/aoKRf3O9JK1ND8 UsDYlXhUz1VgY= X-Google-Smtp-Source: AGHT+IEThfma4vyAoTFD9Z1px96n831nFofd6uJzy0WpP50OzQzghORJxsBujiDHnCn4NZgVK1DF1w== X-Received: by 2002:a17:902:cf0e:b0:297:f09a:51cd with SMTP id d9443c01a7336-2a3e2cbb55fmr472125ad.14.1767625106054; Mon, 05 Jan 2026 06:58:26 -0800 (PST) Received: from karthik.. ([43.247.159.43]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a3e2b81484sm715955ad.78.2026.01.05.06.58.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jan 2026 06:58:25 -0800 (PST) From: Karthikey D Kadati To: Hans de Goede , Mauro Carvalho Chehab Cc: Sakari Ailus , linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Karthikey D Kadati Subject: [PATCH v2 2/3] media: atomisp: consolidate statistics buffer allocation Date: Mon, 5 Jan 2026 20:27:23 +0530 Message-ID: <20260105145724.37305-3-karthikey3608@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260105145724.37305-1-karthikey3608@gmail.com> References: <81e2d12c-342b-4b88-88a0-3e24115541aa@kernel.org> <20260105145724.37305-1-karthikey3608@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- .../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/st= aging/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); } =20 +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 =3D 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; + } + list_add_tail(&s3a_buf->list, buf_list); + break; + case IA_CSS_BUFFER_TYPE_DIS_STATISTICS: + dis_buf =3D kzalloc(sizeof(*dis_buf), GFP_KERNEL); + if (!dis_buf) + return -ENOMEM; + + if (atomisp_css_allocate_stat_buffers(asd, + stream_id, + NULL, + dis_buf, + NULL)) { + kfree(dis_buf); + return -ENOMEM; + } + list_add_tail(&dis_buf->list, buf_list); + break; + case IA_CSS_BUFFER_TYPE_METADATA: + md_buf =3D kzalloc(sizeof(*md_buf), GFP_KERNEL); + if (!md_buf) + return -ENOMEM; + + if (atomisp_css_allocate_stat_buffers(asd, + stream_id, + NULL, + NULL, + md_buf)) { + kfree(md_buf); + return -ENOMEM; + } + list_add_tail(&md_buf->list, buf_list); + break; + default: + return -EINVAL; + } + } + + return 0; +} + int atomisp_alloc_css_stat_bufs(struct atomisp_sub_device *asd, - uint16_t stream_id) + u16 stream_id) { struct atomisp_device *isp =3D asd->isp; - struct atomisp_s3a_buf *s3a_buf =3D NULL, *_s3a_buf; - struct atomisp_dis_buf *dis_buf =3D NULL, *_dis_buf; - struct atomisp_metadata_buf *md_buf =3D NULL, *_md_buf; + struct atomisp_dis_buf *dis_buf, *_dis_buf; + struct atomisp_s3a_buf *s3a_buf, *_s3a_buf; + struct atomisp_metadata_buf *md_buf, *_md_buf; int count; struct ia_css_dvs_grid_info *dvs_grid_info =3D atomisp_css_get_dvs_grid_info(&asd->params.curr_grid_info); @@ -695,37 +760,20 @@ int atomisp_alloc_css_stat_bufs(struct atomisp_sub_de= vice *asd, count =3D ATOMISP_CSS_Q_DEPTH + ATOMISP_S3A_BUF_QUEUE_DEPTH_FOR_HAL; dev_dbg(isp->dev, "allocating %d 3a buffers\n", count); - while (count--) { - s3a_buf =3D kzalloc(sizeof(struct atomisp_s3a_buf), GFP_KERNEL); - if (!s3a_buf) - goto error; - - if (atomisp_css_allocate_stat_buffers( - asd, stream_id, s3a_buf, NULL, NULL)) { - kfree(s3a_buf); - goto error; - } - - list_add_tail(&s3a_buf->list, &asd->s3a_stats); - } + if (atomisp_alloc_stat_bufs_list(asd, stream_id, + &asd->s3a_stats, count, + IA_CSS_BUFFER_TYPE_3A_STATISTICS)) + goto error; } =20 if (list_empty(&asd->dis_stats) && dvs_grid_info && dvs_grid_info->enable) { count =3D ATOMISP_CSS_Q_DEPTH + 1; dev_dbg(isp->dev, "allocating %d dis buffers\n", count); - while (count--) { - dis_buf =3D kzalloc(sizeof(struct atomisp_dis_buf), GFP_KERNEL); - if (!dis_buf) - goto error; - if (atomisp_css_allocate_stat_buffers( - asd, stream_id, NULL, dis_buf, NULL)) { - kfree(dis_buf); - goto error; - } - - list_add_tail(&dis_buf->list, &asd->dis_stats); - } + if (atomisp_alloc_stat_bufs_list(asd, stream_id, + &asd->dis_stats, count, + IA_CSS_BUFFER_TYPE_DIS_STATISTICS)) + goto error; } =20 for (i =3D 0; i < ATOMISP_METADATA_TYPE_NUM; i++) { @@ -736,19 +784,10 @@ int atomisp_alloc_css_stat_bufs(struct atomisp_sub_de= vice *asd, ATOMISP_METADATA_QUEUE_DEPTH_FOR_HAL; dev_dbg(isp->dev, "allocating %d metadata buffers for type %d\n", count, i); - while (count--) { - md_buf =3D kzalloc(sizeof(struct atomisp_metadata_buf), - GFP_KERNEL); - if (!md_buf) - goto error; - - if (atomisp_css_allocate_stat_buffers( - asd, stream_id, NULL, NULL, md_buf)) { - kfree(md_buf); - goto error; - } - list_add_tail(&md_buf->list, &asd->metadata[i]); - } + if (atomisp_alloc_stat_bufs_list(asd, stream_id, + &asd->metadata[i], count, + IA_CSS_BUFFER_TYPE_METADATA)) + goto error; } } return 0; --=20 2.43.0