linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] media: mediatek: encoder: Fix uninitialized scalar variable issue
@ 2025-07-16  7:14 Irui Wang
  2025-08-29 19:10 ` Nicolas Dufresne
  0 siblings, 1 reply; 4+ messages in thread
From: Irui Wang @ 2025-07-16  7:14 UTC (permalink / raw)
  To: Hans Verkuil, Mauro Carvalho Chehab, Matthias Brugger,
	angelogioacchino.delregno, nicolas.dufresne
  Cc: Project_Global_Chrome_Upstream_Group, linux-media, linux-kernel,
	linux-arm-kernel, linux-mediatek, Yunfei Dong, Longfei Wang,
	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 V4L2 Video Encoder Driver")

Signed-off-by: Irui Wang <irui.wang@mediatek.com>
---
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
index a01dc25a7699..3065f3e66336 100644
--- a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c
+++ b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c
@@ -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);
 
-- 
2.46.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] media: mediatek: encoder: Fix uninitialized scalar variable issue
  2025-07-16  7:14 [PATCH v2] media: mediatek: encoder: Fix uninitialized scalar variable issue Irui Wang
@ 2025-08-29 19:10 ` Nicolas Dufresne
  2025-09-01  2:37   ` Irui Wang (王瑞)
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Dufresne @ 2025-08-29 19:10 UTC (permalink / raw)
  To: Irui Wang, Hans Verkuil, Mauro Carvalho Chehab, Matthias Brugger,
	angelogioacchino.delregno, Qianfeng Rong
  Cc: Project_Global_Chrome_Upstream_Group, linux-media, linux-kernel,
	linux-arm-kernel, linux-mediatek, Yunfei Dong, Longfei Wang

[-- Attachment #1: Type: text/plain, Size: 2759 bytes --]

Le mercredi 16 juillet 2025 à 15:14 +0800, Irui Wang a écrit :
> 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 Video
> Encoder Driver")
> 
> Signed-off-by: Irui Wang <irui.wang@mediatek.com>
> ---
> 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
> index a01dc25a7699..3065f3e66336 100644
> --- a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c
> +++ b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c
> @@ -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));

Please, apply review comment to all occurrence, so same here.

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

Same here.

>  	ret = venc_if_encode(ctx, VENC_START_OPT_ENCODE_FRAME,
>  			     &frm_buf, &bs_buf, &enc_result);
>  
> 


Would be nice to coordinate with Qianfeng Rong <rongqianfeng@vivo.com> [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/20250803135514.118892-1-rongqianfeng@vivo.com/

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] media: mediatek: encoder: Fix uninitialized scalar variable issue
  2025-08-29 19:10 ` Nicolas Dufresne
@ 2025-09-01  2:37   ` Irui Wang (王瑞)
  2025-09-02 12:57     ` Nicolas Dufresne
  0 siblings, 1 reply; 4+ messages in thread
From: Irui Wang (王瑞) @ 2025-09-01  2:37 UTC (permalink / raw)
  To: rongqianfeng@vivo.com, matthias.bgg@gmail.com, mchehab@kernel.org,
	AngeloGioacchino Del Regno, nicolas.dufresne@collabora.com,
	hverkuil-cisco@xs4all.nl
  Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
	linux-mediatek@lists.infradead.org,
	Longfei Wang (王龙飞),
	Project_Global_Chrome_Upstream_Group,
	Yunfei Dong (董云飞)

Dear Nicolas,

Thanks for your comments.

On Fri, 2025-08-29 at 15:10 -0400, Nicolas Dufresne wrote:
> Le mercredi 16 juillet 2025 à 15:14 +0800, Irui Wang a écrit :
> > 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
> > Video
> > Encoder Driver")
> > 
> > Signed-off-by: Irui Wang <irui.wang@mediatek.com>
> > ---
> > 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
> > index a01dc25a7699..3065f3e66336 100644
> > ---
> > a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c
> > +++
> > b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c
> > @@ -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));
> 
> Please, apply review comment to all occurrence, so same here.
> 
> >  	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));
> 
> Same here.
> 
> >  	ret = venc_if_encode(ctx, VENC_START_OPT_ENCODE_FRAME,
> >  			     &frm_buf, &bs_buf, &enc_result);
> >  
> > 
> 
> 
> Would be nice to coordinate with Qianfeng Rong <rongqianfeng@vivo.com
> > [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.

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
> 
> regards
> Nicolas
> 
> [0] 
> https://patchwork.linuxtv.org/project/linux-media/patch/20250803135514.118892-1-rongqianfeng@vivo.com/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] media: mediatek: encoder: Fix uninitialized scalar variable issue
  2025-09-01  2:37   ` Irui Wang (王瑞)
@ 2025-09-02 12:57     ` Nicolas Dufresne
  0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Dufresne @ 2025-09-02 12:57 UTC (permalink / raw)
  To: Irui Wang (王瑞), rongqianfeng@vivo.com,
	matthias.bgg@gmail.com, mchehab@kernel.org,
	AngeloGioacchino Del Regno, hverkuil-cisco@xs4all.nl
  Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
	linux-mediatek@lists.infradead.org,
	Longfei Wang (王龙飞),
	Project_Global_Chrome_Upstream_Group,
	Yunfei Dong (董云飞)

[-- Attachment #1: Type: text/plain, Size: 3839 bytes --]

Le lundi 01 septembre 2025 à 02:37 +0000, Irui Wang (王瑞) a écrit :
> Dear Nicolas,
> 
> Thanks for your comments.
> 
> On Fri, 2025-08-29 at 15:10 -0400, Nicolas Dufresne wrote:
> > Le mercredi 16 juillet 2025 à 15:14 +0800, Irui Wang a écrit :
> > > 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
> > > Video
> > > Encoder Driver")
> > > 
> > > Signed-off-by: Irui Wang <irui.wang@mediatek.com>
> > > ---
> > > 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
> > > index a01dc25a7699..3065f3e66336 100644
> > > ---
> > > a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c
> > > +++
> > > b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c
> > > @@ -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));
> > 
> > Please, apply review comment to all occurrence, so same here.
> > 
> > >  	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));
> > 
> > Same here.
> > 
> > >  	ret = venc_if_encode(ctx, VENC_START_OPT_ENCODE_FRAME,
> > >  			     &frm_buf, &bs_buf, &enc_result);
> > >  
> > > 
> > 
> > 
> > Would be nice to coordinate with Qianfeng Rong <rongqianfeng@vivo.com
> > > [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.
> 
> 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

> 
> If I misunderstood your opinion, please correct me, thank you very
> much.
> 
> Best Regards
> > 
> > regards
> > Nicolas
> > 
> > [0] 
> > https://patchwork.linuxtv.org/project/linux-media/patch/20250803135514.118892-1-rongqianfeng@vivo.com/

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-09-02 12:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-16  7:14 [PATCH v2] media: mediatek: encoder: Fix uninitialized scalar variable issue Irui Wang
2025-08-29 19:10 ` Nicolas Dufresne
2025-09-01  2:37   ` Irui Wang (王瑞)
2025-09-02 12:57     ` Nicolas Dufresne

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).