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

From: Hans Verkuil
Date: Mon Apr 17 2023 - 04:02:17 EST


On 14/04/2023 20:30, Markus Elfring wrote:
> 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")

Not a fix, it was never broken.

> Signed-off-by: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
> ---
> .../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;

Just drop these lines instead:

if (!instance || !instance->ctx)
return -EINVAL;

That can never happen.

Regards,

Hans

> - 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
>