From 6203199177e6968f69485ac7d9823f91e8b907e0 Mon Sep 17 00:00:00 2001 From: qhuang8 Date: Tue, 10 Mar 2009 14:34:42 +0000 Subject: [PATCH] Fix a bug that Pages*EFI_PAGES_SIZE might be a negative number. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7854 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Core/Pei/Memory/MemoryServices.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c index d447d688d3..3e424ad1a5 100644 --- a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c +++ b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c @@ -128,6 +128,7 @@ PeiAllocatePages ( EFI_PEI_HOB_POINTERS Hob; EFI_PHYSICAL_ADDRESS *FreeMemoryTop; EFI_PHYSICAL_ADDRESS *FreeMemoryBottom; + UINTN RemainingPages; PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices); Hob.Raw = PrivateData->HobList.Raw; @@ -159,11 +160,10 @@ PeiAllocatePages ( // // Verify that there is sufficient memory to satisfy the allocation // - if (*(FreeMemoryTop) - ((Pages * EFI_PAGE_SIZE) + sizeof (EFI_HOB_MEMORY_ALLOCATION)) < - *(FreeMemoryBottom)) { - DEBUG ((EFI_D_ERROR, "AllocatePages failed: No 0x%x Pages is available.\n", Pages)); - DEBUG ((EFI_D_ERROR, "There is only left 0x%x pages memory resource to be allocated.\n", \ - EFI_SIZE_TO_PAGES ((UINTN) (*(FreeMemoryTop) - *(FreeMemoryBottom))))); + RemainingPages = EFI_SIZE_TO_PAGES ((UINTN) (*FreeMemoryTop - *FreeMemoryBottom)); + if ((INTN) (RemainingPages - EFI_SIZE_TO_PAGES (sizeof (EFI_HOB_MEMORY_ALLOCATION))) < Pages) { + DEBUG ((EFI_D_ERROR, "AllocatePages failed: No 0x%lx Pages is available.\n", (UINT64) Pages)); + DEBUG ((EFI_D_ERROR, "There is only left 0x%lx pages memory resource to be allocated.\n", (UINT64) RemainingPages)); return EFI_OUT_OF_RESOURCES; } else { // -- 2.39.2