From: Arun Iyengar via B4 Relay <devnull+aiyengar1990.gmail.com@kernel.org>
To: Nicolas Dufresne <nicolas.dufresne@collabora.com>,
Benjamin Gaignard <benjamin.gaignard@collabora.com>,
Philipp Zabel <p.zabel@pengutronix.de>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Hans Verkuil <hverkuil@kernel.org>,
Boris Brezillon <boris.brezillon@collabora.com>,
Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
Jonas Karlman <jonas@kwiboo.se>
Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org,
linux-kernel@vger.kernel.org,
Arun Iyengar <aiyengar1990@gmail.com>
Subject: [PATCH] media: verisilicon: Refuse MPEG-2 sequences below the minimum size
Date: Sat, 05 Dec 2026 22:48:34 +0000 [thread overview]
Message-ID: <20261205-hantro-mpeg2-min-size-v1-1-dfeb36b9f397@gmail.com> (raw)
From: Arun Iyengar <aiyengar1990@gmail.com>
The MPEG-2 decoder programs its size in macroblocks from the CAPTURE
format, which is clamped to the 48x48 hardware minimum. A 16x16 or
32x32 sequence thus decodes as 3x3 macroblocks into a garbage picture.
Without the clamp, the VDPU2 times out on such frames.
Refuse sequences that are smaller than the coded format minimum.
Fixes: 879dee56a40c ("media: rockchip/vpu: Add MPEG2 decoding support to RK3399")
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
Tested on an Orange Pi 5 (RK3588S, VDPU121): 16x16 and 32x32 MPEG-2
streams are refused, other MPEG-1/2 conformance streams decode as before.
Developed with Claude (Anthropic), which wrote the code and the commit messages. I reviewed every change.
---
drivers/media/platform/verisilicon/hantro_drv.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/media/platform/verisilicon/hantro_drv.c b/drivers/media/platform/verisilicon/hantro_drv.c
index 5c962847fdf5..890af2ca27ce 100644
--- a/drivers/media/platform/verisilicon/hantro_drv.c
+++ b/drivers/media/platform/verisilicon/hantro_drv.c
@@ -276,6 +276,9 @@ queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq)
static int hantro_try_ctrl(struct v4l2_ctrl *ctrl)
{
+ struct hantro_ctx *ctx = container_of(ctrl->handler,
+ struct hantro_ctx, ctrl_handler);
+
if (ctrl->id == V4L2_CID_STATELESS_H264_SPS) {
const struct v4l2_ctrl_h264_sps *sps = ctrl->p_new.p_h264_sps;
@@ -305,6 +308,15 @@ static int hantro_try_ctrl(struct v4l2_ctrl *ctrl)
if (sequence->bit_depth != 8 && sequence->bit_depth != 10)
return -EINVAL;
+ } else if (ctrl->id == V4L2_CID_STATELESS_MPEG2_SEQUENCE) {
+ const struct v4l2_ctrl_mpeg2_sequence *seq = ctrl->p_new.p_mpeg2_sequence;
+ const struct v4l2_frmsize_stepwise *frmsize = &ctx->vpu_src_fmt->frmsize;
+
+ /* Refuse sizes below the minimum; 0x0 is the control default */
+ if ((seq->horizontal_size || seq->vertical_size) &&
+ (ALIGN(seq->horizontal_size, MB_DIM) < frmsize->min_width ||
+ ALIGN(seq->vertical_size, MB_DIM) < frmsize->min_height))
+ return -EINVAL;
}
return 0;
@@ -465,6 +477,7 @@ static const struct hantro_ctrl controls[] = {
.codec = HANTRO_MPEG2_DECODER,
.cfg = {
.id = V4L2_CID_STATELESS_MPEG2_SEQUENCE,
+ .ops = &hantro_ctrl_ops,
},
}, {
.codec = HANTRO_MPEG2_DECODER,
---
base-commit: 52fec895d81d2b587f1b2c43e661509c1276096d
change-id: 20261205-hantro-mpeg2-min-size-aa6956858930
Best regards,
--
Arun Iyengar <aiyengar1990@gmail.com>
reply other threads:[~2026-12-05 22:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261205-hantro-mpeg2-min-size-v1-1-dfeb36b9f397@gmail.com \
--to=devnull+aiyengar1990.gmail.com@kernel.org \
--cc=aiyengar1990@gmail.com \
--cc=benjamin.gaignard@collabora.com \
--cc=boris.brezillon@collabora.com \
--cc=ezequiel@vanguardiasur.com.ar \
--cc=hverkuil@kernel.org \
--cc=jonas@kwiboo.se \
--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®