From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web10.9829.1616078339759980539 for ; Thu, 18 Mar 2021 07:38:59 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MWN63sNX; spf=pass (domain: redhat.com, ip: 216.205.24.124, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616078338; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+BmjfCSgCTwbcTgQ6hkXPSFzLrWq+7ENj5rAj/05aqQ=; b=MWN63sNXZBcH3W/q5Nx9IEbESPD6gOk8unVr9Jk+4Wvc7tRU4EUZzxAFArWmuA/rsQovh8 kog2DHFtsjrm3B/daC3dQkOno6gO3OW3QwDzq5AXPE6zjPOv6BMqRE1vo0TFpDqYbLr747 g9ssoECReVqC833eBJSfbq9WrIDVLnE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-169-ScOFmab4MESepakMdQj_Rw-1; Thu, 18 Mar 2021 10:38:55 -0400 X-MC-Unique: ScOFmab4MESepakMdQj_Rw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1701F107B287; Thu, 18 Mar 2021 14:38:54 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-115-176.ams2.redhat.com [10.36.115.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id 194A66064B; Thu, 18 Mar 2021 14:38:52 +0000 (UTC) Subject: Re: [edk2-devel] [Patch v2] MdeModulePkg: Initialize local variable value before they are used To: devel@edk2.groups.io, gaoliming@byosoft.com.cn Cc: Jian J Wang , Hao A Wu References: <20210318045046.1909-1-gaoliming@byosoft.com.cn> From: "Laszlo Ersek" Message-ID: <5bbd0b1f-7a53-d63c-58ed-b637c47aad11@redhat.com> Date: Thu, 18 Mar 2021 15:38:51 +0100 MIME-Version: 1.0 In-Reply-To: <20210318045046.1909-1-gaoliming@byosoft.com.cn> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lersek@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 03/18/21 05:50, gaoliming wrote: > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3228 > This change is to fix the false compiler error on GCC49 release build. > > Cc: Jian J Wang > Cc: Hao A Wu > Signed-off-by: Liming Gao > Reviewed-by: Hao A Wu > --- > In V2, add the comments for the false compiler warning > > MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c | 5 +++++ > .../VariablePolicyHelperLib/VariablePolicyHelperLib.c | 5 +++++ > 2 files changed, 10 insertions(+) > > diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c > index e99a812a44..1053695b3b 100644 > --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c > +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c > @@ -1127,6 +1127,11 @@ AhciDmaTransfer ( > return EFI_INVALID_PARAMETER; > } > > + // > + // Set Status to suppress incorrect compiler/analyzer warnings > + // > + Status = EFI_SUCCESS; > + > // > // DMA buffer allocation. Needs to be done only once for both sync and async > // DMA transfers irrespective of number of retries. Yes, it's indeed a compiler problem. In the middle of the function, we have control flow like this: if (Task == NULL) { for (Retry = 0; Retry < AHCI_COMMAND_RETRIES; Retry++) { Status = AhciStartCommand (...); } } else { if (!Task->IsStart) { Status = AhciStartCommand (...); } if (Task->IsStart) { Status = AhciCheckFisReceived (...); } } There is no path through this without setting "Status", so the subsequent warning is indeed unjustified. > diff --git a/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.c b/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.c > index 0c9299c8b0..6bcb95247f 100644 > --- a/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.c > +++ b/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.c > @@ -115,6 +115,11 @@ CreateBasicVariablePolicy ( > return EFI_INVALID_PARAMETER; > } > > + // > + // Set NameSize to suppress incorrect compiler/analyzer warnings > + // > + NameSize = 0; > + > // Now we've gotta determine the total size of the buffer required for > // the VariablePolicy structure. > TotalSize = sizeof( VARIABLE_POLICY_ENTRY ); > Also correct: NameSize is only read if (Name != NULL), but in that case, NameSize is also set. And Name does not change between the two checks. Reviewed-by: Laszlo Ersek Thanks Laszlo