summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Core
diff options
context:
space:
mode:
authorqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>2009-03-11 13:59:22 +0000
committerqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>2009-03-11 13:59:22 +0000
commit98a601b177b5de6dcb7c5007cd292d87372e0f8c (patch)
tree7ab028c4b801bb556e6b34de42f9602d59f546ef /MdeModulePkg/Core
parent97ef8cff3e3c1f376c8967f08f34ab0ccca20936 (diff)
downloadedk2-98a601b177b5de6dcb7c5007cd292d87372e0f8c.zip
edk2-98a601b177b5de6dcb7c5007cd292d87372e0f8c.tar.gz
edk2-98a601b177b5de6dcb7c5007cd292d87372e0f8c.tar.bz2
Add comments and refine code to avoid addition overflow.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7863 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdeModulePkg/Core')
-rw-r--r--MdeModulePkg/Core/Pei/Memory/MemoryServices.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c
index 3e424ad..22e04cd 100644
--- a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c
+++ b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c
@@ -161,7 +161,11 @@ PeiAllocatePages (
// Verify that there is sufficient memory to satisfy the allocation
//
RemainingPages = EFI_SIZE_TO_PAGES ((UINTN) (*FreeMemoryTop - *FreeMemoryBottom));
- if ((INTN) (RemainingPages - EFI_SIZE_TO_PAGES (sizeof (EFI_HOB_MEMORY_ALLOCATION))) < Pages) {
+ //
+ // For page allocation, the overhead sizeof (EFI_HOB_MEMORY_ALLOCATION) needs one extra page.
+ // So the number of remaining pages needs to be greater than that of the request pages.
+ //
+ if (RemainingPages <= 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;