[PATCH 3/3] media: mediatek: jpeg: cancel job timeout work before m2m release

Nicolas Dufresne nicolas.dufresne at collabora.com
Thu Nov 19 10:35:18 PST 2026


Hi,

Le mardi 25 août 2026 à 03:34 +0800, Shengzhuo Wei a écrit :
> Each job arms jpeg->job_timeout_work, cancelled only by the IRQ
> completion path. If a job stalls, mtk_jpeg_remove() frees
> jpeg->m2m_dev via v4l2_m2m_release() with the timeout still pending,
> and mtk_jpeg_job_timeout_work() then dereferences the freed m2m_dev
> and the stale ctx it returns -- a use-after-free.
> 
> Drain the work before the m2m device is released. The device-level
> job_timeout_work was missed by the earlier fix for ctx->jpeg_work.
> 
> Fixes: 5fb1c2361e56 ("mtk-jpegenc: add jpeg encode worker interface")
> Fixes: dedc21500334 ("media: mtk-jpegdec: add jpeg decode worker interface")
> Cc: stable at vger.kernel.org
> Signed-off-by: Shengzhuo Wei <me at cherr.cc>
> Assisted-by: GLM:5.3
> ---
>  drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> index d147ec48308110ae8520662e182dc0445447d8d0..f0fe14e83d515f5011cbfe051abbf565568013d0 100644
> --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> @@ -1405,6 +1405,7 @@ static void mtk_jpeg_remove(struct platform_device *pdev)
>  
>  	pm_runtime_disable(&pdev->dev);
>  	video_unregister_device(jpeg->vdev);
> +	cancel_delayed_work_sync(&jpeg->job_timeout_work);

A similar fix was made by Fan We, instead of doing it in remove, it actually
sync on the delayed work in stop streaming:

https://lore.kernel.org/lkml/20260623103031.3051-1-fanwu01@zju.edu.cn/

This way, whatever gets added in the timeout later won't possibly outlive the
instance. Might be just extra cautious for this specific driver, but I'd rather
fix it once, then having this fixed again later.

In some ways, your Sashiko review tends to verbosely lean toward this.

Nicolas

>  	v4l2_m2m_release(jpeg->m2m_dev);
>  	v4l2_device_unregister(&jpeg->v4l2_dev);
>  }
-------------- 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/20261119/fabb3ff1/attachment.sig>


More information about the linux-arm-kernel mailing list