mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Benjamin Gaignard <benjamin.gaignard@collabora.com>
To: nicolas.dufresne@collabora.com, p.zabel@pengutronix.de,
	mchehab@kernel.org, heiko@sntech.de, hverkuil@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
	linux-rockchip@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org, kernel@collabora.com,
	Benjamin Gaignard <benjamin.gaignard@collabora.com>
Subject: [PATCH v9 1/4] media: v4l2-ctrls: validate AV1 reference frame index
Date: Wed, 25 Nov 2026 13:28:22 +0100	[thread overview]
Message-ID: <20261125122825.236422-2-benjamin.gaignard@collabora.com> (raw)
In-Reply-To: <20261125122825.236422-1-benjamin.gaignard@collabora.com>

The stateless AV1 decoders use primary_ref_frame and ref_frame_idx[] to
to find the matching reference frames.
V4L2_AV1_PRIMARY_REF_NONE is the value of primary_ref_frame indicating
that there is no primary reference frame.
Iterate over ref_frame_idx[] to check if the indexes are in [-1, 7] range
like described in AV1 specifications.

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
---
changes in v9:
- Split core changes and drivers changes
- Add V4L2_AV1_REF_FRAME_INVALID
- Rework checks in validate_av1_reference_index() to be sure that
  all values of ref_frame_idx[] are in the correct range.

 drivers/media/v4l2-core/v4l2-ctrls-core.c | 30 +++++++++++++++++++++++
 include/uapi/linux/v4l2-controls.h        |  2 ++
 2 files changed, 32 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c b/drivers/media/v4l2-core/v4l2-ctrls-core.c
index 6e751a043a21..e707897e36fd 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-core.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c
@@ -817,10 +817,40 @@ static int validate_av1_tile_info(struct v4l2_av1_tile_info *t)
 	return 0;
 }
 
+static int validate_av1_reference_index(struct v4l2_ctrl_av1_frame *f)
+{
+	int i, idx;
+
+	/* The valid range for ref_frame_idx[] values is [-1, 7] */
+	for (i = 0; i < V4L2_AV1_REFS_PER_FRAME; i++) {
+		idx = f->ref_frame_idx[i];
+		if (idx < V4L2_AV1_REF_FRAME_INVALID)
+			return -EINVAL;
+		if (idx >= V4L2_AV1_TOTAL_REFS_PER_FRAME)
+			return -EINVAL;
+	}
+
+	if (f->primary_ref_frame > V4L2_AV1_PRIMARY_REF_NONE)
+		return -EINVAL;
+
+	if (f->primary_ref_frame == V4L2_AV1_PRIMARY_REF_NONE)
+		return 0;
+
+	/* If set primary_ref_frame index must be valid */
+	idx = f->ref_frame_idx[f->primary_ref_frame];
+	if (idx <= V4L2_AV1_REF_FRAME_INVALID)
+		return -EINVAL;
+
+	return 0;
+}
+
 static int validate_av1_frame(struct v4l2_ctrl_av1_frame *f)
 {
 	int ret = 0;
 
+	ret = validate_av1_reference_index(f);
+	if (ret)
+		return ret;
 	ret = validate_av1_tile_info(&f->tile_info);
 	if (ret)
 		return ret;
diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h
index d17e41d51d2e..f21f00fd5a84 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -2940,6 +2940,8 @@ struct v4l2_ctrl_vp9_compressed_hdr {
 #define V4L2_AV1_MAX_TILE_COLS		64
 #define V4L2_AV1_MAX_TILE_ROWS		64
 #define V4L2_AV1_MAX_TILE_COUNT		512
+#define V4L2_AV1_PRIMARY_REF_NONE	7
+#define V4L2_AV1_REF_FRAME_INVALID	-1
 
 #define V4L2_AV1_SEQUENCE_FLAG_STILL_PICTURE		  0x00000001
 #define V4L2_AV1_SEQUENCE_FLAG_USE_128X128_SUPERBLOCK	  0x00000002
-- 
2.53.0


  reply	other threads:[~2026-11-25 12:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 12:28 [PATCH v9 0/4] media: verisilicon: Create AV1 helper library Benjamin Gaignard
2026-11-25 12:28 ` Benjamin Gaignard [this message]
2026-11-25 12:28 ` [PATCH v9 2/4] media: verisilicon: Use V4L2_AV1_PRIMARY_REF_NONE and V4L2_AV1_REF_FRAME_INVALID Benjamin Gaignard
2026-11-25 12:28 ` [PATCH v9 3/4] media: verisilicon: AV1: Fix luma size Benjamin Gaignard
2026-11-25 12:28 ` [PATCH v9 4/4] media: verisilicon: Create AV1 helper library Benjamin Gaignard

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=20261125122825.236422-2-benjamin.gaignard@collabora.com \
    --to=benjamin.gaignard@collabora.com \
    --cc=heiko@sntech.de \
    --cc=hverkuil@kernel.org \
    --cc=kernel@collabora.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=mchehab@kernel.org \
    --cc=nicolas.dufresne@collabora.com \
    --cc=p.zabel@pengutronix.de \
    /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

all inboxes | Powered by JetHome®