]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Fix a bug that Pages*EFI_PAGES_SIZE might be a negative number.
authorqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 10 Mar 2009 14:34:42 +0000 (14:34 +0000)
committerqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 10 Mar 2009 14:34:42 +0000 (14:34 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7854 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Core/Pei/Memory/MemoryServices.c

index d447d688d3c1d60e0810df0a0f054d5054e8b2c3..3e424ad1a5262b5062991b8603bc2d401bdc7414 100644 (file)
@@ -128,6 +128,7 @@ PeiAllocatePages (
   EFI_PEI_HOB_POINTERS                    Hob;\r
   EFI_PHYSICAL_ADDRESS                    *FreeMemoryTop;\r
   EFI_PHYSICAL_ADDRESS                    *FreeMemoryBottom;\r
+  UINTN                                   RemainingPages;\r
 \r
   PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
   Hob.Raw     = PrivateData->HobList.Raw;\r
@@ -159,11 +160,10 @@ PeiAllocatePages (
   //\r
   // Verify that there is sufficient memory to satisfy the allocation\r
   //\r
-  if (*(FreeMemoryTop) - ((Pages * EFI_PAGE_SIZE) + sizeof (EFI_HOB_MEMORY_ALLOCATION)) < \r
-      *(FreeMemoryBottom)) {\r
-    DEBUG ((EFI_D_ERROR, "AllocatePages failed: No 0x%x Pages is available.\n", Pages));\r
-    DEBUG ((EFI_D_ERROR, "There is only left 0x%x pages memory resource to be allocated.\n", \\r
-    EFI_SIZE_TO_PAGES ((UINTN) (*(FreeMemoryTop) - *(FreeMemoryBottom)))));\r
+  RemainingPages = EFI_SIZE_TO_PAGES ((UINTN) (*FreeMemoryTop - *FreeMemoryBottom));\r
+  if ((INTN) (RemainingPages - EFI_SIZE_TO_PAGES (sizeof (EFI_HOB_MEMORY_ALLOCATION))) < Pages) {\r
+    DEBUG ((EFI_D_ERROR, "AllocatePages failed: No 0x%lx Pages is available.\n", (UINT64) Pages));\r
+    DEBUG ((EFI_D_ERROR, "There is only left 0x%lx pages memory resource to be allocated.\n", (UINT64) RemainingPages));\r
     return  EFI_OUT_OF_RESOURCES;\r
   } else {\r
     //\r