mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ryan Brue <ryanbrue.dev@gmail.com>
To: Tiffany Lin <tiffany.lin@mediatek.com>,
	 Andrew-CT Chen <andrew-ct.chen@mediatek.com>,
	 Yunfei Dong <yunfei.dong@mediatek.com>,
	 Mauro Carvalho Chehab <mchehab@kernel.org>,
	 Matthias Brugger <matthias.bgg@gmail.com>,
	 AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	 Hans Verkuil <hverkuil@kernel.org>,
	 Minghsiu Tsai <minghsiu.tsai@mediatek.com>,
	 Houlong Wei <houlong.wei@mediatek.com>,
	 Enric Balletbo i Serra <eballetbo@kernel.org>,
	 Eizan Miyamoto <eizan@chromium.org>,
	 Francois Buergisser <fbuergisser@chromium.org>
Cc: Nicolas Dufresne <nicolas.dufresne@collabora.com>,
	 Youngjoon Lee <getfeus@gmail.com>,
	linux-media@vger.kernel.org,  linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	 linux-mediatek@lists.infradead.org,
	 Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
	 Ryan Brue <ryanbrue.dev@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH v2 7/9] media: mtk-mdp: Refuse a format change once buffers are allocated
Date: Wed, 25 Nov 2026 14:16:10 -0600	[thread overview]
Message-ID: <20261125-rbrue-suez-upstreaming-mtk-vcodec-mdp-fixes-v2-7-fdc047cf75a5@gmail.com> (raw)
In-Reply-To: <20261125-rbrue-suez-upstreaming-mtk-vcodec-mdp-fixes-v2-0-fdc047cf75a5@gmail.com>

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")
Cc: stable@vger.kernel.org
Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com>
---
 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.1


  parent reply	other threads:[~2026-11-25 20:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 20:16 [PATCH v2 0/9] media: mediatek: Fix MT8173 decoding through GStreamer Ryan Brue
2026-11-25 20:16 ` [PATCH v2 1/9] media: mediatek: vcodec: Decode H.264 access units on MT8173 Ryan Brue
2026-11-25 20:16 ` [PATCH v2 2/9] media: mediatek: vcodec: Pick an OUTPUT buffer size when given zero Ryan Brue
2026-11-25 20:16 ` [PATCH v2 3/9] media: mediatek: vcodec: Report the visible rectangle as default compose Ryan Brue
2026-11-25 20:16 ` [PATCH v2 4/9] media: mtk-mdp: Round MT21C sources up to whole tiles Ryan Brue
2026-11-25 20:16 ` [PATCH v2 5/9] media: mtk-mdp: Do not refuse a crop for the other side's size Ryan Brue
2026-11-25 20:16 ` [PATCH v2 6/9] media: mtk-mdp: Check buffer plane sizes against the format Ryan Brue
2026-11-25 20:16 ` Ryan Brue [this message]
2026-11-25 20:16 ` [PATCH v2 8/9] media: mediatek: vcodec: Refuse a format change once buffers are allocated Ryan Brue
2026-11-25 20:16 ` [PATCH v2 9/9] media: mediatek: vcodec: Flag the last buffer before a resolution change Ryan Brue

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=20261125-rbrue-suez-upstreaming-mtk-vcodec-mdp-fixes-v2-7-fdc047cf75a5@gmail.com \
    --to=ryanbrue.dev@gmail.com \
    --cc=andrew-ct.chen@mediatek.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=eballetbo@kernel.org \
    --cc=eizan@chromium.org \
    --cc=fbuergisser@chromium.org \
    --cc=getfeus@gmail.com \
    --cc=houlong.wei@mediatek.com \
    --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-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=mchehab+huawei@kernel.org \
    --cc=mchehab@kernel.org \
    --cc=minghsiu.tsai@mediatek.com \
    --cc=nicolas.dufresne@collabora.com \
    --cc=stable@vger.kernel.org \
    --cc=tiffany.lin@mediatek.com \
    --cc=yunfei.dong@mediatek.com \
    /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®