diff mbox

UEFI-ARM: PrepareFdt need to use DescriptorSize to iterate through MemoryMap

Message ID 1377320028-14160-2-git-send-email-victor.kamensky@linaro.org
State New
Headers show

Commit Message

vkamensky Aug. 24, 2013, 4:53 a.m. UTC
Fix PrepareFdt function to use DescriptorSize returned by gBS->GetMemoryMap
(CoreGetMemoryMap) to iterate through MemoryMap area returned by the same
function. Existing code that assumes that MemoryMap is array of
EFI_MEMORY_DESCRIPTOR structures which is incorrect.

Signed-off-by: Victor Kamensky <victor.kamensky@linaro.org>
---
 ArmPkg/Library/BdsLib/BdsLinuxFdt.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/ArmPkg/Library/BdsLib/BdsLinuxFdt.c b/ArmPkg/Library/BdsLib/BdsLinuxFdt.c
index 4ff0afe..df12607 100644
--- a/ArmPkg/Library/BdsLib/BdsLinuxFdt.c
+++ b/ArmPkg/Library/BdsLib/BdsLinuxFdt.c
@@ -490,17 +490,18 @@  PrepareFdt (
 
   // Go through the list and add the reserved region to the Device Tree
   if (!EFI_ERROR(Status)) {
-    for (Index = 0; Index < (MemoryMapSize / sizeof(EFI_MEMORY_DESCRIPTOR)); Index++) {
+    for (Index = 0; Index < (MemoryMapSize / DescriptorSize); Index++) {
       if (IsLinuxReservedRegion ((EFI_MEMORY_TYPE)MemoryMap[Index].Type)) {
         DEBUG((DEBUG_VERBOSE, "Reserved region of type %d [0x%X, 0x%X]\n",
-            MemoryMap[Index].Type,
-            (UINTN)MemoryMap[Index].PhysicalStart,
-            (UINTN)(MemoryMap[Index].PhysicalStart + MemoryMap[Index].NumberOfPages * EFI_PAGE_SIZE)));
-        err = fdt_add_mem_rsv(fdt, MemoryMap[Index].PhysicalStart, MemoryMap[Index].NumberOfPages * EFI_PAGE_SIZE);
+            MemoryMap->Type,
+            (UINTN)MemoryMap->PhysicalStart,
+            (UINTN)(MemoryMap->PhysicalStart + MemoryMap->NumberOfPages * EFI_PAGE_SIZE)));
+        err = fdt_add_mem_rsv(fdt, MemoryMap->PhysicalStart, MemoryMap->NumberOfPages * EFI_PAGE_SIZE);
         if (err != 0) {
           Print(L"Warning: Fail to add 'memreserve' (err:%d)\n", err);
         }
       }
+      MemoryMap = (EFI_MEMORY_DESCRIPTOR *)((UINTN)MemoryMap + DescriptorSize);
     }
   }