summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSami Mujawar <sami.mujawar@arm.com>2020-12-03 18:33:58 +0000
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2021-01-07 11:13:39 +0000
commita9da96ac2ae6af4df2ef1c036a18c3092783cfa6 (patch)
treefe017929a11fd0f33575f02760efa709114d99c0
parent9ef62f5078c33368cbf481e36adb2ae3c450f835 (diff)
downloadedk2-a9da96ac2ae6af4df2ef1c036a18c3092783cfa6.tar.gz
edk2-a9da96ac2ae6af4df2ef1c036a18c3092783cfa6.tar.bz2
edk2-a9da96ac2ae6af4df2ef1c036a18c3092783cfa6.zip
StandaloneMmPkg: Fix ECC error 3002 in StandaloneMmCpu
Bugzilla: 3150 (https://bugzilla.tianocore.org/show_bug.cgi?id=3150) Fix the ECC tool reported error "[3002] Non-Boolean comparisons should use a compare operator". Also fix the following: - add curly braces for 'if' condition statements to comply with the coding standard. - The value returned by GET_GUID_HOB_DATA() is stored in *HobData. Therefore, check *HobData against NULL. The original code was checking HobData which is incorrect. Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> Acked-by: Jiewen Yao <Jiewen.yao@intel.com> Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
-rw-r--r--StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c19
-rw-r--r--StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.c11
2 files changed, 20 insertions, 10 deletions
diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
index 6a25c4c548..2087748053 100644
--- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
+++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
@@ -1,7 +1,7 @@
/** @file
Copyright (c) 2016 HP Development Company, L.P.
- Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
+ Copyright (c) 2016 - 2021, Arm Limited. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -84,12 +84,18 @@ PiMmStandaloneArmTfCpuDriverEntry (
}
// Perform parameter validation of NsCommBufferAddr
- if (NsCommBufferAddr && (NsCommBufferAddr < mNsCommBuffer.PhysicalStart))
+ if (NsCommBufferAddr == (UINTN)NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (NsCommBufferAddr < mNsCommBuffer.PhysicalStart) {
return EFI_ACCESS_DENIED;
+ }
if ((NsCommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
- (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize))
+ (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)) {
return EFI_INVALID_PARAMETER;
+ }
// Find out the size of the buffer passed
NsCommBufferSize = ((EFI_MM_COMMUNICATE_HEADER *) NsCommBufferAddr)->MessageLength +
@@ -97,9 +103,9 @@ PiMmStandaloneArmTfCpuDriverEntry (
// perform bounds check.
if (NsCommBufferAddr + NsCommBufferSize >=
- mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)
+ mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize) {
return EFI_ACCESS_DENIED;
-
+ }
// Now that the secure world can see the normal world buffer, allocate
// memory to copy the communication buffer to the secure world.
@@ -192,8 +198,9 @@ PiMmCpuTpFwRootMmiHandler (
ASSERT (CommBufferSize == NULL);
CpuNumber = mMmst->CurrentlyExecutingCpu;
- if (!PerCpuGuidedEventContext[CpuNumber])
+ if (PerCpuGuidedEventContext[CpuNumber] == NULL) {
return EFI_NOT_FOUND;
+ }
DEBUG ((DEBUG_INFO, "CommBuffer - 0x%x, CommBufferSize - 0x%x\n",
PerCpuGuidedEventContext[CpuNumber],
diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.c b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.c
index 617babd5ab..9e49609601 100644
--- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.c
+++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.c
@@ -2,7 +2,7 @@
Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
Copyright (c) 2016 HP Development Company, L.P.
- Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
+ Copyright (c) 2016 - 2021, Arm Limited. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -53,16 +53,19 @@ GetGuidedHobData (
{
EFI_HOB_GUID_TYPE *Hob;
- if (!HobList || !HobGuid || !HobData)
+ if ((HobList == NULL) || (HobGuid == NULL) || (HobData == NULL)) {
return EFI_INVALID_PARAMETER;
+ }
Hob = GetNextGuidHob (HobGuid, HobList);
- if (!Hob)
+ if (Hob == NULL) {
return EFI_NOT_FOUND;
+ }
*HobData = GET_GUID_HOB_DATA (Hob);
- if (!HobData)
+ if (*HobData == NULL) {
return EFI_NOT_FOUND;
+ }
return EFI_SUCCESS;
}