Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kyrie Wu" <kyrie.wu@mediatek.com>
Cc: devicetree@vger.kernel.org, media-ci@linuxtv.org,
	conor+dt@kernel.org, robh@kernel.org
Subject: Re: [PATCH v7 03/14] media: mediatek: vcodec: add driver to support vcp encoder
Date: Wed, 23 Sep 2026 03:06:18 +0000	[thread overview]
Message-ID: <20260923030618.91DCF1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260923024258.257846-4-kyrie.wu@mediatek.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Missing device tree parsing makes VCP encoder initialization dead code
- [High] Stub mtk_vcodec_vcp_dm_addr() returns NULL causing encoder init failure
- [High] IPI ID mismatch causes VCP encoder IPI registration and messaging to fail
--

commit 28bb4d159c923a5740008e975162078560f6eee9
Author: Kyrie Wu <kyrie.wu@mediatek.com>

media: mediatek: vcodec: add driver to support vcp encoder
    
Encoder also need to call vcp interface to communicate with vcp,
add driver to support encoder.

> diff --git a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vcp.c b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vcp.c
> index 150d842c7d226..ece4e3e87e62d 100644
> --- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vcp.c
> +++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vcp.c
> @@ -223,8 +225,13 @@ static int mtk_vcodec_vcp_msg_ipi_send(struct mtk_vcodec_fw *fw, int id, void *b
>  	}
>  
>  	mutex_lock(&vcp->ipi_mutex);
> -	feature_id = VDEC_FEATURE_ID;
> -	mailbox_id = IPI_OUT_VDEC_1;
> +	if (fw->fw_use == ENCODER) {
> +		feature_id = VENC_FEATURE_ID;
> +		mailbox_id = IPI_OUT_VENC_0;
> +	} else {
> +		feature_id = VDEC_FEATURE_ID;
> +		mailbox_id = IPI_OUT_VDEC_1;
> +	}

[Severity: High]
Does this code handle the IPI IDs used by the encoder correctly?

The VCP firmware abstraction requires the IPI id to be less than VCP_IPI_MAX
(which is 3). However, the encoder driver initializes its vpu->id to values
like SCP_IPI_VENC_H264 (4) or IPI_VENC_VP8 (5).

For example, in venc_h264_if.c:

drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c:venc_h264_init() {
    ...
    inst->vpu_inst.id = SCP_IPI_VENC_H264;
    ...
}

When this id is passed to mtk_vcodec_vcp_msg_ipi_send() and checked against
mtk_vcodec_vcp_ipi_id_valid(), won't validation fail and return -EINVAL?
This would prevent the VCP encoder from successfully sending messages.

Note that while patch 04 ('media: mediatek: vcodec: get different firmware
ipi id') fixes this mapping for decoders via mtk_vcodec_fw_get_ipi(), it
appears to completely omit the encoder implementations.

[ ... ]

> @@ -402,6 +414,26 @@ static int mtk_vcodec_vcp_load_firmware(struct mtk_vcodec_fw *fw)
>  		mutex_init(&fw->vcp->ipi_desc[i].lock);
>  	mutex_init(&fw->vcp->ipi_mutex);
>  
> +	if (fw->fw_use == ENCODER) {
> +		init_waitqueue_head(&fw->vcp->msg_wq[VCP_IPI_ENCODER]);
> +		fw->vcp->msg_thread =
> +			kthread_run(mtk_vcodec_vcp_msg_process_thread, fw, "vcp_enc_msq_thread");
> +		if (IS_ERR(fw->vcp->msg_thread)) {
> +			ret = PTR_ERR(fw->vcp->msg_thread);
> +			fw->vcp->msg_thread = NULL;
> +			goto err_deregister_feature;
> +		}
> +
> +		fw->vcp->vsi_addr = vcp_device->ops->get_mem_virt(vcp_device, mem_id);
> +		fw->vcp->vsi_size = vcp_device->ops->get_mem_size(vcp_device, mem_id);
> +		fw->vcp->iova_addr = vcp_device->ops->get_mem_iova(vcp_device, mem_id);
> +
> +		dev_dbg(&fw->pdev->dev, "enc vcp init done => va: %p size:0x%x iova:%pad.\n",
> +			fw->vcp->vsi_addr, fw->vcp->vsi_size, &fw->vcp->iova_addr);
> +
> +		return 0;
> +	}

[Severity: High]
Does the encoder receive a valid VSI pointer during initialization?

In mtk_vcodec_fw_vcp.c, mtk_vcodec_vcp_dm_addr() is currently a stub that
unconditionally returns NULL:

drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vcp.c:mtk_vcodec_vcp_dm_addr() {
    static void *mtk_vcodec_vcp_dm_addr(struct mtk_vcodec_fw *fw, u32 dtcm_dmem_addr)
    {
        return NULL;
    }
}

When the encoder receives VPU_IPIMSG_ENC_INIT_DONE, it calls
mtk_vcodec_fw_map_dm_addr(), which invokes this stub and causes vpu->vsi
to be NULL.

The core encoder initialization then explicitly rejects a NULL VSI address:

drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c:vpu_enc_init() {
    ...
    if (IS_ERR_OR_NULL(vpu->vsi)) {
        mtk_venc_err(vpu->ctx, "invalid venc vsi");
        return -EINVAL;
    }
    ...
}

Will this cause VCP encoder initialization to unconditionally fail?

Even though patch 05 ('media: mediatek: vcodec: get share memory address')
updates this function to switch on mem_type, won't the caller in venc_vpu_if.c
still pass a remote instance address (e.g., msg->vpu_inst_addr) rather than
the expected ENCODER_MEM enum value? This would hit the default case and
still return NULL at the end of the series.

[ ... ]

> @@ -530,7 +562,11 @@ struct mtk_vcodec_fw *mtk_vcodec_fw_vcp_init(void *priv, enum mtk_vcodec_fw_use
>  	struct mtk_vcodec_fw *fw;
>  	int i;
>  
> -	if (fw_use == DECODER) {
> +	if (fw_use == ENCODER) {
> +		struct mtk_vcodec_enc_dev *enc_dev = priv;
> +
> +		plat_dev = enc_dev->plat_dev;
> +	} else if (fw_use == DECODER) {
>  		struct mtk_vcodec_dec_dev *dec_dev = priv;
>  
>  		plat_dev = dec_dev->plat_dev;

[Severity: High]
Is the newly added VCP encoder initialization unreachable due to missing
device tree parsing?

While this patch adds VCP firmware support for the encoder, the encoder's
probe function only checks for mediatek,vpu and mediatek,scp:

drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c:mtk_vcodec_probe() {
    ...
    } else if (!of_property_read_u32(pdev->dev.of_node, "mediatek,scp",
                                     &rproc_phandle)) {
        fw_type = SCP;
        dev->fw_init = mtk_vcodec_fw_scp_init;
    } else {
        dev_err(&pdev->dev, "[MTK VCODEC] Could not get venc IPI device");
        return -ENODEV;
    }
    ...
}

Since mediatek,vcp is never checked, won't the driver return -ENODEV if an
encoder node specifies it? The assignment to mtk_vcodec_fw_vcp_init seems
to be missing from the encoder probe path.

This appears to remain unfixed through the end of the patch series.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260923024258.257846-1-kyrie.wu@mediatek.com?part=3

  reply	other threads:[~2026-09-23  3:06 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23  2:42 [PATCH v7 00/14] media: mediatek: vcodec: support video decoder in mt8196 Kyrie Wu
2026-09-23  2:42 ` [PATCH v7 01/14] media: mediatek: vcodec: support vcp architecture Kyrie Wu
2026-09-23  2:42 ` [PATCH v7 02/14] media: mediatek: vcodec: add driver to support vcp Kyrie Wu
2026-09-23  2:57   ` sashiko-bot
2026-09-23  2:42 ` [PATCH v7 03/14] media: mediatek: vcodec: add driver to support vcp encoder Kyrie Wu
2026-09-23  3:06   ` sashiko-bot [this message]
2026-09-23  2:42 ` [PATCH v7 04/14] media: mediatek: vcodec: get different firmware ipi id Kyrie Wu
2026-09-23  3:03   ` sashiko-bot
2026-09-23  2:42 ` [PATCH v7 05/14] media: mediatek: vcodec: get share memory address Kyrie Wu
2026-09-23  2:58   ` sashiko-bot
2026-09-23  2:42 ` [PATCH v7 06/14] media: mediatek: vcodec: add debug information Kyrie Wu
2026-09-23  2:42 ` [PATCH v7 07/14] media: mediatek: vcodec: send share memory address to vcp Kyrie Wu
2026-09-23  2:42 ` [PATCH v7 08/14] Add the MT8196 compatible string to the MediaTek vcodec subdev decoder binding Kyrie Wu
2026-10-06 14:35   ` Rob Herring
2026-09-23  2:42 ` [PATCH v7 09/14] media: mediatek: vcodec: add decoder compatible to support mt8196 Kyrie Wu
2026-09-23  2:42 ` [PATCH v7 10/14] media: mediatek: vcodec: define MT8196 vcodec levels Kyrie Wu
2026-09-23  2:42 ` [PATCH v7 11/14] media: mediatek: vcodec: support 36bit iova address Kyrie Wu
2026-09-23  2:42 ` [PATCH v7 12/14] media: mediatek: vcodec: clean xpc status Kyrie Wu
2026-09-23  3:02   ` sashiko-bot
2026-09-23  2:42 ` [PATCH v7 13/14] media: mediatek: decoder: fill av1 buffer size with picinfo Kyrie Wu
2026-09-23  2:42 ` [PATCH v7 14/14] media: mediatek: decoder: support av1 extend vsi Kyrie Wu
2026-09-23  3:00   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260923030618.91DCF1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=kyrie.wu@mediatek.com \
    --cc=media-ci@linuxtv.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox