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

From: Fei Shao

Date: Fri Nov 27 2026 - 00:45:57 EST


On Fri, Nov 27, 2026 at 3:17 AM Nicolas Dufresne <nicolas@xxxxxxxxxxxx> wrote:
>
> Hi Fei,
>
> sorry for the delay, so many patches...

No problem at all. Appreciate your time and review!

>
> 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@xxxxxxxxxxxx>
> >
> > ---
> >
> > (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.

Agreed. Early rejection, fewer manual checks and less code overall is
much better.
I sent v3 as a single patch:
https://lore.kernel.org/all/20261127-vcodec-null-va-v3-1-e24521086062@xxxxxxxxxxxx/

Thanks,
Fei


>
> Nicolas
>
> > return;
> > }
> > mtk_v4l2_vdec_dbg(3, ctx, "[%d] Bitstream VA=%p DMA=%pad Size=%zx vb=%p",