Message ID | b98dcc94-13f3-a6cb-f5bd-f1f8644d87d1@web.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | media: mediatek: vcodec: Move a variable assignment behind condition checks in vdec_vp9_slice_single_decode() | expand |
Il 14/04/23 20:30, Markus Elfring ha scritto: > 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@users.sourceforge.net> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
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@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; 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 >
Date: Mon, 17 Apr 2023 14:32:14 +0200 The deletion of an if statement was requested by Hans Verkuil. This update triggered another change possibility. Markus Elfring (2): Delete null pointer checks Move variable assignments behind null pointer checks .../mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) -- 2.40.0
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);
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@users.sourceforge.net> --- .../media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.40.0