]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
MdeModulePkg/Bds: Fix a bug that may causes S4 fails to resume
[mirror_edk2.git] / MdeModulePkg / Library / UefiBootManagerLib / BmMisc.c
index 09e421135205d2fcc166840243e4a314e18a67e6..e11d8428d63b4466bd297710e13e7be615f796cd 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Misc library functions.\r
 \r
-Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
@@ -205,8 +205,11 @@ BmSetMemoryTypeInformationVariable (
     //\r
     return;\r
   }\r
-  PreviousMemoryTypeInformation = GET_GUID_HOB_DATA (GuidHob);\r
-  VariableSize = GET_GUID_HOB_DATA_SIZE (GuidHob);\r
+  VariableSize                  = GET_GUID_HOB_DATA_SIZE (GuidHob);\r
+  PreviousMemoryTypeInformation = AllocateCopyPool (VariableSize, GET_GUID_HOB_DATA (GuidHob));\r
+  if (PreviousMemoryTypeInformation == NULL) {\r
+    return;\r
+  }\r
 \r
   //\r
   // Use a heuristic to adjust the Memory Type Information for the next boot\r
@@ -278,14 +281,18 @@ BmSetMemoryTypeInformationVariable (
       // then reset the platform so the new Memory Type Information setting will be used to guarantee that an S4\r
       // entry/resume cycle will not fail.\r
       //\r
-      if (MemoryTypeInformationModified && Boot && PcdGetBool (PcdResetOnMemoryTypeInformationChange)) {\r
-        DEBUG ((EFI_D_INFO, "Memory Type Information settings change. Warm Reset!!!\n"));\r
-        gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r
+      if (MemoryTypeInformationModified) {\r
+        DEBUG ((EFI_D_INFO, "Memory Type Information settings change.\n"));\r
+        if (Boot && PcdGetBool (PcdResetOnMemoryTypeInformationChange)) {\r
+          DEBUG ((EFI_D_INFO, "...Warm Reset!!!\n"));\r
+          gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r
+        }\r
       }\r
     } else {\r
       DEBUG ((EFI_D_ERROR, "Memory Type Information settings cannot be saved. OS S4 may fail!\n"));\r
     }\r
   }\r
+  FreePool (PreviousMemoryTypeInformation);\r
 }\r
 \r
 /**\r