[PATCH 6/8] media: mtk-mdp: Check buffer plane sizes against the format

From: Ryan Brue

Date: Fri Nov 20 2026 - 14:56:22 EST


queue_setup() ignores the number of planes and their sizes that come with
VIDIOC_CREATE_BUFS and always answers with the current format, so a
client can allocate buffers too small for it, which v4l2-compliance
reports:

fail: v4l2-test-buffers.cpp(872): q.create_bufs(node, 1, &fmt) != EINVAL

Refuse a request with a different number of planes or a plane smaller
than the format needs, as vb2 expects of queue_setup(), and check each
buffer's planes in buf_prepare() as well.

Fixes: c8eb2d7e8202 ("[media] media: Add Mediatek MDP Driver")
Signed-off-by: Ryan Brue <ryanbrue.dev@xxxxxxxxx>
---
drivers/media/platform/mediatek/mdp/mtk_mdp_m2m.c | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/drivers/media/platform/mediatek/mdp/mtk_mdp_m2m.c b/drivers/media/platform/mediatek/mdp/mtk_mdp_m2m.c
index a40bcf61b7ca..e0627127430b 100644
--- a/drivers/media/platform/mediatek/mdp/mtk_mdp_m2m.c
+++ b/drivers/media/platform/mediatek/mdp/mtk_mdp_m2m.c
@@ -546,6 +546,15 @@ static int mtk_mdp_m2m_queue_setup(struct vb2_queue *vq,
int i;

frame = mtk_mdp_ctx_get_frame(ctx, vq->type);
+ if (*num_planes) {
+ if (*num_planes != frame->fmt->num_planes)
+ return -EINVAL;
+ for (i = 0; i < frame->fmt->num_planes; i++)
+ if (sizes[i] < frame->payload[i])
+ return -EINVAL;
+ return 0;
+ }
+
*num_planes = frame->fmt->num_planes;
for (i = 0; i < frame->fmt->num_planes; i++)
sizes[i] = frame->payload[i];
@@ -563,6 +572,10 @@ static int mtk_mdp_m2m_buf_prepare(struct vb2_buffer *vb)

frame = mtk_mdp_ctx_get_frame(ctx, vb->vb2_queue->type);

+ for (i = 0; i < frame->fmt->num_planes; i++)
+ if (vb2_plane_size(vb, i) < frame->payload[i])
+ return -EINVAL;
+
if (!V4L2_TYPE_IS_OUTPUT(vb->vb2_queue->type)) {
for (i = 0; i < frame->fmt->num_planes; i++)
vb2_set_plane_payload(vb, i, frame->payload[i]);

--
2.56.0