[PATCH v2 2/3] media: mediatek: vcodec: unregister VPU watchdog handler
From: Guangshuo Li
Date: Mon Jul 20 2026 - 05:03:41 EST
mtk_vcodec_fw_vpu_init() registers a VPU watchdog reset handler and
passes the vcodec device as the private data.
The handler is stored in the VPU device and can outlive the vcodec
device. If firmware initialization fails after the handler has been
registered, or if the firmware object is later released, the watchdog
table can retain a pointer to a vcodec device that is about to be
released. A later watchdog reset can then call the reset handler with a
stale pointer and dereference freed memory while walking the vcodec
context list.
Unregister the watchdog handler in the firmware initialization failure
path and in the firmware release path before dropping the VPU device
reference.
Fixes: 01abf5fbb081 ("media: mediatek: vcodec: separate struct 'mtk_vcodec_ctx'")
Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
---
.../platform/mediatek/vcodec/common/mtk_vcodec_fw_vpu.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vpu.c b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vpu.c
index 3632037f78f5..ee50a794077f 100644
--- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vpu.c
+++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vpu.c
@@ -40,6 +40,11 @@ static int mtk_vcodec_vpu_ipi_send(struct mtk_vcodec_fw *fw, int id, void *buf,
static void mtk_vcodec_vpu_release(struct mtk_vcodec_fw *fw)
{
+ enum rst_id rst_id;
+
+ rst_id = fw->fw_use == ENCODER ? VPU_RST_ENC : VPU_RST_DEC;
+ vpu_wdt_unreg_handler(fw->pdev, rst_id);
+
put_device(&fw->pdev->dev);
}
@@ -120,6 +125,7 @@ struct mtk_vcodec_fw *mtk_vcodec_fw_vpu_init(void *priv, enum mtk_vcodec_fw_use
fw = devm_kzalloc(&plat_dev->dev, sizeof(*fw), GFP_KERNEL);
if (!fw) {
+ vpu_wdt_unreg_handler(fw_pdev, rst_id);
put_device(&fw_pdev->dev);
return ERR_PTR(-ENOMEM);
}
--
2.43.0