ALSA: firewire-lib: Fix uninitialized variable err issue
Subsystems (3)
PATCH 1/1 ALSA: firewire-lib: Fix uninitialized variable err issue
From: Colin Ian King <[email protected]>
Currently in the case where the payload_length is less than the cip_header_size the error return variable err is not being set and function parse_ir_ctx_header can return an uninitialized error return value. Fix this by setting err to zero.
Addresses-Coverity: ("Uninitialized scalar variable")
--- sound/firewire/amdtp-stream.c | 1 + 1 file changed, 1 insertion(+)
sound/firewire/amdtp-stream.c +1 -0
@@ -663,6 +663,7 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle, }else {// Handle the cycle so that empty packet arrives. cip_header =NULL ; + err =0 ; *data_blocks =0 ; *syt =0 ; }
Signature · 1 line
2.31.1
Quoted 11 lines · Colin King
From: Colin Ian King <[email protected]>
Currently in the case where the
payload_lengthis less than thecip_header_sizethe error return variable err is not being set and functionparse_ir_ctx_headercan return an uninitialized error return value. Fix this by setting err to zero.Addresses-Coverity: ("Uninitialized scalar variable")
Fixes c09010eeb373 ("ALSA: firewire-lib: handle the case that empty isochronous packet payload for CIP")Signed-off-by Colin Ian King <[email protected]>
Just a bikeshed, IMO, it'd be more proper to initialize err at the beginning than setting 0 at every branch, e.g.
sound/firewire/amdtp-stream.c +1 -2
@@ -652,7 +652,7 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle,unsigned int payload_length;const __be32 *cip_header;unsigned int cip_header_size; -int err; +int err =0 ; payload_length =be32_to_cpu (ctx_header[0 ]) >>ISO_DATA_LENGTH_SHIFT ;
@@ -683,7 +683,6 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle, } }else { cip_header =NULL ; - err =0 ; *data_blocks = payload_length /sizeof (__be32) / s->data_block_quadlets; *syt =0 ;
thanks,
Takashi
Takashi Sakamoto
maintainerHi,
Quoted 29 lines · Takashi Iwai
Quoted 11 lines · Colin King
From: Colin Ian King <[email protected]>
Currently in the case where the
payload_lengthis less than thecip_header_sizethe error return variable err is not being set and functionparse_ir_ctx_headercan return an uninitialized error return value. Fix this by setting err to zero.Addresses-Coverity: ("Uninitialized scalar variable")
Fixes c09010eeb373 ("ALSA: firewire-lib: handle the case that empty isochronous packet payload for CIP")Signed-off-by Colin Ian King <[email protected]>Just a bikeshed, IMO, it'd be more proper to initialize err at the beginning than setting 0 at every branch, e.g.
sound/firewire/amdtp-stream.c +1
-1@@ -652,7 +652,7 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle,unsigned int payload_length;const __be32 *cip_header;unsigned int cip_header_size; -int err; +int err =0 ; payload_length =be32_to_cpu (ctx_header[0 ]) >>ISO_DATA_LENGTH_SHIFT ;
sound/firewire/amdtp-stream.c static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle, · line 687
Quoted 6 lines
sound/firewire/amdtp-stream.c +0
-1@@ -683,7 +683,6 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle, } }else { cip_header =NULL ; - err =0 ; *data_blocks = payload_length /sizeof (__be32) / s->data_block_quadlets; *syt =0 ;
Thanks for the patches.
The error check is just done for the case to process CIP header, thus we can put the auto variable into the branch.
======== 8< --------
From 3fcca0062297e937c665f1c8e3a117e1187f4115 Mon Sep 17 00:00:00 2001
From: Takashi Sakamoto <[email protected]>
Date: Thu, 20 May 2021 21:59:50 +0900
Subject: [PATCH] ALSA: firewire-lib: Fix uninitialized variable err issue
The check of error is just done for the case that CIP header is available.
This commit moves auto variable into the branch to process CIP header.
Addresses-Coverity: ("Uninitialized scalar variable")
--- sound/firewire/amdtp-stream.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
sound/firewire/amdtp-stream.c +3 -3
@@ -748,7 +748,6 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle,unsigned int payload_length;const __be32 *cip_header;unsigned int cip_header_size; -int err; payload_length =be32_to_cpu (ctx_header[0 ]) >>ISO_DATA_LENGTH_SHIFT ;
@@ -766,6 +765,8 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle,if (cip_header_size >0 ) {if (payload_length >= cip_header_size) { +int err; + cip_header = ctx_header +IR_CTX_HEADER_DEFAULT_QUADLETS ; err =check_cip_header (s, cip_header, payload_length - cip_header_size, data_blocks, data_block_counter, syt);
@@ -779,7 +780,6 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle, } }else { cip_header =NULL ; - err =0 ; *data_blocks = payload_length /sizeof (__be32) / s->data_block_quadlets; *syt =0 ;
@@ -790,7 +790,7 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle,trace_amdtp_packet (s, cycle, cip_header, payload_length, *data_blocks, *data_block_counter, packet_index, index); -return err; +return 0 ; }// In CYCLE_TIMER register of IEEE 1394, 7 bits are used to represent second. On
Signature · 7 lines
2.27.0 ======== 8< -------- Thanks Takashi Sakamoto
Takashi Sakamoto
maintainerHi,
Quoted 103 lines · Takashi Sakamoto
Hi,
Quoted 29 lines · Takashi Iwai
Quoted 11 lines · Colin King
From: Colin Ian King <[email protected]>
Currently in the case where the
payload_lengthis less than thecip_header_sizethe error return variable err is not being set and functionparse_ir_ctx_headercan return an uninitialized error return value. Fix this by setting err to zero.Addresses-Coverity: ("Uninitialized scalar variable")
Fixes c09010eeb373 ("ALSA: firewire-lib: handle the case that empty isochronous packet payload for CIP")Signed-off-by Colin Ian King <[email protected]>Just a bikeshed, IMO, it'd be more proper to initialize err at the beginning than setting 0 at every branch, e.g.
sound/firewire/amdtp-stream.c +1
-1@@ -652,7 +652,7 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle,unsigned int payload_length;const __be32 *cip_header;unsigned int cip_header_size; -int err; +int err =0 ; payload_length =be32_to_cpu (ctx_header[0 ]) >>ISO_DATA_LENGTH_SHIFT ;sound/firewire/amdtp-stream.c static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle, · line 687
Quoted 6 lines
sound/firewire/amdtp-stream.c +0
-1@@ -683,7 +683,6 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle, } }else { cip_header =NULL ; - err =0 ; *data_blocks = payload_length /sizeof (__be32) / s->data_block_quadlets; *syt =0 ;Thanks for the patches.
The error check is just done for the case to process CIP header, thus we can put the auto variable into the branch.
======== 8< --------
From3fcca0062297e937c665f1c8e3a117e1187f4115Mon Sep 17 00:00:00 2001
From: Takashi Sakamoto <[email protected]>
Date: Thu, 20 May 2021 21:59:50 +0900
Subject: [PATCH] ALSA: firewire-lib: Fix uninitialized variable err issueThe check of error is just done for the case that CIP header is available.
This commit moves auto variable into the branch to process CIP header.
Addresses-Coverity: ("Uninitialized scalar variable")
Fixes c09010eeb373 ("ALSA: firewire-lib: handle the case that empty isochronous packet payload for CIP")Suggested-by Colin Ian King <[email protected]>Signed-off-by Takashi Sakamoto <[email protected]>--- sound/firewire/amdtp-stream.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)sound/firewire/amdtp-stream.c +3
-3@@ -748,7 +748,6 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle,unsigned int payload_length;const __be32 *cip_header;unsigned int cip_header_size; -int err; payload_length =be32_to_cpu (ctx_header[0 ]) >>ISO_DATA_LENGTH_SHIFT ;@@ -766,6 +765,8 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle,if (cip_header_size >0 ) {if (payload_length >= cip_header_size) { +int err; + cip_header = ctx_header +IR_CTX_HEADER_DEFAULT_QUADLETS ; err =check_cip_header (s, cip_header, payload_length - cip_header_size, data_blocks, data_block_counter, syt);@@ -779,7 +780,6 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle, } }else { cip_header =NULL ; - err =0 ; *data_blocks = payload_length /sizeof (__be32) / s->data_block_quadlets; *syt =0 ;@@ -790,7 +790,7 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle,trace_amdtp_packet (s, cycle, cip_header, payload_length, *data_blocks, *data_block_counter, packet_index, index); -return err; +return 0 ; }// In CYCLE_TIMER register of IEEE 1394, 7 bits are used to represent second. On Signature · 2 lines
2.27.0 ======== 8< --------
Thanks for applying the patch but the commit in your tree includes duplicated From/Data/Subject lines and causes failure of git-am for the patch simply generated by git-am. Is it possible for you to modify history of your for-next branch with enough correction?
Regards
Takashi Sakamoto
Quoted 103 lines · Takashi Sakamoto
Hi,
Quoted 99 lines · Takashi Sakamoto
Hi,
Quoted 29 lines · Takashi Iwai
Quoted 11 lines · Colin King
From: Colin Ian King <[email protected]>
Currently in the case where the
payload_lengthis less than thecip_header_sizethe error return variable err is not being set and functionparse_ir_ctx_headercan return an uninitialized error return value. Fix this by setting err to zero.Addresses-Coverity: ("Uninitialized scalar variable")
Fixes c09010eeb373 ("ALSA: firewire-lib: handle the case that empty isochronous packet payload for CIP")Signed-off-by Colin Ian King <[email protected]>Just a bikeshed, IMO, it'd be more proper to initialize err at the beginning than setting 0 at every branch, e.g.
sound/firewire/amdtp-stream.c +1
-1@@ -652,7 +652,7 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle,unsigned int payload_length;const __be32 *cip_header;unsigned int cip_header_size; -int err; +int err =0 ; payload_length =be32_to_cpu (ctx_header[0 ]) >>ISO_DATA_LENGTH_SHIFT ;sound/firewire/amdtp-stream.c static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle, · line 687
Quoted 6 lines
sound/firewire/amdtp-stream.c +0
-1@@ -683,7 +683,6 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle, } }else { cip_header =NULL ; - err =0 ; *data_blocks = payload_length /sizeof (__be32) / s->data_block_quadlets; *syt =0 ;Thanks for the patches.
The error check is just done for the case to process CIP header, thus we can put the auto variable into the branch.
======== 8< --------
From3fcca0062297e937c665f1c8e3a117e1187f4115Mon Sep 17 00:00:00 2001
From: Takashi Sakamoto <[email protected]>
Date: Thu, 20 May 2021 21:59:50 +0900
Subject: [PATCH] ALSA: firewire-lib: Fix uninitialized variable err issueThe check of error is just done for the case that CIP header is available.
This commit moves auto variable into the branch to process CIP header.
Addresses-Coverity: ("Uninitialized scalar variable")
Fixes c09010eeb373 ("ALSA: firewire-lib: handle the case that empty isochronous packet payload for CIP")Suggested-by Colin Ian King <[email protected]>Signed-off-by Takashi Sakamoto <[email protected]>--- sound/firewire/amdtp-stream.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)sound/firewire/amdtp-stream.c +3
-3@@ -748,7 +748,6 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle,unsigned int payload_length;const __be32 *cip_header;unsigned int cip_header_size; -int err; payload_length =be32_to_cpu (ctx_header[0 ]) >>ISO_DATA_LENGTH_SHIFT ;@@ -766,6 +765,8 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle,if (cip_header_size >0 ) {if (payload_length >= cip_header_size) { +int err; + cip_header = ctx_header +IR_CTX_HEADER_DEFAULT_QUADLETS ; err =check_cip_header (s, cip_header, payload_length - cip_header_size, data_blocks, data_block_counter, syt);@@ -779,7 +780,6 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle, } }else { cip_header =NULL ; - err =0 ; *data_blocks = payload_length /sizeof (__be32) / s->data_block_quadlets; *syt =0 ;@@ -790,7 +790,7 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle,trace_amdtp_packet (s, cycle, cip_header, payload_length, *data_blocks, *data_block_counter, packet_index, index); -return err; +return 0 ; }
Quoted 9 lines
Quoted 4 lines
sound/firewire/amdtp-stream.c +0
-0// In CYCLE_TIMER register of IEEE 1394, 7 bits are used to represent second. On Signature · 2 lines
2.27.0 ======== 8< --------Thanks for applying the patch but the commit in your tree includes duplicated From/Data/Subject lines and causes failure of git-am for the patch simply generated by git-am. Is it possible for you to modify history of your for-next branch with enough correction?
My bad, now corrected.
thanks,
Takashi