From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: redhat.com, ip: 209.132.183.28, mailfrom: lersek@redhat.com) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by groups.io with SMTP; Fri, 12 Apr 2019 16:31:48 -0700 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C806E46288; Fri, 12 Apr 2019 23:31:47 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-65.rdu2.redhat.com [10.10.120.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 442276090C; Fri, 12 Apr 2019 23:31:46 +0000 (UTC) From: "Laszlo Ersek" To: edk2-devel-groups-io Cc: Anthony Perard , Ard Biesheuvel , Jordan Justen , Julien Grall Subject: [PATCH 08/10] OvmfPkg: suppress "Value stored to ... is never read" analyzer warnings Date: Sat, 13 Apr 2019 01:31:26 +0200 Message-Id: <20190412233128.4756-9-lersek@redhat.com> In-Reply-To: <20190412233128.4756-1-lersek@redhat.com> References: <20190412233128.4756-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 12 Apr 2019 23:31:47 +0000 (UTC) Content-Transfer-Encoding: quoted-printable RH covscan warns about assignments that it can determine are never "consumed" later ("dead stores"). The idea behind the warning is presumably that the programmer forgot to implement a dependent check somewhere. For each such warning that has been emitted for OvmfPkg, the case is one of the following however: - We assign a variable a value for (re-)initialization's sake, in preparation for further or future uses. This practice is safe (sometime= s even recommended!), hence we should suppress these warnings. - We capture a result or a computation in a variable, following a general programming pattern, but then decide to ignore the value in that particular case. This is again safe, and we should suppress these warnings too. According to the Clang documentation at https://clang-analyzer.llvm.org/faq.html#dead_store we should use (void)x; See the logs below (produced originally for edk2-stable201903). > Error: CLANG_WARNING: > edk2-89910a39dcfd/OvmfPkg/AcpiPlatformDxe/Xen.c:156:3: warning: Value > stored to 'NumberOfTableEntries' is never read > # NumberOfTableEntries =3D 0; > # ^ ~ > edk2-89910a39dcfd/OvmfPkg/AcpiPlatformDxe/Xen.c:156:3: note: Value > stored to 'NumberOfTableEntries' is never read > # NumberOfTableEntries =3D 0; > # ^ ~ > # 154| DsdtTable =3D NULL; > # 155| TableHandle =3D 0; > # 156|-> NumberOfTableEntries =3D 0; > # 157| > # 158| // > > Error: CLANG_WARNING: > edk2-89910a39dcfd/OvmfPkg/Library/PlatformBootManagerLib/QemuKernel.c:4= 3:3: > warning: Value stored to 'SetupSize' is never read > # SetupSize =3D 0; > # ^ ~ > edk2-89910a39dcfd/OvmfPkg/Library/PlatformBootManagerLib/QemuKernel.c:4= 3:3: > note: Value stored to 'SetupSize' is never read > # SetupSize =3D 0; > # ^ ~ > # 41| > # 42| SetupBuf =3D NULL; > # 43|-> SetupSize =3D 0; > # 44| KernelBuf =3D NULL; > # 45| KernelInitialSize =3D 0; > > Error: CLANG_WARNING: > edk2-89910a39dcfd/OvmfPkg/Library/SerializeVariablesLib/SerializeVariab= lesLib.c:609:9: > warning: Value stored to 'VariableDataBufferSize' is never read > # VariableDataBufferSize =3D 0; > # ^ ~ > edk2-89910a39dcfd/OvmfPkg/Library/SerializeVariablesLib/SerializeVariab= lesLib.c:609:9: > note: Value stored to 'VariableDataBufferSize' is never read > # VariableDataBufferSize =3D 0; > # ^ ~ > # 607| FreePool (VariableData); > # 608| VariableData =3D NULL; > # 609|-> VariableDataBufferSize =3D 0; > # 610| } > # 611| VariableData =3D AllocatePool (VariableDataSize); > > Error: CLANG_WARNING: > edk2-89910a39dcfd/OvmfPkg/Library/VirtioLib/VirtioLib.c:125:3: warning: > Value stored to 'RingPagesPtr' is never read > # RingPagesPtr +=3D sizeof *Ring->Used.AvailEvent; > # ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > edk2-89910a39dcfd/OvmfPkg/Library/VirtioLib/VirtioLib.c:125:3: note: > Value stored to 'RingPagesPtr' is never read > # RingPagesPtr +=3D sizeof *Ring->Used.AvailEvent; > # ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > # 123| > # 124| Ring->Used.AvailEvent =3D (volatile VOID *) RingPagesPtr; > # 125|-> RingPagesPtr +=3D sizeof *Ring->Used.AvailEvent; > # 126| > # 127| Ring->QueueSize =3D QueueSize; > > Error: CLANG_WARNING: > edk2-89910a39dcfd/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService= .c:1079:3: > warning: Value stored to 'FwhInstance' is never read > # FwhInstance =3D (EFI_FW_VOL_INSTANCE *) > # ^ ~~~~~~~~~~~~~~~~~~~~~~~ > edk2-89910a39dcfd/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService= .c:1079:3: > note: Value stored to 'FwhInstance' is never read > # FwhInstance =3D (EFI_FW_VOL_INSTANCE *) > # ^ ~~~~~~~~~~~~~~~~~~~~~~~ > # 1077| ASSERT_RETURN_ERROR (PcdStatus); > # 1078| > # 1079|-> FwhInstance =3D (EFI_FW_VOL_INSTANCE *) > # 1080| ( > # 1081| (UINTN) ((UINT8 *) FwhInstance) + FwVolHeader->HeaderLe= ngth + > > Error: CLANG_WARNING: > edk2-89910a39dcfd/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService= Dxe.c:173:3: > warning: Value stored to 'Status' is never read > # Status =3D gDS->RemoveMemorySpace ( > # ^ ~~~~~~~~~~~~~~~~~~~~~~~~ > edk2-89910a39dcfd/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService= Dxe.c:173:3: > note: Value stored to 'Status' is never read > # Status =3D gDS->RemoveMemorySpace ( > # ^ ~~~~~~~~~~~~~~~~~~~~~~~~ > # 171| // Mark flash region as runtime memory > # 172| // > # 173|-> Status =3D gDS->RemoveMemorySpace ( > # 174| BaseAddress, > # 175| Length > > Error: CLANG_WARNING: > edk2-89910a39dcfd/OvmfPkg/SataControllerDxe/SataController.c:231:3: > warning: Value stored to 'DeviceUDmaMode' is never read > # DeviceUDmaMode =3D 0; > # ^ ~ > edk2-89910a39dcfd/OvmfPkg/SataControllerDxe/SataController.c:231:3: > note: Value stored to 'DeviceUDmaMode' is never read > # DeviceUDmaMode =3D 0; > # ^ ~ > # 229| UINT16 DeviceUDmaMode; > # 230| > # 231|-> DeviceUDmaMode =3D 0; > # 232| > # 233| // > > Error: CLANG_WARNING: > edk2-89910a39dcfd/OvmfPkg/VirtioGpuDxe/Gop.c:65:5: warning: Value store= d > to 'Status' is never read > # Status =3D VirtioGpuSetScanout ( > # ^ ~~~~~~~~~~~~~~~~~~~~~ > edk2-89910a39dcfd/OvmfPkg/VirtioGpuDxe/Gop.c:65:5: note: Value stored t= o > 'Status' is never read > # Status =3D VirtioGpuSetScanout ( > # ^ ~~~~~~~~~~~~~~~~~~~~~ > # 63| // by setting ResourceId=3D0 for it. > # 64| // > # 65|-> Status =3D VirtioGpuSetScanout ( > # 66| VgpuGop->ParentBus, // VgpuDev > # 67| 0, 0, 0, 0, // X, Y, Width, Height > > Error: CLANG_WARNING: > edk2-89910a39dcfd/OvmfPkg/VirtioNetDxe/SnpReceive.c:165:3: warning: > Value stored to 'RxPtr' is never read > # RxPtr +=3D sizeof (UINT16); > # ^ ~~~~~~~~~~~~~~~ > edk2-89910a39dcfd/OvmfPkg/VirtioNetDxe/SnpReceive.c:165:3: note: Value > stored to 'RxPtr' is never read > # RxPtr +=3D sizeof (UINT16); > # ^ ~~~~~~~~~~~~~~~ > # 163| *Protocol =3D (UINT16) ((RxPtr[0] << 8) | RxPtr[1]); > # 164| } > # 165|-> RxPtr +=3D sizeof (UINT16); > # 166| > # 167| Status =3D EFI_SUCCESS; Cc: Anthony Perard Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Julien Grall Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1710 Issue: scan-0992.txt Issue: scan-0996.txt Issue: scan-0997.txt Issue: scan-0998.txt Issue: scan-1000.txt Issue: scan-1001.txt Issue: scan-1006.txt Issue: scan-1011.txt Issue: scan-1012.txt Signed-off-by: Laszlo Ersek --- OvmfPkg/AcpiPlatformDxe/Xen.c | 5 +++++ OvmfPkg/Library/PlatformBootManagerLib/QemuKernel.c | 5 +++++ OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.c | 4 ++++ OvmfPkg/Library/VirtioLib/VirtioLib.c | 5 +++++ OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c | 5 +++++ OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c | 5 +++++ OvmfPkg/SataControllerDxe/SataController.c | 5 +++++ OvmfPkg/VirtioGpuDxe/Gop.c | 6 ++++++ OvmfPkg/VirtioNetDxe/SnpReceive.c | 5 +++++ 9 files changed, 45 insertions(+) diff --git a/OvmfPkg/AcpiPlatformDxe/Xen.c b/OvmfPkg/AcpiPlatformDxe/Xen.= c index 357c60d23f4e..c8f275a8ee84 100644 --- a/OvmfPkg/AcpiPlatformDxe/Xen.c +++ b/OvmfPkg/AcpiPlatformDxe/Xen.c @@ -144,16 +144,21 @@ InstallXenTables ( Fadt2Table =3D NULL; Fadt1Table =3D NULL; Facs2Table =3D NULL; Facs1Table =3D NULL; DsdtTable =3D NULL; TableHandle =3D 0; NumberOfTableEntries =3D 0; =20 + // + // Suppress "Value stored to ... is never read" analyzer warnings. + // + (VOID)NumberOfTableEntries; + // // Try to find Xen ACPI tables // Status =3D GetXenAcpiRsdp (&XenAcpiRsdpStructurePtr); if (EFI_ERROR (Status)) { return Status; } =20 diff --git a/OvmfPkg/Library/PlatformBootManagerLib/QemuKernel.c b/OvmfPk= g/Library/PlatformBootManagerLib/QemuKernel.c index ddfef925edd3..fde8c40218a4 100644 --- a/OvmfPkg/Library/PlatformBootManagerLib/QemuKernel.c +++ b/OvmfPkg/Library/PlatformBootManagerLib/QemuKernel.c @@ -37,16 +37,21 @@ TryRunningQemuKernel ( SetupSize =3D 0; KernelBuf =3D NULL; KernelInitialSize =3D 0; CommandLine =3D NULL; CommandLineSize =3D 0; InitrdData =3D NULL; InitrdSize =3D 0; =20 + // + // Suppress "Value stored to ... is never read" analyzer warnings. + // + (VOID)SetupSize; + if (!QemuFwCfgIsAvailable ()) { return EFI_NOT_FOUND; } =20 QemuFwCfgSelectItem (QemuFwCfgItemKernelSize); KernelSize =3D (UINTN) QemuFwCfgRead64 (); =20 QemuFwCfgSelectItem (QemuFwCfgItemKernelSetupSize); diff --git a/OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.= c b/OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.c index a6cebcb54f6b..64fe9d9be543 100644 --- a/OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.c +++ b/OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.c @@ -596,16 +596,20 @@ SerializeVariablesIterateSystemVariables ( // // The currently allocated VariableData buffer is too small, // so we allocate a larger buffer. // if (VariableDataBufferSize !=3D 0) { FreePool (VariableData); VariableData =3D NULL; VariableDataBufferSize =3D 0; + // + // Suppress "Value stored to ... is never read" analyzer warning= s. + // + (VOID)VariableDataBufferSize; } VariableData =3D AllocatePool (VariableDataSize); if (VariableData =3D=3D NULL) { Status =3D EFI_OUT_OF_RESOURCES; break; } VariableDataBufferSize =3D VariableDataSize; =20 diff --git a/OvmfPkg/Library/VirtioLib/VirtioLib.c b/OvmfPkg/Library/Virt= ioLib/VirtioLib.c index 555d2a5ce7c9..0e4b8b6b265e 100644 --- a/OvmfPkg/Library/VirtioLib/VirtioLib.c +++ b/OvmfPkg/Library/VirtioLib/VirtioLib.c @@ -113,16 +113,21 @@ VirtioRingInit ( RingPagesPtr +=3D sizeof *Ring->Used.Idx; =20 Ring->Used.UsedElem =3D (volatile VOID *) RingPagesPtr; RingPagesPtr +=3D sizeof *Ring->Used.UsedElem * QueueSize; =20 Ring->Used.AvailEvent =3D (volatile VOID *) RingPagesPtr; RingPagesPtr +=3D sizeof *Ring->Used.AvailEvent; =20 + // + // Suppress "Value stored to ... is never read" analyzer warnings. + // + (VOID)RingPagesPtr; + Ring->QueueSize =3D QueueSize; return EFI_SUCCESS; } =20 =20 /** =20 Tear down the internal resources of a configured virtio ring. diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c b/Ov= mfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c index edf438a422fa..ff6565865846 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c @@ -1071,16 +1071,21 @@ FvbInitialize ( ASSERT_RETURN_ERROR (PcdStatus); =20 FwhInstance =3D (EFI_FW_VOL_INSTANCE *) ( (UINTN) ((UINT8 *) FwhInstance) + FwVolHeader->HeaderLength + (sizeof (EFI_FW_VOL_INSTANCE) - sizeof (EFI_FIRMWARE_VOLUME_HEADER= )) ); =20 + // + // Suppress "Value stored to ... is never read" analyzer warnings. + // + (VOID)FwhInstance; + // // Module type specific hook. // InstallVirtualAddressChangeHandler (); =20 PcdStatus =3D PcdSetBoolS (PcdOvmfFlashVariablesEnable, TRUE); ASSERT_RETURN_ERROR (PcdStatus); return EFI_SUCCESS; diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c b= /OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c index 69b20916bc7c..979122f2e2fd 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c @@ -164,16 +164,21 @@ MarkIoMemoryRangeForRuntimeAccess ( // // Mark flash region as runtime memory // Status =3D gDS->RemoveMemorySpace ( BaseAddress, Length ); =20 + // + // Suppress "Value stored to ... is never read" analyzer warnings. + // + (VOID)Status; + Status =3D gDS->AddMemorySpace ( EfiGcdMemoryTypeMemoryMappedIo, BaseAddress, Length, EFI_MEMORY_UC | EFI_MEMORY_RUNTIME ); ASSERT_EFI_ERROR (Status); =20 diff --git a/OvmfPkg/SataControllerDxe/SataController.c b/OvmfPkg/SataCon= trollerDxe/SataController.c index 8d6a6bbb2286..0cf6b42c886a 100644 --- a/OvmfPkg/SataControllerDxe/SataController.c +++ b/OvmfPkg/SataControllerDxe/SataController.c @@ -219,16 +219,21 @@ CalculateBestUdmaMode ( OUT UINT16 *SelectedMode ) { UINT16 TempMode; UINT16 DeviceUDmaMode; =20 DeviceUDmaMode =3D 0; =20 + // + // Suppress "Value stored to ... is never read" analyzer warnings. + // + (VOID)DeviceUDmaMode; + // // Check whether the WORD 88 (supported UltraDMA by drive) is valid // if ((IdentifyData->AtaData.field_validity & 0x04) =3D=3D 0x00) { return EFI_UNSUPPORTED; } =20 DeviceUDmaMode =3D IdentifyData->AtaData.ultra_dma_mode; diff --git a/OvmfPkg/VirtioGpuDxe/Gop.c b/OvmfPkg/VirtioGpuDxe/Gop.c index 0b2659d1d2b9..d0f81c349f73 100644 --- a/OvmfPkg/VirtioGpuDxe/Gop.c +++ b/OvmfPkg/VirtioGpuDxe/Gop.c @@ -57,16 +57,22 @@ ReleaseGopResources ( // by setting ResourceId=3D0 for it. // Status =3D VirtioGpuSetScanout ( VgpuGop->ParentBus, // VgpuDev 0, 0, 0, 0, // X, Y, Width, Height 0, // ScanoutId 0 // ResourceId ); + + // + // Suppress "Value stored to ... is never read" analyzer warnings. + // + (VOID)Status; + // // HACK BEGINS HERE // // According to the GPU Device section of the VirtIo specification, = the // above operation is valid: // // "The driver can use resource_id =3D 0 to disable a scanout." // diff --git a/OvmfPkg/VirtioNetDxe/SnpReceive.c b/OvmfPkg/VirtioNetDxe/Snp= Receive.c index cdee9a2aee47..51b2f8a4e370 100644 --- a/OvmfPkg/VirtioNetDxe/SnpReceive.c +++ b/OvmfPkg/VirtioNetDxe/SnpReceive.c @@ -153,16 +153,21 @@ VirtioNetReceive ( } RxPtr +=3D SIZE_OF_VNET (Mac); =20 if (Protocol !=3D NULL) { *Protocol =3D (UINT16) ((RxPtr[0] << 8) | RxPtr[1]); } RxPtr +=3D sizeof (UINT16); =20 + // + // Suppress "Value stored to ... is never read" analyzer warnings. + // + (VOID)RxPtr; + Status =3D EFI_SUCCESS; =20 RecycleDesc: ++Dev->RxLastUsed; =20 // // virtio-0.9.5, 2.4.1 Supplying Buffers to The Device // --=20 2.19.1.3.g30247aa5d201