public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: "Ewan D. Milne" <emilne@redhat.com>
To: Tomas Henzl <thenzl@redhat.com>
Cc: Arnd Bergmann <arnd@arndb.de>,
	qla2xxx-upstream@qlogic.com,
	"James E.J. Bottomley" <jejb@linux.vnet.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	Nicholas Bellinger <nab@linux-iscsi.org>,
	Himanshu Madhani <himanshu.madhani@qlogic.com>,
	Quinn Tran <quinn.tran@qlogic.com>,
	Alexei Potashnik <alexei@purestorage.com>,
	Bart Van Assche <bart.vanassche@sandisk.com>,
	Swapnil Nagle <swapnil.nagle@purestorage.com>,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] qla2xxx: avoid maybe_uninitialized warning
Date: Wed, 16 Mar 2016 11:47:26 -0400	[thread overview]
Message-ID: <1458143246.17965.10.camel@localhost.localdomain> (raw)
In-Reply-To: <56E975B8.6040807@redhat.com>

On Wed, 2016-03-16 at 16:03 +0100, Tomas Henzl wrote:
> On 15.3.2016 22:40, Arnd Bergmann wrote:
> > The qlt_check_reserve_free_req() function produces an incorrect warning
> > when CONFIG_PROFILE_ANNOTATED_BRANCHES is set:
> >
> > drivers/scsi/qla2xxx/qla_target.c: In function 'qlt_check_reserve_free_req':
> > drivers/scsi/qla2xxx/qla_target.c:1887:3: error: 'cnt_in' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> >    ql_dbg(ql_dbg_io, vha, 0x305a,
> >    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >        "qla_target(%d): There is no room in the request ring: vha->req->ring_index=%d, vha->req->cnt=%d, req_cnt=%d Req-out=%d Req-in=%d Req-Length=%d\n",
> >        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >        vha->vp_idx, vha->req->ring_index,
> >        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >        vha->req->cnt, req_cnt, cnt, cnt_in, vha->req->length);
> >        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > drivers/scsi/qla2xxx/qla_target.c:1887:3: error: 'cnt' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> >
> > The problem is that gcc fails to track the state of the condition across
> > an annotated branch.
> >
> > This slightly rearranges the code to move the second if() block
> > into the first one, to avoid the warning while retaining the
> > behavior of the code.
> 
> When the first 'if' is true the vha->req->ring_index gets a new value 
> assigned - so it could be possible that the second 'if' wont be true any more.
> The code should not be merged into that single 'if', or am I missing something?
> 
> tomash

If the first "if" is false, the second "if" will be false also, because
the vha->req->cnt value has not changed.  If the first "if" is true, the
nested second "if" will retest the condition.

The compiler is not at fault, because vha->req->cnt can't be tracked as
it could be modified by another thread/process.  It isn't, it's protected
by the ->hardware_lock, but the compiler doesn't know that.

-Ewan

> >
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> > ---
> >  drivers/scsi/qla2xxx/qla_target.c | 16 +++++++++-------
> >  1 file changed, 9 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/scsi/qla2xxx/qla_target.c b/drivers/scsi/qla2xxx/qla_target.c
> > index 985231900aca..8a44d1541eb4 100644
> > --- a/drivers/scsi/qla2xxx/qla_target.c
> > +++ b/drivers/scsi/qla2xxx/qla_target.c
> > @@ -1881,15 +1881,17 @@ static int qlt_check_reserve_free_req(struct scsi_qla_host *vha,
> >  		else
> >  			vha->req->cnt = vha->req->length -
> >  			    (vha->req->ring_index - cnt);
> > -	}
> >  
> > -	if (unlikely(vha->req->cnt < (req_cnt + 2))) {
> > -		ql_dbg(ql_dbg_io, vha, 0x305a,
> > -		    "qla_target(%d): There is no room in the request ring: vha->req->ring_index=%d, vha->req->cnt=%d, req_cnt=%d Req-out=%d Req-in=%d Req-Length=%d\n",
> > -		    vha->vp_idx, vha->req->ring_index,
> > -		    vha->req->cnt, req_cnt, cnt, cnt_in, vha->req->length);
> > -		return -EAGAIN;
> > +		if (unlikely(vha->req->cnt < (req_cnt + 2))) {
> > +			ql_dbg(ql_dbg_io, vha, 0x305a,
> > +			    "qla_target(%d): There is no room in the request ring: vha->req->ring_index=%d, vha->req->cnt=%d, req_cnt=%d Req-out=%d Req-in=%d Req-Length=%d\n",
> > +			    vha->vp_idx, vha->req->ring_index,
> > +			    vha->req->cnt, req_cnt, cnt, cnt_in,
> > +			    vha->req->length);
> > +			return -EAGAIN;
> > +		}
> >  	}
> > +
> >  	vha->req->cnt -= req_cnt;
> >  
> >  	return 0;
> 

  parent reply	other threads:[~2016-03-16 15:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-15 21:40 [PATCH] qla2xxx: avoid maybe_uninitialized warning Arnd Bergmann
2016-03-15 21:49 ` James Bottomley
2016-03-16 12:59   ` Arnd Bergmann
2016-03-16 14:05     ` Himanshu Madhani
2016-03-16 14:24       ` James Bottomley
2016-03-16 15:03 ` Tomas Henzl
2016-03-16 15:11   ` Tomas Henzl
2016-03-16 15:47   ` Ewan D. Milne [this message]
2016-03-18 19:26 ` Martin K. Petersen

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=1458143246.17965.10.camel@localhost.localdomain \
    --to=emilne@redhat.com \
    --cc=alexei@purestorage.com \
    --cc=arnd@arndb.de \
    --cc=bart.vanassche@sandisk.com \
    --cc=himanshu.madhani@qlogic.com \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=nab@linux-iscsi.org \
    --cc=qla2xxx-upstream@qlogic.com \
    --cc=quinn.tran@qlogic.com \
    --cc=swapnil.nagle@purestorage.com \
    --cc=thenzl@redhat.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