* [PATCH] media: verisilicon: Refuse MPEG-2 sequences below the minimum size
@ 2026-12-05 22:48 Arun Iyengar via B4 Relay
0 siblings, 0 replies; only message in thread
From: Arun Iyengar via B4 Relay @ 2026-12-05 22:48 UTC (permalink / raw)
To: Nicolas Dufresne, Benjamin Gaignard, Philipp Zabel,
Mauro Carvalho Chehab, Hans Verkuil, Boris Brezillon,
Ezequiel Garcia, Jonas Karlman
Cc: linux-media, linux-rockchip, linux-kernel, Arun Iyengar
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>
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-05 22:48 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-05 22:48 [PATCH] media: verisilicon: Refuse MPEG-2 sequences below the minimum size Arun Iyengar via B4 Relay
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®