[PATCH v2 1/7] media: qcom: iris: Centralize internal buffer table selection

Dikshita Agarwal
2026-04-23T12:00:40Z

Internal buffer table dispatch is duplicated across multiple Iris code
paths, which is error‑prone and makes future changes harder to reason
about.

Consolidate the buffer dispatch logic into a single helper so that table
selection is defined in exactly one place and keep call sites minimal.
No functional change intended.

Signed-off-by: Dikshita Agarwal <dikshita.agarwal@oss.qualcomm.com>
---
drivers/media/platform/qcom/iris/iris_buffer.c | 107 ++++++-------------------
1 file changed, 26 insertions(+), 81 deletions(-)

diff --git a/drivers/media/platform/qcom/iris/iris_buffer.c b/drivers/media/platform/qcom/iris/iris_buffer.c
index 9151f43bc6b9c2c34c803de4231d1e6de0bec6c4..5b31c511da6e735943e2561683016cb9414d760c 100644
--- a/drivers/media/platform/qcom/iris/iris_buffer.c
+++ b/drivers/media/platform/qcom/iris/iris_buffer.c
@@ -299,39 +299,41 @@ static void iris_fill_internal_buf_info(struct iris_inst *inst,
buffers->min_count = iris_vpu_buf_count(inst, buffer_type);
}

-void iris_get_internal_buffers(struct iris_inst *inst, u32 plane)
+static void iris_get_int_buf_tbl(struct iris_inst *inst, u32 plane,
+ const u32 **internal_buf_type, u32 *internal_buffer_count)
{
const struct iris_platform_data *platform_data = inst->core->iris_platform_data;
- const u32 *internal_buf_type;
- u32 internal_buffer_count, i;

if (inst->domain == DECODER) {
if (V4L2_TYPE_IS_OUTPUT(plane)) {
- internal_buf_type = platform_data->dec_ip_int_buf_tbl;
- internal_buffer_count = platform_data->dec_ip_int_buf_tbl_size;
- for (i = 0; i < internal_buffer_count; i++)
- iris_fill_internal_buf_info(inst, internal_buf_type[i]);
+ *internal_buf_type = platform_data->dec_ip_int_buf_tbl;
+ *internal_buffer_count = platform_data->dec_ip_int_buf_tbl_size;
} else {
- internal_buf_type = platform_data->dec_op_int_buf_tbl;
- internal_buffer_count = platform_data->dec_op_int_buf_tbl_size;
- for (i = 0; i < internal_buffer_count; i++)
- iris_fill_internal_buf_info(inst, internal_buf_type[i]);
+ *internal_buf_type = platform_data->dec_op_int_buf_tbl;
+ *internal_buffer_count = platform_data->dec_op_int_buf_tbl_size;
}
} else {
if (V4L2_TYPE_IS_OUTPUT(plane)) {
- internal_buf_type = platform_data->enc_ip_int_buf_tbl;
- internal_buffer_count = platform_data->enc_ip_int_buf_tbl_size;
- for (i = 0; i < internal_buffer_count; i++)
- iris_fill_internal_buf_info(inst, internal_buf_type[i]);
+ *internal_buf_type = platform_data->enc_ip_int_buf_tbl;
+ *internal_buffer_count = platform_data->enc_ip_int_buf_tbl_size;
} else {
- internal_buf_type = platform_data->enc_op_int_buf_tbl;
- internal_buffer_count = platform_data->enc_op_int_buf_tbl_size;
- for (i = 0; i < internal_buffer_count; i++)
- iris_fill_internal_buf_info(inst, internal_buf_type[i]);
+ *internal_buf_type = platform_data->enc_op_int_buf_tbl;
+ *internal_buffer_count = platform_data->enc_op_int_buf_tbl_size;
}
}
}

+void iris_get_internal_buffers(struct iris_inst *inst, u32 plane)
+{
+ const u32 *internal_buf_type;
+ u32 internal_buffer_count, i;
+
+ iris_get_int_buf_tbl(inst, plane, &internal_buf_type, &internal_buffer_count);
+
+ for (i = 0; i < internal_buffer_count; i++)
+ iris_fill_internal_buf_info(inst, internal_buf_type[i]);
+}
+
static int iris_create_internal_buffer(struct iris_inst *inst,
enum iris_buffer_type buffer_type, u32 index)
{
@@ -366,29 +368,12 @@ static int iris_create_internal_buffer(struct iris_inst *inst,

int iris_create_internal_buffers(struct iris_inst *inst, u32 plane)
{
- const struct iris_platform_data *platform_data = inst->core->iris_platform_data;
u32 internal_buffer_count, i, j;
struct iris_buffers *buffers;
const u32 *internal_buf_type;
int ret;

- if (inst->domain == DECODER) {
- if (V4L2_TYPE_IS_OUTPUT(plane)) {
- internal_buf_type = platform_data->dec_ip_int_buf_tbl;
- internal_buffer_count = platform_data->dec_ip_int_buf_tbl_size;
- } else {
- internal_buf_type = platform_data->dec_op_int_buf_tbl;
- internal_buffer_count = platform_data->dec_op_int_buf_tbl_size;
- }
- } else {
- if (V4L2_TYPE_IS_OUTPUT(plane)) {
- internal_buf_type = platform_data->enc_ip_int_buf_tbl;
- internal_buffer_count = platform_data->enc_ip_int_buf_tbl_size;
- } else {
- internal_buf_type = platform_data->enc_op_int_buf_tbl;
- internal_buffer_count = platform_data->enc_op_int_buf_tbl_size;
- }
- }
+ iris_get_int_buf_tbl(inst, plane, &internal_buf_type, &internal_buffer_count);

for (i = 0; i < internal_buffer_count; i++) {
buffers = &inst->buffers[internal_buf_type[i]];
@@ -442,30 +427,13 @@ int iris_queue_internal_deferred_buffers(struct iris_inst *inst, enum iris_buffe

int iris_queue_internal_buffers(struct iris_inst *inst, u32 plane)
{
- const struct iris_platform_data *platform_data = inst->core->iris_platform_data;
struct iris_buffer *buffer, *next;
struct iris_buffers *buffers;
const u32 *internal_buf_type;
u32 internal_buffer_count, i;
int ret;

- if (inst->domain == DECODER) {
- if (V4L2_TYPE_IS_OUTPUT(plane)) {
- internal_buf_type = platform_data->dec_ip_int_buf_tbl;
- internal_buffer_count = platform_data->dec_ip_int_buf_tbl_size;
- } else {
- internal_buf_type = platform_data->dec_op_int_buf_tbl;
- internal_buffer_count = platform_data->dec_op_int_buf_tbl_size;
- }
- } else {
- if (V4L2_TYPE_IS_OUTPUT(plane)) {
- internal_buf_type = platform_data->enc_ip_int_buf_tbl;
- internal_buffer_count = platform_data->enc_ip_int_buf_tbl_size;
- } else {
- internal_buf_type = platform_data->enc_op_int_buf_tbl;
- internal_buffer_count = platform_data->enc_op_int_buf_tbl_size;
- }
- }
+ iris_get_int_buf_tbl(inst, plane, &internal_buf_type, &internal_buffer_count);

for (i = 0; i < internal_buffer_count; i++) {
buffers = &inst->buffers[internal_buf_type[i]];
@@ -501,30 +469,13 @@ int iris_destroy_internal_buffer(struct iris_inst *inst, struct iris_buffer *buf

static int iris_destroy_internal_buffers(struct iris_inst *inst, u32 plane, bool force)
{
- const struct iris_platform_data *platform_data = inst->core->iris_platform_data;
struct iris_buffer *buf, *next;
struct iris_buffers *buffers;
const u32 *internal_buf_type;
u32 i, len;
int ret;

- if (inst->domain == DECODER) {
- if (V4L2_TYPE_IS_OUTPUT(plane)) {
- internal_buf_type = platform_data->dec_ip_int_buf_tbl;
- len = platform_data->dec_ip_int_buf_tbl_size;
- } else {
- internal_buf_type = platform_data->dec_op_int_buf_tbl;
- len = platform_data->dec_op_int_buf_tbl_size;
- }
- } else {
- if (V4L2_TYPE_IS_OUTPUT(plane)) {
- internal_buf_type = platform_data->enc_ip_int_buf_tbl;
- len = platform_data->enc_ip_int_buf_tbl_size;
- } else {
- internal_buf_type = platform_data->enc_op_int_buf_tbl;
- len = platform_data->enc_op_int_buf_tbl_size;
- }
- }
+ iris_get_int_buf_tbl(inst, plane, &internal_buf_type, &len);

for (i = 0; i < len; i++) {
buffers = &inst->buffers[internal_buf_type[i]];
@@ -593,18 +544,12 @@ static int iris_release_internal_buffers(struct iris_inst *inst,

static int iris_release_input_internal_buffers(struct iris_inst *inst)
{
- const struct iris_platform_data *platform_data = inst->core->iris_platform_data;
const u32 *internal_buf_type;
u32 internal_buffer_count, i;
int ret;

- if (inst->domain == DECODER) {
- internal_buf_type = platform_data->dec_ip_int_buf_tbl;
- internal_buffer_count = platform_data->dec_ip_int_buf_tbl_size;
- } else {
- internal_buf_type = platform_data->enc_ip_int_buf_tbl;
- internal_buffer_count = platform_data->enc_ip_int_buf_tbl_size;
- }
+ iris_get_int_buf_tbl(inst, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
+ &internal_buf_type, &internal_buffer_count);

for (i = 0; i < internal_buffer_count; i++) {
ret = iris_release_internal_buffers(inst, internal_buf_type[i]);

--
2.34.1