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,
	Benjamin Gaignard <benjamin.gaignard@collabora.com>
Subject: [PATCH v7 1/3] media: verisilicon: AV1: Check reference frame index
Date: Fri, 20 Nov 2026 15:31:33 +0100	[thread overview]
Message-ID: <20261120143135.71134-2-benjamin.gaignard@collabora.com> (raw)
In-Reply-To: <20261120143135.71134-1-benjamin.gaignard@collabora.com>

Make sure that reference frame index is valid before using it.

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Fixes: 727a400686a2c ("media: verisilicon: Add Rockchip AV1 decoder")
---
 .../platform/verisilicon/rockchip_vpu981_hw_av1_dec.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c b/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c
index 2a145433e6d1..5da59104a966 100644
--- a/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c
+++ b/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c
@@ -121,7 +121,12 @@ static int rockchip_vpu981_get_frame_index(struct hantro_ctx *ctx, int ref)
 	struct hantro_av1_dec_ctrls *ctrls = &av1_dec->ctrls;
 	const struct v4l2_ctrl_av1_frame *frame = ctrls->frame;
 	u64 timestamp;
-	int i, idx = frame->ref_frame_idx[ref];
+	int i, idx;
+
+	if (ref < 0 || ref >= V4L2_AV1_REFS_PER_FRAME)
+		return AV1_INVALID_IDX;
+
+	idx = frame->ref_frame_idx[ref];
 
 	if (idx >= V4L2_AV1_TOTAL_REFS_PER_FRAME || idx < 0)
 		return AV1_INVALID_IDX;
@@ -1262,6 +1267,10 @@ static void rockchip_vpu981_av1_dec_set_prob(struct hantro_ctx *ctx)
 		rockchip_av1_default_coeff_probs(quantization->base_q_idx,
 						 av1_dec->cdfs);
 	} else {
+		if (frame->primary_ref_frame < 0 ||
+		    frame->primary_ref_frame >= V4L2_AV1_REFS_PER_FRAME)
+			return;
+
 		rockchip_av1_get_cdfs(ctx, frame->ref_frame_idx[frame->primary_ref_frame]);
 	}
 	rockchip_av1_store_cdfs(ctx, frame->refresh_frame_flags);
-- 
2.53.0


  reply	other threads:[~2026-11-20 14:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 14:31 [PATCH v7 0/3] media: verisilicon: Create AV1 helper library Benjamin Gaignard
2026-11-20 14:31 ` Benjamin Gaignard [this message]
2026-11-20 14:31 ` [PATCH v7 2/3] media: verisilicon: AV1: Fix luma size Benjamin Gaignard
2026-11-20 14:31 ` [PATCH v7 3/3] 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=20261120143135.71134-2-benjamin.gaignard@collabora.com \
    --to=benjamin.gaignard@collabora.com \
    --cc=heiko@sntech.de \
    --cc=hverkuil@kernel.org \
    --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®