Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935142AbcCPPD2 (ORCPT ); Wed, 16 Mar 2016 11:03:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47953 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934990AbcCPPDZ (ORCPT ); Wed, 16 Mar 2016 11:03:25 -0400 Subject: Re: [PATCH] qla2xxx: avoid maybe_uninitialized warning To: Arnd Bergmann , qla2xxx-upstream@qlogic.com, "James E.J. Bottomley" , "Martin K. Petersen" References: <1458078051-529344-1-git-send-email-arnd@arndb.de> Cc: Nicholas Bellinger , Himanshu Madhani , Quinn Tran , Alexei Potashnik , Bart Van Assche , Swapnil Nagle , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org From: Tomas Henzl Message-ID: <56E975B8.6040807@redhat.com> Date: Wed, 16 Mar 2016 16:03:20 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <1458078051-529344-1-git-send-email-arnd@arndb.de> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3005 Lines: 64 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 > > Signed-off-by: Arnd Bergmann > --- > 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;