[PATCH v2 2/2] media: mediatek: vcodec: Complete request on NULL va in stateless decoder
Fei Shao
fshao at chromium.org
Fri Oct 23 00:55:20 PDT 2026
If vb2_plane_vaddr() returns NULL for the source buffer because it has
no kernel mapping, mtk_vdec_worker() finishes the m2m job without
returning any buffer or completing the media request, so userspace
waiting on the request never gets a result. The source buffer was only
peeked and stays at the head of the ready list, so
v4l2_m2m_job_finish() also schedules the same job again, which fails
the same way.
Remove the source buffer from the ready list and return it with
VB2_BUF_STATE_ERROR, complete the request controls, and manually
complete the media request before finishing the job. Look up the
request before the address check and log the error before returning
the buffer.
Fixes: 7b182b8d9c85 ("media: mediatek: vcodec: Refactor get and put capture buffer flow")
Signed-off-by: Fei Shao <fshao at chromium.org>
---
Changes in v2:
- Call media_request_manual_complete() instead of
mtk_vdec_stateless_cap_to_disp() to avoid dequeuing a capture buffer
that may be in use by the core workqueue on MediaTek LAT platforms.
.../vcodec/decoder/mtk_vcodec_dec_stateless.c | 22 ++++++++++++-------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c
index ab1894fba0d9..402d20572f2d 100644
--- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c
+++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c
@@ -342,23 +342,29 @@ static void mtk_vdec_worker(struct work_struct *work)
bs_src->va = vb2_plane_vaddr(vb2_src, 0);
bs_src->dma_addr = vb2_dma_contig_plane_dma_addr(vb2_src, 0);
bs_src->size = (size_t)vb2_src->planes[0].bytesused;
- if (!bs_src->va) {
+
+ mreq = vb2_src->req_obj.req;
+ if (WARN_ON(!mreq)) {
v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx);
+ mtk_v4l2_vdec_err(ctx, "vb2 buffer media request is NULL");
+ return;
+ }
+
+ if (!bs_src->va) {
mtk_v4l2_vdec_err(ctx, "[%d] id=%d source buffer is NULL", ctx->id,
vb2_src->index);
+ v4l2_ctrl_request_complete(mreq, &ctx->ctrl_hdl);
+ v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
+ v4l2_m2m_buf_done(vb2_v4l2_src, VB2_BUF_STATE_ERROR);
+ media_request_manual_complete(mreq);
+ v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx);
return;
}
mtk_v4l2_vdec_dbg(3, ctx, "[%d] Bitstream VA=%p DMA=%pad Size=%zx vb=%p",
ctx->id, bs_src->va, &bs_src->dma_addr, bs_src->size, vb2_src);
- /* Apply request controls. */
- mreq = vb2_src->req_obj.req;
- if (WARN_ON(!mreq)) {
- v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx);
- mtk_v4l2_vdec_err(ctx, "vb2 buffer media request is NULL");
- return;
- }
+ /* Apply request controls. */
v4l2_ctrl_request_setup(mreq, &ctx->ctrl_hdl);
/* Keep a reference so that if the processing completes before this function
--
2.56.0.257.gf7497c7d27-goog
More information about the Linux-mediatek
mailing list