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 5/9] media: mtk-mdp: Do not refuse a crop for the other side's size
Date: Wed, 25 Nov 2026 14:16:08 -0600 [thread overview]
Message-ID: <20261125-rbrue-suez-upstreaming-mtk-vcodec-mdp-fixes-v2-5-fdc047cf75a5@gmail.com> (raw)
In-Reply-To: <20261125-rbrue-suez-upstreaming-mtk-vcodec-mdp-fixes-v2-0-fdc047cf75a5@gmail.com>
Setting the source crop checks the scaling ratio against the destination
as it stands: the 32x32 default that open() sets, or whatever a client
set while probing. GStreamer sets the source format and crop first, and
a 1280x720 crop was refused with -EINVAL against that 32x32 destination.
The same holds for the compose rectangle and the source, and for the
rotation control.
Check the ratio once both queues are streaming, when both sizes are
settled: at VIDIOC_STREAMON, and for a crop, compose or rotation change
made while streaming. VIDIOC_STREAMON is the first point where both
sizes are known: before it a client may still set either side in any
order, and checking there leaves the queues untouched on refusal. Log a
refusal at debug level, since any client can trigger it.
Fixes: 0d1e342a17f5 ("media: mtk-mdp: Remove states for format checks")
Cc: stable@vger.kernel.org
Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com>
---
drivers/media/platform/mediatek/mdp/mtk_mdp_m2m.c | 121 +++++++++++++---------
1 file changed, 73 insertions(+), 48 deletions(-)
diff --git a/drivers/media/platform/mediatek/mdp/mtk_mdp_m2m.c b/drivers/media/platform/mediatek/mdp/mtk_mdp_m2m.c
index 34d02de4453d..a40bcf61b7ca 100644
--- a/drivers/media/platform/mediatek/mdp/mtk_mdp_m2m.c
+++ b/drivers/media/platform/mediatek/mdp/mtk_mdp_m2m.c
@@ -727,10 +727,40 @@ static int mtk_mdp_m2m_reqbufs(struct file *file, void *fh,
return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs);
}
+static int mtk_mdp_check_scaler_ratio(struct mtk_mdp_variant *var, int src_w,
+ int src_h, int dst_w, int dst_h, int rot)
+{
+ int tmp_w, tmp_h;
+
+ if (rot == 90 || rot == 270) {
+ tmp_w = dst_h;
+ tmp_h = dst_w;
+ } else {
+ tmp_w = dst_w;
+ tmp_h = dst_h;
+ }
+
+ if ((src_w / tmp_w) > var->h_scale_down_max ||
+ (src_h / tmp_h) > var->v_scale_down_max ||
+ (tmp_w / src_w) > var->h_scale_up_max ||
+ (tmp_h / src_h) > var->v_scale_up_max)
+ return -EINVAL;
+
+ return 0;
+}
+
+/* Both sizes are settled once both queues are streaming */
+static bool mtk_mdp_ctx_streaming(struct mtk_mdp_ctx *ctx)
+{
+ return vb2_is_streaming(v4l2_m2m_get_src_vq(ctx->m2m_ctx)) &&
+ vb2_is_streaming(v4l2_m2m_get_dst_vq(ctx->m2m_ctx));
+}
+
static int mtk_mdp_m2m_streamon(struct file *file, void *fh,
enum v4l2_buf_type type)
{
struct mtk_mdp_ctx *ctx = file_to_ctx(file);
+ struct vb2_queue *other;
int ret;
if (!mtk_mdp_ctx_state_is_set(ctx, MTK_MDP_VPU_INIT)) {
@@ -744,6 +774,21 @@ static int mtk_mdp_m2m_streamon(struct file *file, void *fh,
mtk_mdp_ctx_state_lock_set(ctx, MTK_MDP_VPU_INIT);
}
+ /* the queue that starts second checks the ratio */
+ other = v4l2_m2m_get_vq(ctx->m2m_ctx, V4L2_TYPE_IS_OUTPUT(type) ?
+ V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE :
+ V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
+ if (vb2_is_streaming(other) &&
+ mtk_mdp_check_scaler_ratio(ctx->mdp_dev->variant,
+ ctx->s_frame.crop.width,
+ ctx->s_frame.crop.height,
+ ctx->d_frame.crop.width,
+ ctx->d_frame.crop.height,
+ ctx->ctrls.rotate->val)) {
+ dev_dbg(&ctx->mdp_dev->pdev->dev, "Out of scaler range\n");
+ return -EINVAL;
+ }
+
return v4l2_m2m_streamon(file, ctx->m2m_ctx, type);
}
@@ -810,35 +855,12 @@ static int mtk_mdp_m2m_g_selection(struct file *file, void *fh,
return -EINVAL;
}
-static int mtk_mdp_check_scaler_ratio(struct mtk_mdp_variant *var, int src_w,
- int src_h, int dst_w, int dst_h, int rot)
-{
- int tmp_w, tmp_h;
-
- if (rot == 90 || rot == 270) {
- tmp_w = dst_h;
- tmp_h = dst_w;
- } else {
- tmp_w = dst_w;
- tmp_h = dst_h;
- }
-
- if ((src_w / tmp_w) > var->h_scale_down_max ||
- (src_h / tmp_h) > var->v_scale_down_max ||
- (tmp_w / src_w) > var->h_scale_up_max ||
- (tmp_h / src_h) > var->v_scale_up_max)
- return -EINVAL;
-
- return 0;
-}
-
static int mtk_mdp_m2m_s_selection(struct file *file, void *fh,
struct v4l2_selection *s)
{
struct mtk_mdp_ctx *ctx = file_to_ctx(file);
struct mtk_mdp_frame *frame;
struct v4l2_rect new_r;
- struct mtk_mdp_variant *variant = ctx->mdp_dev->variant;
int ret;
bool valid = false;
@@ -865,22 +887,27 @@ static int mtk_mdp_m2m_s_selection(struct file *file, void *fh,
else
frame = &ctx->d_frame;
- /* Check to see if scaling ratio is within supported range */
- if (V4L2_TYPE_IS_OUTPUT(s->type))
- ret = mtk_mdp_check_scaler_ratio(variant, new_r.width,
- new_r.height, ctx->d_frame.crop.width,
- ctx->d_frame.crop.height,
- ctx->ctrls.rotate->val);
- else
- ret = mtk_mdp_check_scaler_ratio(variant,
- ctx->s_frame.crop.width,
- ctx->s_frame.crop.height, new_r.width,
- new_r.height, ctx->ctrls.rotate->val);
-
- if (ret) {
- dev_info(&ctx->mdp_dev->pdev->dev,
- "Out of scaler range");
- return -EINVAL;
+ /*
+ * Until both queues are streaming the other side's size may still
+ * change, and VIDIOC_STREAMON checks the scaling ratio.
+ */
+ if (mtk_mdp_ctx_streaming(ctx)) {
+ struct v4l2_rect *src = &ctx->s_frame.crop;
+ struct v4l2_rect *dst = &ctx->d_frame.crop;
+
+ if (V4L2_TYPE_IS_OUTPUT(s->type))
+ src = &new_r;
+ else
+ dst = &new_r;
+
+ if (mtk_mdp_check_scaler_ratio(ctx->mdp_dev->variant,
+ src->width, src->height,
+ dst->width, dst->height,
+ ctx->ctrls.rotate->val)) {
+ dev_dbg(&ctx->mdp_dev->pdev->dev,
+ "Out of scaler range\n");
+ return -EINVAL;
+ }
}
s->r = new_r;
@@ -953,7 +980,6 @@ static int mtk_mdp_s_ctrl(struct v4l2_ctrl *ctrl)
struct mtk_mdp_ctx *ctx = ctrl_to_ctx(ctrl);
struct mtk_mdp_dev *mdp = ctx->mdp_dev;
struct mtk_mdp_variant *variant = mdp->variant;
- int ret = 0;
if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE)
return 0;
@@ -966,14 +992,13 @@ static int mtk_mdp_s_ctrl(struct v4l2_ctrl *ctrl)
ctx->vflip = ctrl->val;
break;
case V4L2_CID_ROTATE:
- ret = mtk_mdp_check_scaler_ratio(variant,
- ctx->s_frame.crop.width,
- ctx->s_frame.crop.height,
- ctx->d_frame.crop.width,
- ctx->d_frame.crop.height,
- ctx->ctrls.rotate->val);
-
- if (ret)
+ if (mtk_mdp_ctx_streaming(ctx) &&
+ mtk_mdp_check_scaler_ratio(variant,
+ ctx->s_frame.crop.width,
+ ctx->s_frame.crop.height,
+ ctx->d_frame.crop.width,
+ ctx->d_frame.crop.height,
+ ctx->ctrls.rotate->val))
return -EINVAL;
ctx->rotation = ctrl->val;
--
2.56.1
next prev 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 ` Ryan Brue [this message]
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 ` [PATCH v2 7/9] media: mtk-mdp: Refuse a format change once buffers are allocated Ryan Brue
2026-11-25 20:16 ` [PATCH v2 8/9] media: mediatek: vcodec: " 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-5-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®