[PATCH] media: mediatek: vcodec: handle request allocation failure

From: Ziheng Wei

Date: Sun Nov 22 2026 - 11:05:25 EST


fops_media_request_alloc() returns &req->req even when allocation fails.
Since req follows struct kref in struct mtk_vcodec_dec_request, this is a
non-NULL offset pointer. media_request_alloc() misses its NULL check and
dereferences it.

Return NULL on allocation failure so the caller reports -ENOMEM.

Found by LLM-assisted static analysis. Build tested with allmodconfig;
no runtime fault-injection test.

Fixes: 1b78aae6313f ("media: mediatek: vcodec: Implement manual request completion")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Ziheng Wei <zihengw03@xxxxxxx>
---
.../platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c
index ab1894fba..626c8368b 100644
--- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c
+++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c
@@ -736,6 +736,8 @@ static struct media_request *fops_media_request_alloc(struct media_device *mdev)
struct mtk_vcodec_dec_request *req;

req = kzalloc_obj(*req);
+ if (!req)
+ return NULL;

return &req->req;
}

base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
--
2.43.0