]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Fix bug of AllocatePages for large alignment
authorHeyi Guo <heyi.guo@linaro.org>
Mon, 8 Jun 2015 09:24:31 +0000 (09:24 +0000)
committerlgao4 <lgao4@Edk2>
Mon, 8 Jun 2015 09:24:31 +0000 (09:24 +0000)
DescEnd will be clipped for alignment in CoreFindFreePagesI, and it
may fall below DescStart, when alignment is more than 16KB (included)
and both DescStart and original DescEnd fall into a single range of
such alignment. This results in a huge size (Negative number in
unsigned type) for this descriptor, fulfilling the allocation
requirement but failing to run ConvertPages; at last it causes
occasional failure of AllocatePages.

A simple comparison is added to ensure we would never get a negative
number.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Heyi Guo <heyi.guo@linaro.org>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17575 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Core/Dxe/Mem/Page.c

index a92c865e171677d1e196ff7c529e19d6d163d944..f2efaf12787b072b10e273d40e82f38acc42e772 100644 (file)
@@ -1051,6 +1051,11 @@ CoreFindFreePagesI (
 \r
     DescEnd = ((DescEnd + 1) & (~(Alignment - 1))) - 1;\r
 \r
+    // Skip if DescEnd is less than DescStart after alignment clipping\r
+    if (DescEnd < DescStart) {\r
+      continue;\r
+    }\r
+\r
     //\r
     // Compute the number of bytes we can used from this\r
     // descriptor, and see it's enough to satisfy the request\r