public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* MdeModulePkg/UefiBootManagerLib: Use hob size to process MemoryTypeInfo
@ 2022-12-06 15:59 Anbazhagan, Baraneedharan
  0 siblings, 0 replies; only message in thread
From: Anbazhagan, Baraneedharan @ 2022-12-06 15:59 UTC (permalink / raw)
  To: devel@edk2.groups.io

[-- Attachment #1: Type: text/plain, Size: 2157 bytes --]

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@hp.com<mailto:anbazhagan@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


[-- Attachment #2: Type: text/html, Size: 6532 bytes --]

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-06 15:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-06 15:59 MdeModulePkg/UefiBootManagerLib: Use hob size to process MemoryTypeInfo Anbazhagan, Baraneedharan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox