[PATCH] media: mediatek: vcodec: Move a variable assignment behind condition checks in vdec_vp9_slice_single_decode()

Markus Elfring Markus.Elfring at web.de
Fri Apr 14 11:30:16 PDT 2023


Date: Fri, 14 Apr 2023 20:07:01 +0200

The address of a data structure member was determined before
a corresponding null pointer check in the implementation of
the function “vdec_vp9_slice_single_decode”.

Thus avoid the risk for undefined behaviour by moving the assignment
for the variable “pfc” behind some condition checks.

This issue was detected by using the Coccinelle software.

Fixes: b0f407c19648ae9110c932c91d6e1b9381ec0aeb ("media: mediatek: vcodec: add vp9 decoder driver for mt8186")
Signed-off-by: Markus Elfring <elfring at users.sourceforge.net>
---
 .../media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c  | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
index cf16cf2807f0..22b27f7b57bf 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
@@ -1990,7 +1990,7 @@ static int vdec_vp9_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
 					struct vdec_fb *fb, bool *res_chg)
 {
 	struct vdec_vp9_slice_instance *instance = h_vdec;
-	struct vdec_vp9_slice_pfc *pfc = &instance->sc_pfc;
+	struct vdec_vp9_slice_pfc *pfc;
 	struct vdec_vp9_slice_vsi *vsi;
 	struct mtk_vcodec_ctx *ctx;
 	int ret;
@@ -2007,6 +2007,7 @@ static int vdec_vp9_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
 	if (!fb)
 		return -EBUSY;

+	pfc = &instance->sc_pfc;
 	vsi = &pfc->vsi;

 	ret = vdec_vp9_slice_setup_single(instance, bs, fb, pfc);
--
2.40.0




More information about the linux-arm-kernel mailing list