[PATCH v2 1/2] media: mediatek: vcodec: Return source buffer on NULL va in stateful decoder

Nicolas Dufresne nicolas at ndufresne.ca
Thu Nov 26 11:17:52 PST 2026


Hi Fei,

sorry for the delay, so many patches...

Le vendredi 23 octobre 2026 à 15:55 +0800, Fei Shao a écrit :
> mtk_vdec_worker() peeks the source buffer with v4l2_m2m_next_src_buf().
> If vb2_plane_vaddr() returns NULL because the buffer has no kernel
> mapping, the worker finishes the m2m job with the buffer still at the
> head of the ready list. v4l2_m2m_job_finish() then schedules the same
> job again, which fails the same way, so the decoder never makes
> progress.
> 
> Remove the buffer from the ready list so that the job is not scheduled
> again, and return it with VB2_BUF_STATE_ERROR so that userspace gets it
> back. Print the error before that, as the buffer must not be touched
> once it is returned.
> 
> Fixes: 590577a4e525 ("[media] vcodec: mediatek: Add Mediatek V4L2 Video Decoder Driver")
> Signed-off-by: Fei Shao <fshao at chromium.org>
> 
> ---
> 
> (no changes since v1)
> 
>  .../mediatek/vcodec/decoder/mtk_vcodec_dec_stateful.c         | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateful.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateful.c
> index aa9bdee7a96c..a4cbb7c76998 100644
> --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateful.c
> +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateful.c
> @@ -348,9 +348,11 @@ static void mtk_vdec_worker(struct work_struct *work)
>  	buf.dma_addr = vb2_dma_contig_plane_dma_addr(&src_buf->vb2_buf, 0);
>  	buf.size = (size_t)src_buf->vb2_buf.planes[0].bytesused;
>  	if (!buf.va) {
> -		v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx);
>  		mtk_v4l2_vdec_err(ctx, "[%d] id=%d src_addr is NULL!!", ctx->id,
>  				  src_buf->vb2_buf.index);
> +		v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
> +		v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_ERROR);
> +		v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx);

I did some research as all this felt very late and defensive. My conclusion is
that you should validate this in vb2ops_vdec_buf_prepare() (mtk_vcodec_dec.c).
This will let you remove this defensive check. Buffers that failed to map (or
unmappable/protected memory?) will simply not endup in the queue. It will also
give an immediate feedback to userspace.

Nicolas

>  		return;
>  	}
>  	mtk_v4l2_vdec_dbg(3, ctx, "[%d] Bitstream VA=%p DMA=%pad Size=%zx vb=%p",
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20261126/a856a6f7/attachment.sig>


More information about the linux-arm-kernel mailing list