[PATCH 7/8] media: mtk-mdp: Refuse a format change once buffers are allocated
From: Ryan Brue
Date: Fri Nov 20 2026 - 14:56:26 EST
VIDIOC_S_FMT stores the new format in the frame before it checks whether
the queue is streaming, so a refused change still takes effect: a client
switching a streaming CAPTURE queue from NV12M to YUV420M gets -EBUSY,
and the next frame is set up for three planes in buffers that have two.
And the check is for streaming only, so a format set after
VIDIOC_REQBUFS can need more than the buffers already allocated.
Check first, and refuse once the queue has buffers, as vb2_is_busy()
does for other drivers, logging it at debug level since any client can
trigger it.
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 | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/media/platform/mediatek/mdp/mtk_mdp_m2m.c b/drivers/media/platform/mediatek/mdp/mtk_mdp_m2m.c
index e0627127430b..1be0f44fe1b2 100644
--- a/drivers/media/platform/mediatek/mdp/mtk_mdp_m2m.c
+++ b/drivers/media/platform/mediatek/mdp/mtk_mdp_m2m.c
@@ -698,6 +698,12 @@ static int mtk_mdp_m2m_s_fmt_mplane(struct file *file, void *fh,
mtk_mdp_dbg(2, "[%d] type:%d", ctx->id, f->type);
+ vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type);
+ if (vb2_is_busy(vq)) {
+ dev_dbg(&ctx->mdp_dev->pdev->dev, "queue %d busy\n", f->type);
+ return -EBUSY;
+ }
+
frame = mtk_mdp_ctx_get_frame(ctx, f->type);
fmt = mtk_mdp_try_fmt_mplane(ctx, f);
if (!fmt) {
@@ -706,12 +712,6 @@ static int mtk_mdp_m2m_s_fmt_mplane(struct file *file, void *fh,
}
frame->fmt = fmt;
- vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type);
- if (vb2_is_streaming(vq)) {
- dev_info(&ctx->mdp_dev->pdev->dev, "queue %d busy", f->type);
- return -EBUSY;
- }
-
pix_mp = &f->fmt.pix_mp;
for (i = 0; i < frame->fmt->num_planes; i++) {
frame->payload[i] = pix_mp->plane_fmt[i].sizeimage;
--
2.56.0