Re: [PATCH] media: mediatek: vcodec: Initialize context lock before firmware setup

From: Nicolas Dufresne

Date: Sun Oct 04 2026 - 07:18:01 EST


Hi,

Le dimanche 30 août 2026 à 22:48 +0800, Runyu Xiao a écrit :
> The VPU firmware setup registers a watchdog callback that accesses the
> encoder context lock. Initialize the lock before selecting the firmware
> implementation so the callback cannot observe an uninitialized lock during
> probe.
>
> Fixes: afaaf3a0f647 ("media: mediatek: vcodec: adding lock to protect encoder context list")
> Cc: stable@xxxxxxxxxxxxxxx
> Assisted-by: Codex:GPT-5
> Signed-off-by: Runyu Xiao <runyu.xiao@xxxxxxxxxx>
> ---
> .../media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c
> index 4e4541b2f..e6cd3817a 100644
> --- a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c
> +++ b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c
> @@ -255,6 +255,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
>
> INIT_LIST_HEAD(&dev->ctx_list);
> dev->plat_dev = pdev;
> + spin_lock_init(&dev->dev_ctx_lock);

I'll have to reject this one for now since the theory of a callback taking the
lock while the probe is happening does not hold. The very first place the lock
will be taken is in _open() and that cannot happen before
video_register_device(), which is kept last. Please demonstrate what the issue
you are suggesting if you'd like to see this merged.

Nicolas

>
> if (!of_property_read_u32(pdev->dev.of_node, "mediatek,vpu",
> &rproc_phandle)) {
> @@ -308,7 +309,6 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
>
> mutex_init(&dev->enc_mutex);
> mutex_init(&dev->dev_mutex);
> - spin_lock_init(&dev->dev_ctx_lock);
> spin_lock_init(&dev->irqlock);
>
> snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name), "%s",

Attachment: signature.asc
Description: This is a digitally signed message part