From: Karthikey D Kadati <karthikey3608@gmail.com>
To: Hans de Goede <hansg@kernel.org>,
Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Dan Carpenter <dan.carpenter@linaro.org>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
linux-media@vger.kernel.org, linux-staging@lists.linux.dev,
linux-kernel@vger.kernel.org,
Karthikey D Kadati <karthikey3608@gmail.com>
Subject: [PATCH v3 2/3] media: atomisp: consolidate statistics buffer allocation
Date: Wed, 7 Jan 2026 20:12:51 +0530 [thread overview]
Message-ID: <20260107144252.74666-3-karthikey3608@gmail.com> (raw)
In-Reply-To: <20260107144252.74666-1-karthikey3608@gmail.com>
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 the actual error code on failure (instead of
hardcoded -ENOMEM), triggering the existing cleanup path in the caller
which correctly frees any partially allocated lists.
Signed-off-by: Karthikey D Kadati <karthikey3608@gmail.com>
---
.../staging/media/atomisp/pci/atomisp_ioctl.c | 127 ++++++++++++------
1 file changed, 85 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..c81773a75 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
@@ -678,13 +678,82 @@ 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;
+ int ret;
+
+ while (count--) {
+ switch (type) {
+ case IA_CSS_BUFFER_TYPE_3A_STATISTICS:
+ s3a_buf = kzalloc(sizeof(*s3a_buf), GFP_KERNEL);
+ if (!s3a_buf)
+ return -ENOMEM;
+
+ ret = atomisp_css_allocate_stat_buffers(asd,
+ stream_id,
+ s3a_buf,
+ NULL,
+ NULL);
+ if (ret) {
+ kfree(s3a_buf);
+ return ret;
+ }
+ list_add_tail(&s3a_buf->list, buf_list);
+ break;
+ case IA_CSS_BUFFER_TYPE_DIS_STATISTICS:
+ dis_buf = kzalloc(sizeof(*dis_buf), GFP_KERNEL);
+ if (!dis_buf)
+ return -ENOMEM;
+
+ ret = atomisp_css_allocate_stat_buffers(asd,
+ stream_id,
+ NULL,
+ dis_buf,
+ NULL);
+ if (ret) {
+ kfree(dis_buf);
+ return ret;
+ }
+ list_add_tail(&dis_buf->list, buf_list);
+ break;
+ case IA_CSS_BUFFER_TYPE_METADATA:
+ md_buf = kzalloc(sizeof(*md_buf), GFP_KERNEL);
+ if (!md_buf)
+ return -ENOMEM;
+
+ ret = atomisp_css_allocate_stat_buffers(asd,
+ stream_id,
+ NULL,
+ NULL,
+ md_buf);
+ if (ret) {
+ kfree(md_buf);
+ return ret;
+ }
+ 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 = asd->isp;
- struct atomisp_s3a_buf *s3a_buf = NULL, *_s3a_buf;
- struct atomisp_dis_buf *dis_buf = NULL, *_dis_buf;
- struct atomisp_metadata_buf *md_buf = 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 =
atomisp_css_get_dvs_grid_info(&asd->params.curr_grid_info);
@@ -695,37 +764,20 @@ int atomisp_alloc_css_stat_bufs(struct atomisp_sub_device *asd,
count = 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 = 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;
}
if (list_empty(&asd->dis_stats) && dvs_grid_info &&
dvs_grid_info->enable) {
count = ATOMISP_CSS_Q_DEPTH + 1;
dev_dbg(isp->dev, "allocating %d dis buffers\n", count);
- while (count--) {
- dis_buf = 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;
}
for (i = 0; i < ATOMISP_METADATA_TYPE_NUM; i++) {
@@ -736,19 +788,10 @@ int atomisp_alloc_css_stat_bufs(struct atomisp_sub_device *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 = 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;
--
2.43.0
next prev parent reply other threads:[~2026-01-07 14:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-07 14:42 [PATCH v3 0/3] media: atomisp: refactoring and fixes for V4L2 compliance Karthikey D Kadati
2026-01-07 14:42 ` [PATCH v3 1/3] media: atomisp: replace shadow zoom structs with v4l2_rect Karthikey D Kadati
2026-01-07 14:42 ` Karthikey D Kadati [this message]
2026-01-07 14:42 ` [PATCH v3 3/3] media: atomisp: propagate errors from ISP xnr and IRQ enable Karthikey D Kadati
2026-01-07 14:56 ` [PATCH v3 0/3] media: atomisp: refactoring and fixes for V4L2 compliance Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260107144252.74666-3-karthikey3608@gmail.com \
--to=karthikey3608@gmail.com \
--cc=dan.carpenter@linaro.org \
--cc=hansg@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=mchehab@kernel.org \
--cc=sakari.ailus@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox