From: Ranbir Singh <ranbir.sin...@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...@intel.com> Cc: Liming Gao <gaolim...@byosoft.com.cn> Co-authored-by: Veeresh Sangolli <veeresh.sango...@dellteam.com> Signed-off-by: Ranbir Singh <ranbir.sin...@dell.com> Signed-off-by: Ranbir Singh <rsi...@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/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-