[edk2-devel] [PATCH v2 3/5] MdeModulePkg/Core/Dxe: Fix DEADCODE Coverity issue

Ranbir Singh rsingh at ventanamicro.com
Wed Sep 27 06:05:59 UTC 2023


From: Ranbir Singh <Ranbir.Singh3 at Dell.com>

In the function PromoteGuardedFreePages(), the value of AvailablePages
cannot be ZERO at the condition check point

  if (AvailablePages != 0) {

as the code can come out of the while loop above only when AvailablePages
is non-ZERO.

Hence, remove the redundant condition check and the return FALSE;
DEADCODE statement at the end of the function.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4219

Cc: Dandan Bi <dandan.bi at intel.com>
Cc: Liming Gao <gaoliming at byosoft.com.cn>
Co-authored-by: Veeresh Sangolli <veeresh.sangolli at dellteam.com>
Signed-off-by: Ranbir Singh <Ranbir.Singh3 at Dell.com>
Signed-off-by: Ranbir Singh <rsingh at ventanamicro.com>
---
 MdeModulePkg/Core/Dxe/Mem/HeapGuard.c | 35 +++++++++-----------
 1 file changed, 16 insertions(+), 19 deletions(-)

diff --git a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
index 0c0ca61872b4..016791ee002b 100644
--- a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
+++ b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
@@ -1568,28 +1568,25 @@ PromoteGuardedFreePages (
     }
   }
 
-  if (AvailablePages != 0) {
-    DEBUG ((DEBUG_INFO, "Promoted pages: %lX (%lx)\r\n", Start, (UINT64)AvailablePages));
-    ClearGuardedMemoryBits (Start, AvailablePages);
+  DEBUG ((DEBUG_INFO, "Promoted pages: %lX (%lx)\r\n", Start, (UINT64)AvailablePages));
+  ClearGuardedMemoryBits (Start, AvailablePages);
 
-    if (gCpu != NULL) {
-      //
-      // Set flag to make sure allocating memory without GUARD for page table
-      // operation; otherwise infinite loops could be caused.
-      //
-      mOnGuarding = TRUE;
-      Status      = gCpu->SetMemoryAttributes (gCpu, Start, EFI_PAGES_TO_SIZE (AvailablePages), 0);
-      ASSERT_EFI_ERROR (Status);
-      mOnGuarding = FALSE;
-    }
-
-    mLastPromotedPage = Start;
-    *StartAddress     = Start;
-    *EndAddress       = Start + EFI_PAGES_TO_SIZE (AvailablePages) - 1;
-    return TRUE;
+  if (gCpu != NULL) {
+    //
+    // Set flag to make sure allocating memory without GUARD for page table
+    // operation; otherwise infinite loops could be caused.
+    //
+    mOnGuarding = TRUE;
+    Status      = gCpu->SetMemoryAttributes (gCpu, Start, EFI_PAGES_TO_SIZE (AvailablePages), 0);
+    ASSERT_EFI_ERROR (Status);
+    mOnGuarding = FALSE;
   }
 
-  return FALSE;
+  mLastPromotedPage = Start;
+  *StartAddress     = Start;
+  *EndAddress       = Start + EFI_PAGES_TO_SIZE (AvailablePages) - 1;
+
+  return TRUE;
 }
 
 /**
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#109104): https://edk2.groups.io/g/devel/message/109104
Mute This Topic: https://groups.io/mt/101612679/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-




More information about the edk2-devel-archive mailing list