[edk2-devel] MdeModulePkg/UefiBootManagerLib: Use hob size to process MemoryTypeInfo

Anbazhagan, Baraneedharan via groups.io anbazhagan=hp.com at groups.io
Tue Dec 6 15:59:34 UTC 2022


Current code relies on last entry in hob to be MaxMemoryType enum value
which keeps changing on new memory type definition. If the HOB is
created by binaries built with older Edk2, current code leads to hang
which could be avoided by using hob size.

Signed-off-by: Baraneedharan Anbazhagan anbazhagan at hp.com<mailto:anbazhagan at hp.com>
---
MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c b/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
index a5e32ebdba..014e4557bf 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
@@ -140,6 +140,7 @@ BmSetMemoryTypeInformationVariable (
   UINT32                       Current;
   UINT32                       Next;
   EFI_HOB_GUID_TYPE            *GuidHob;
+  UINTN                        NoOfEntries;
   BOOLEAN                      MemoryTypeInformationModified;
   BOOLEAN                      MemoryTypeInformationVariableExists;
   EFI_BOOT_MODE                BootMode;
@@ -200,6 +201,7 @@ BmSetMemoryTypeInformationVariable (
   }
   VariableSize                  = GET_GUID_HOB_DATA_SIZE (GuidHob);
+  NoOfEntries                   = VariableSize / sizeof(EFI_MEMORY_TYPE_INFORMATION);
   PreviousMemoryTypeInformation = AllocateCopyPool (VariableSize, GET_GUID_HOB_DATA (GuidHob));
   if (PreviousMemoryTypeInformation == NULL) {
     return;
@@ -212,8 +214,8 @@ BmSetMemoryTypeInformationVariable (
   DEBUG ((DEBUG_INFO, " Type    Pages     Pages     Pages  \n"));
   DEBUG ((DEBUG_INFO, "======  ========  ========  ========\n"));
-  for (Index = 0; PreviousMemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) {
-    for (Index1 = 0; CurrentMemoryTypeInformation[Index1].Type != EfiMaxMemoryType; Index1++) {
+  for (Index = 0; Index < NoOfEntries; Index++) {
+    for (Index1 = 0; Index1 < NoOfEntries; Index1++) {
       if (PreviousMemoryTypeInformation[Index].Type == CurrentMemoryTypeInformation[Index1].Type) {
         break;
       }
--
2.38.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#97040): https://edk2.groups.io/g/devel/message/97040
Mute This Topic: https://groups.io/mt/95495909/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/edk2-devel-archive/attachments/20221206/a6b9ffe1/attachment-0001.htm>


More information about the edk2-devel-archive mailing list