media: mediatek: encoder: Fix uninitialized scalar variable issue
Subsystems (3)
PATCH v2 1/1 media: mediatek: encoder: Fix uninitialized scalar variable issue
UNINIT checker finds some instances of variables that are used without being initialized, for example using the uninitialized value enc_result.is_key_frm can result in unpredictable behavior, so initialize these variables after declaring.
---
v2:
- Add Fixes tag, update commit message
- Remove unnecessary memset
- Move memset to before the first usage
--- .../media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c +3 -1
@@ -865,7 +865,7 @@ static void vb2ops_venc_buf_queue(struct vb2_buffer *vb)static int vb2ops_venc_start_streaming (struct vb2_queue *q,unsigned int count) {struct mtk_vcodec_enc_ctx *ctx =vb2_get_drv_priv (q); -struct venc_enc_param param; +struct venc_enc_param param = {0 };int ret;int i;
@@ -1036,6 +1036,7 @@ static int mtk_venc_encode_header(void *priv) ctx->id, dst_buf->vb2_buf.index, bs_buf.va, (u64)bs_buf.dma_addr, bs_buf.size); +memset (&enc_result,0 ,sizeof (enc_result)); ret =venc_if_encode (ctx,VENC_START_OPT_ENCODE_SEQUENCE_HEADER ,NULL , &bs_buf, &enc_result);
@@ -1185,6 +1186,7 @@ static void mtk_venc_worker(struct work_struct *work) (u64 )frm_buf.fb_addr[1 ].dma_addr, frm_buf.fb_addr[1 ].size, (u64)frm_buf.fb_addr[2].dma_addr, frm_buf.fb_addr[2].size); +memset (&enc_result,0 ,sizeof (enc_result)); ret =venc_if_encode (ctx,VENC_START_OPT_ENCODE_FRAME , &frm_buf, &bs_buf, &enc_result);
Signature · 1 line
2.46.0
Le mercredi 16 juillet 2025 à 15:14 +0800, Irui Wang a écrit :
Quoted 37 lines
UNINIT checker finds some instances of variables that are used without being initialized, for example using the uninitialized value enc_result.is_key_frm can result in unpredictable behavior, so initialize these variables after declaring.
Fixes 4e855a6efa54 ("[media] vcodec: mediatek: Add Mediatek V4L2 VideoEncoder Driver")
Signed-off-by Irui Wang <[email protected]>---
v2:
- Add Fixes tag, update commit message
- Remove unnecessary memset
- Move memset to before the first usage
---
.../media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c | 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c +0
-0@@ -865,7 +865,7 @@ static void vb2ops_venc_buf_queue(struct vb2_buffer *vb)static int
vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count)
{
structmtk_vcodec_enc_ctx*ctx =vb2_get_drv_priv(q);drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c +1
-1-struct venc_enc_param param; +struct venc_enc_param param = {0 };int ret;
int i;drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c +0
-0@@ -1036,6 +1036,7 @@ static int mtk_venc_encode_header(void *priv) ctx->id, dst_buf->vb2_buf.index, bs_buf.va, (u64)bs_buf.dma_addr, bs_buf.size);
drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c
Quoted 1 line
drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c +1
-0+memset (&enc_result,0 ,sizeof (enc_result));
Please, apply review comment to all occurrence, so same here.
drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c
Quoted 10 lines
ret =
venc_if_encode(ctx, VENC_START_OPT_ENCODE_SEQUENCE_HEADER, NULL, &bs_buf, &enc_result);drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c +0
-0@@ -1185,6 +1186,7 @@ static void mtk_venc_worker(struct work_struct *work) (u64)frm_buf.fb_addr[1].dma_addr, frm_buf.fb_addr[1 ].size, (u64)frm_buf.fb_addr[2].dma_addr, frm_buf.fb_addr[2].size);drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c +1
-0+memset (&enc_result,0 ,sizeof (enc_result));
Same here.
Quoted 4 lines
ret =
venc_if_encode(ctx, VENC_START_OPT_ENCODE_FRAME, &frm_buf, &bs_buf, &enc_result);
Would be nice to coordinate with Qianfeng Rong <[email protected]> [0], he ported the entire driver to this initialization method, which is clearly the way to go.
- Patch 1 will port the driver to {} stack init
- Patch 2 will add missing initializes
Consistency is key for this type of things since developer usually follow the surrounding style.
regards
Nicolas
[0] https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/
Dear Nicolas,
Thanks for your comments.
Quoted 75 lines · Nicolas Dufresne
Quoted 41 lines · Irui Wang
UNINIT checker finds some instances of variables that are used without being initialized, for example using the uninitialized value enc_result.is_key_frm can result in unpredictable behavior, so initialize these variables after declaring.
Fixes 4e855a6efa54 ("[media] vcodec: mediatek: Add Mediatek V4L2Video
Encoder Driver")Signed-off-by Irui Wang <[email protected]>---
v2:
- Add Fixes tag, update commit message
- Remove unnecessary memset
- Move memset to before the first usage--- .../media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)diff --git
a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.cb/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.cindexa01dc25a7699..3065f3e66336100644
---a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c
+++b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c(quoted diff) +0
-0@@ -865,7 +865,7 @@ static void vb2ops_venc_buf_queue(struct vb2_buffer *vb) static int vb2ops_venc_start_streaming(struct vb2_queue *q,unsigned int
count)
{drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c +1
-1struct mtk_vcodec_enc_ctx *ctx =vb2_get_drv_priv (q); -struct venc_enc_param param; +struct venc_enc_param param = {0 };int ret;int i;drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c static int mtk_venc_encode_header(void *priv) · line 1039
Quoted 4 lines
drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c +1
-0@@ -1036,6 +1036,7 @@ static int mtk_venc_encode_header(void *priv) ctx->id, dst_buf->vb2_buf.index, bs_buf.va, (u64)bs_buf.dma_addr, bs_buf.size); +memset (&enc_result,0 ,sizeof (enc_result));Please, apply review comment to all occurrence, so same here.
drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c static void mtk_venc_worker(struct · line 1192
Quoted 11 lines
drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c +1
-0ret =venc_if_encode (ctx,VENC_START_OPT_ENCODE_SEQUENCE_HEADER ,NULL , &bs_buf, &enc_result);@@ -1185,6 +1186,7 @@ static void mtk_venc_worker(struct work_struct *work) (u64)frm_buf.fb_addr[1].dma_addr, frm_buf.fb_addr[1].size, (u64)frm_buf.fb_addr[2].dma_addr, frm_buf.fb_addr[2].size); + memset(&enc_result, 0, sizeof(enc_result));Same here.
drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c static void mtk_venc_worker(struct work_struct *work) · line 1191
Quoted 4 lines
drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c +0
-0ret =venc_if_encode (ctx,VENC_START_OPT_ENCODE_FRAME , &frm_buf, &bs_buf, &enc_result);Would be nice to coordinate with Qianfeng Rong <[email protected]
Quoted 1 line
[0], he
ported the entire driver to this initialization method, which is clearly the way
to go.
Quoted 6 lines
- Patch 1 will port the driver to {} stack init
- Patch 2 will add missing initializesConsistency is key for this type of things since developer usually follow the
surrounding style.
I have learned Qianfeng's patch and comments. I understand what you mean is change my patch coding style to Qianfeng's, modify 'memset' to '{}' for initialization, and amend Qianfeng's patch as patch-2, then send this two patches together.
If I misunderstood your opinion, please correct me, thank you very much.
Best Regards
Quoted 6 lines
regards
Nicolas[0]
https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/
Le lundi 01 septembre 2025 à 02:37 +0000, Irui Wang (王瑞) a écrit :
Quoted 83 lines
Dear Nicolas,
Thanks for your comments.
Quoted 78 lines · Nicolas Dufresne
Quoted 44 lines · Irui Wang
UNINIT checker finds some instances of variables that are used without being initialized, for example using the uninitialized value enc_result.is_key_frm can result in unpredictable behavior, so initialize these variables after declaring.
Fixes 4e855a6efa54 ("[media] vcodec: mediatek: Add Mediatek V4L2Video
Encoder Driver")Signed-off-by Irui Wang <[email protected]>---
v2:
- Add Fixes tag, update commit message
- Remove unnecessary memset
- Move memset to before the first usage
---
.../media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c | 4
+++-1 file changed, 3 insertions(+), 1 deletion(-)diff --git
a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.cb/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.cindexa01dc25a7699..3065f3e66336100644
---a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c
+++b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c(quoted diff) +0
-0@@ -865,7 +865,7 @@ static void vb2ops_venc_buf_queue(struct vb2_buffer *vb) static int vb2ops_venc_start_streaming(struct vb2_queue *q,unsigned int
count)
{
structmtk_vcodec_enc_ctx*ctx =vb2_get_drv_priv(q);drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c +1
-1-struct venc_enc_param param; +struct venc_enc_param param = {0 };int ret;
int i;drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c +0
-0@@ -1036,6 +1036,7 @@ static int mtk_venc_encode_header(void *priv) ctx->id, dst_buf->vb2_buf.index, bs_buf.va, (u64)bs_buf.dma_addr, bs_buf.size);Review
Quoted 1 line
(quoted diff) +1
-0+ memset(&enc_result, 0, sizeof(enc_result));Please, apply review comment to all occurrence, so same here.
Review
Quoted 11 lines
ret =
venc_if_encode(ctx, VENC_START_OPT_ENCODE_SEQUENCE_HEADER, NULL, &bs_buf, &enc_result);(quoted diff) +0
-0@@ -1185,6 +1186,7 @@ static void mtk_venc_worker(struct work_struct *work) (u64)frm_buf.fb_addr[1].dma_addr, frm_buf.fb_addr[1].size, (u64)frm_buf.fb_addr[2].dma_addr, frm_buf.fb_addr[2].size);(quoted diff) +1
-0+ memset(&enc_result, 0, sizeof(enc_result));Same here.
Quoted 4 lines
ret =
venc_if_encode(ctx, VENC_START_OPT_ENCODE_FRAME, &frm_buf, &bs_buf, &enc_result);Would be nice to coordinate with Qianfeng Rong <[email protected]
Quoted 1 line
[0], he
ported the entire driver to this initialization method, which is clearly the way
to go.- Patch 1 will port the driver to {} stack init
- Patch 2 will add missing initializes
Quoted 8 lines
Quoted 3 lines
Consistency is key for this type of things since developer usually follow the
surrounding style.I have learned Qianfeng's patch and comments. I understand what you mean is change my patch coding style to Qianfeng's, modify 'memset' to '{}' for initialization, and amend Qianfeng's patch as patch-2, then send this two patches together.
Correct, and I don't mind who do that work, I'd like to see the code kept consistant. And I do agree memset() are error prone.
cheers,
Nicolas
Quoted 11 lines
If I misunderstood your opinion, please correct me, thank you very much.
Best Regards
Quoted 6 lines
regards
Nicolas[0]
https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/
Dear Nicolas,
Quoted 107 lines · Nicolas Dufresne
Quoted 99 lines · Irui Wang (王瑞)
Dear Nicolas,
Thanks for your comments.
Quoted 86 lines · Nicolas Dufresne
Quoted 48 lines · Irui Wang
UNINIT checker finds some instances of variables that are used without being initialized, for example using the uninitialized value enc_result.is_key_frm can result in unpredictable behavior,
so initialize these variables after declaring.Fixes 4e855a6efa54 ("[media] vcodec: mediatek: Add MediatekV4L2
Video
Encoder Driver")Signed-off-by Irui Wang <[email protected]>---
v2:
- Add Fixes tag, update commit message
- Remove unnecessary memset
- Move memset to before the first usage
---
.../media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c
| 4
+++-1 file changed, 3 insertions(+), 1 deletion(-)diff --git a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc .c b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc .c
indexa01dc25a7699..3065f3e66336100644
---
a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc .c
+++
b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc .c(quoted diff) +0
-0@@ -865,7 +865,7 @@ static void vb2ops_venc_buf_queue(struct vb2_buffer *vb) static int vb2ops_venc_start_streaming(struct vb2_queue *q,unsigned int
count)
{drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c +1
-1struct mtk_vcodec_enc_ctx *ctx =vb2_get_drv_priv (q); -struct venc_enc_param param; +struct venc_enc_param param = {0 };int ret;int i;drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c static int mtk_venc_encode_header(void · line 1041
Quoted 6 lines
drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c +1
-0@@ -1036,6 +1036,7 @@ static int mtk_venc_encode_header(void *priv) ctx->id, dst_buf->vb2_buf.index, bs_buf.va, (u64)bs_buf.dma_addr, bs_buf.size); +memset (&enc_result,0 ,sizeof (enc_result));Please, apply review comment to all occurrence, so same here.
drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c static void mtk_venc_worker(struct · line 1192
Quoted 11 lines
drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c +0
-0ret = venc_if_encode(ctx,drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c +1
-0VENC_START_OPT_ENCODE_SEQUENCE_HEADER , NULL, &bs_buf, &enc_result);@@ -1185,6 +1186,7 @@ static void mtk_venc_worker(struct work_struct *work) (u64)frm_buf.fb_addr[1].dma_addr, frm_buf.fb_addr[1].size, (u64)frm_buf.fb_addr[2].dma_addr, frm_buf.fb_addr[2].size); + memset(&enc_result, 0, sizeof(enc_result));Same here.
drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c static void mtk_venc_worker(struct work_struct *work) · line 1191
Quoted 4 lines
drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c +0
-0ret =venc_if_encode (ctx,VENC_START_OPT_ENCODE_FRAME , &frm_buf, &bs_buf, &enc_result);Would be nice to coordinate with Qianfeng Rong <
[email protected]Quoted 1 line
[0], he
ported the entire driver to this initialization method, which is clearly the way
to go.Quoted 7 lines
- Patch 1 will port the driver to {} stack init
- Patch 2 will add missing initializesConsistency is key for this type of things since developer usually
follow the
surrounding style.Quoted 6 lines
I have learned Qianfeng's patch and comments. I understand what you mean is change my patch coding style to Qianfeng's, modify 'memset' to
'{}' for initialization, and amend Qianfeng's patch as patch-2, then
send this two patches together.
Quoted 3 lines
Correct, and I don't mind who do that work, I'd like to see the code kept
consistant. And I do agreememset()are error prone.
patch v3 has sent, please kindly help to review when you have time, thank you very much.
https://patchwork.linuxtv.org/project/linux-media/list/?series=18118
Quoted 15 lines
cheers,
NicolasQuoted 11 lines
If I misunderstood your opinion, please correct me, thank you very much.
Best Regards
Quoted 6 lines
regards
Nicolas[0]
https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/