[1/5] media: mediatek: vcodec: Fix getting NULL pointer for dst buffer

Message ID 20221112094144.4256-2-yunfei.dong@mediatek.com
State New
Headers
Series media: mediatek: vcodec: Fix decode random crash for PLT test |

Commit Message

Yunfei Dong (董云飞) Nov. 12, 2022, 9:41 a.m. UTC
  The driver may can't get v4l2 buffer when lat or core decode timeout,
will lead to crash when call v4l2_m2m_buf_done to set dst buffer
(NULL pointer) done.

Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
---
 .../mediatek/vcodec/mtk_vcodec_dec_stateless.c        | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
  

Comments

AngeloGioacchino Del Regno Nov. 14, 2022, 11:15 a.m. UTC | #1
Il 12/11/22 10:41, Yunfei Dong ha scritto:
> The driver may can't get v4l2 buffer when lat or core decode timeout,
> will lead to crash when call v4l2_m2m_buf_done to set dst buffer
> (NULL pointer) done.
> 
> Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>

This commit needs a Fixes tag.

Regards,
Angelo
  

Patch

diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
index c45bd2599bb2..e86809052a9f 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
@@ -138,10 +138,13 @@  static void mtk_vdec_stateless_cap_to_disp(struct mtk_vcodec_ctx *ctx, int error
 		state = VB2_BUF_STATE_DONE;
 
 	vb2_dst = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
-	v4l2_m2m_buf_done(vb2_dst, state);
-
-	mtk_v4l2_debug(2, "free frame buffer id:%d to done list",
-		       vb2_dst->vb2_buf.index);
+	if (vb2_dst) {
+		v4l2_m2m_buf_done(vb2_dst, state);
+		mtk_v4l2_debug(2, "free frame buffer id:%d to done list",
+			       vb2_dst->vb2_buf.index);
+	} else {
+		mtk_v4l2_err("dst buffer is NULL");
+	}
 
 	if (src_buf_req)
 		v4l2_ctrl_request_complete(src_buf_req, &ctx->ctrl_hdl);