linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Cc: Colin King <colin.king@canonical.com>,
	Clemens Ladisch <clemens@ladisch.de>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	alsa-devel@alsa-project.org, kernel-janitors@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next] ALSA: firewire-lib: Fix uninitialized variable err issue
Date: Sat, 22 May 2021 08:45:32 +0200	[thread overview]
Message-ID: <s5him3bfer7.wl-tiwai@suse.de> (raw)
In-Reply-To: <20210521222146.GA10202@workstation>

On Sat, 22 May 2021 00:21:46 +0200,
Takashi Sakamoto wrote:
> 
> Hi,
> 
> On Thu, May 20, 2021 at 10:04:09PM +0900, Takashi Sakamoto wrote:
> > Hi,
> > 
> > On Thu, May 20, 2021 at 02:26:24PM +0200, Takashi Iwai wrote:
> > > On Thu, 20 May 2021 10:34:24 +0200,
> > > Colin King wrote:
> > > > 
> > > > From: Colin Ian King <colin.king@canonical.com>
> > > > 
> > > > 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")
> > > > Fixes: c09010eeb373 ("ALSA: firewire-lib: handle the case that empty isochronous packet payload for CIP")
> > > > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > > 
> > > Just a bikeshed, IMO, it'd be more proper to initialize err at the
> > > beginning than setting 0 at every branch, e.g.
> > > 
> > > --- a/sound/firewire/amdtp-stream.c
> > > +++ b/sound/firewire/amdtp-stream.c
> > > @@ -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 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 <o-takashi@sakamocchi.jp>
> > 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")
> > Fixes: c09010eeb373 ("ALSA: firewire-lib: handle the case that empty isochronous packet payload for CIP")
> > Suggested-by: Colin Ian King <colin.king@canonical.com>
> > Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
> > ---
> >  sound/firewire/amdtp-stream.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/sound/firewire/amdtp-stream.c b/sound/firewire/amdtp-stream.c
> > index 37c8de8a..11ae4e88 100644
> > --- a/sound/firewire/amdtp-stream.c
> > +++ b/sound/firewire/amdtp-stream.c
> > @@ -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
> > -- 
> > 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

      reply	other threads:[~2021-05-22  6:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-20  8:34 [PATCH][next] ALSA: firewire-lib: Fix uninitialized variable err issue Colin King
2021-05-20 12:26 ` Takashi Iwai
2021-05-20 13:04   ` Takashi Sakamoto
2021-05-21 22:21     ` Takashi Sakamoto
2021-05-22  6:45       ` Takashi Iwai [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=s5him3bfer7.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=clemens@ladisch.de \
    --cc=colin.king@canonical.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=o-takashi@sakamocchi.jp \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).