]> git.proxmox.com Git - mirror_edk2.git/commitdiff
StandaloneMmPkg: Fix ECC error 3002 in StandaloneMmCpu
authorSami Mujawar <sami.mujawar@arm.com>
Thu, 3 Dec 2020 18:33:58 +0000 (18:33 +0000)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 7 Jan 2021 11:13:39 +0000 (11:13 +0000)
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>
StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.c

index 6a25c4c54843ccdc2d745e8e537942d49b1d1141..20877480535c66761ba2420f9b3fbd8a709c2155 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 \r
   Copyright (c) 2016 HP Development Company, L.P.\r
-  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.\r
+  Copyright (c) 2016 - 2021, Arm Limited. All rights reserved.\r
 \r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
@@ -84,12 +84,18 @@ PiMmStandaloneArmTfCpuDriverEntry (
   }\r
 \r
   // Perform parameter validation of NsCommBufferAddr\r
-  if (NsCommBufferAddr && (NsCommBufferAddr < mNsCommBuffer.PhysicalStart))\r
+  if (NsCommBufferAddr == (UINTN)NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (NsCommBufferAddr < mNsCommBuffer.PhysicalStart) {\r
     return EFI_ACCESS_DENIED;\r
+  }\r
 \r
   if ((NsCommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=\r
-      (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize))\r
+      (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)) {\r
     return EFI_INVALID_PARAMETER;\r
+  }\r
 \r
   // Find out the size of the buffer passed\r
   NsCommBufferSize = ((EFI_MM_COMMUNICATE_HEADER *) NsCommBufferAddr)->MessageLength +\r
@@ -97,9 +103,9 @@ PiMmStandaloneArmTfCpuDriverEntry (
 \r
   // perform bounds check.\r
   if (NsCommBufferAddr + NsCommBufferSize >=\r
-      mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)\r
+      mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize) {\r
     return EFI_ACCESS_DENIED;\r
-\r
+  }\r
 \r
   // Now that the secure world can see the normal world buffer, allocate\r
   // memory to copy the communication buffer to the secure world.\r
@@ -192,8 +198,9 @@ PiMmCpuTpFwRootMmiHandler (
   ASSERT (CommBufferSize == NULL);\r
 \r
   CpuNumber = mMmst->CurrentlyExecutingCpu;\r
-  if (!PerCpuGuidedEventContext[CpuNumber])\r
+  if (PerCpuGuidedEventContext[CpuNumber] == NULL) {\r
     return EFI_NOT_FOUND;\r
+  }\r
 \r
   DEBUG ((DEBUG_INFO, "CommBuffer - 0x%x, CommBufferSize - 0x%x\n",\r
           PerCpuGuidedEventContext[CpuNumber],\r
index 617babd5ab4bcb200ee10e19ec6f99c2ef163200..9e496096018da80aa8e7fe84721b1fa757a0b3ce 100644 (file)
@@ -2,7 +2,7 @@
 \r
   Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
   Copyright (c) 2016 HP Development Company, L.P.\r
-  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.\r
+  Copyright (c) 2016 - 2021, Arm Limited. All rights reserved.\r
 \r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
@@ -53,16 +53,19 @@ GetGuidedHobData (
 {\r
   EFI_HOB_GUID_TYPE *Hob;\r
 \r
-  if (!HobList || !HobGuid || !HobData)\r
+  if ((HobList == NULL) || (HobGuid == NULL) || (HobData == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
+  }\r
 \r
   Hob = GetNextGuidHob (HobGuid, HobList);\r
-  if (!Hob)\r
+  if (Hob == NULL) {\r
     return EFI_NOT_FOUND;\r
+  }\r
 \r
   *HobData = GET_GUID_HOB_DATA (Hob);\r
-  if (!HobData)\r
+  if (*HobData == NULL) {\r
     return EFI_NOT_FOUND;\r
+  }\r
 \r
   return EFI_SUCCESS;\r
 }\r