Revision: 16708
          http://sourceforge.net/p/edk2/code/16708
Author:   vanjeff
Date:     2015-02-03 08:12:46 +0000 (Tue, 03 Feb 2015)
Log Message:
-----------
MdeModulePkg DxeCore/PiSmmCore/MemoryProfileInfo: Fix EBC and VS2013 build 
failure.

(Sync patch r16396 from main trunk.)

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.z...@intel.com>
Reviewed-by: Jiewen Yao <jiewen....@intel.com>

Revision Links:
--------------
    http://sourceforge.net/p/edk2/code/16396

Modified Paths:
--------------
    
branches/UDK2014.SP1/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c
    branches/UDK2014.SP1/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c
    branches/UDK2014.SP1/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c

Modified: 
branches/UDK2014.SP1/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c
===================================================================
--- 
branches/UDK2014.SP1/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c
 2015-02-03 08:11:38 UTC (rev 16707)
+++ 
branches/UDK2014.SP1/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c
 2015-02-03 08:12:46 UTC (rev 16708)
@@ -557,6 +557,7 @@
   Size = Size + sizeof (MEMORY_PROFILE_ALLOC_INFO);
   Data = AllocateZeroPool ((UINTN) Size);
   if (Data == NULL) {
+    Status = EFI_OUT_OF_RESOURCES;
     Print (L"UefiMemoryProfile: AllocateZeroPool (0x%x) - %r\n", Size, Status);
     return Status;
   }
@@ -597,7 +598,7 @@
 {
   EFI_STATUS                                    Status;
   UINTN                                         CommSize;
-  UINT8                                         CommBuffer[sizeof (EFI_GUID) + 
sizeof (UINTN) + sizeof (SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA)];
+  UINT8                                         *CommBuffer;
   EFI_SMM_COMMUNICATE_HEADER                    *CommHeader;
   SMRAM_PROFILE_PARAMETER_GET_PROFILE_INFO      *CommGetProfileInfo;
   SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA      *CommGetProfileData;
@@ -611,6 +612,14 @@
     return Status;
   }
 
+  CommSize = sizeof (EFI_GUID) + sizeof (UINTN) + sizeof 
(SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA);
+  CommBuffer = AllocateZeroPool (CommSize);
+  if (CommBuffer == NULL) {
+    Status = EFI_OUT_OF_RESOURCES;
+    Print (L"SmramProfile: AllocateZeroPool (0x%x) for comm buffer - %r\n", 
CommSize, Status);
+    return Status;
+  }
+
   //
   // Get Size
   //
@@ -627,6 +636,7 @@
   CommSize = sizeof (EFI_GUID) + sizeof (UINTN) + CommHeader->MessageLength;
   Status = SmmCommunication->Communicate (SmmCommunication, CommBuffer, 
&CommSize);
   if (EFI_ERROR (Status)) {
+    FreePool (CommBuffer);
     DEBUG ((EFI_D_ERROR, "SmramProfile: SmmCommunication - %r\n", Status));
     return Status;
   }
@@ -643,15 +653,17 @@
   //
   ProfileBuffer = (PHYSICAL_ADDRESS) (UINTN) AllocateZeroPool ((UINTN) 
ProfileSize);
   if (ProfileBuffer == 0) {
-    Print (L"UefiMemoryProfile: AllocateZeroPool (0x%x) - %r\n", (UINTN) 
ProfileSize, Status);
-    return EFI_SUCCESS;
+    FreePool (CommBuffer);
+    Status = EFI_OUT_OF_RESOURCES;
+    Print (L"SmramProfile: AllocateZeroPool (0x%x) for profile buffer - %r\n", 
(UINTN) ProfileSize, Status);
+    return Status;
   }
 
   CommHeader = (EFI_SMM_COMMUNICATE_HEADER *) &CommBuffer[0];
   CopyMem (&CommHeader->HeaderGuid, &gEdkiiMemoryProfileGuid, 
sizeof(gEdkiiMemoryProfileGuid));
   CommHeader->MessageLength = sizeof 
(SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA);
 
-  CommGetProfileData = (SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA 
*)&CommBuffer[OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data)];
+  CommGetProfileData = (SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA *) 
&CommBuffer[OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data)];
   CommGetProfileData->Header.Command      = 
SMRAM_PROFILE_COMMAND_GET_PROFILE_DATA;
   CommGetProfileData->Header.DataLength   = sizeof (*CommGetProfileData);
   CommGetProfileData->Header.ReturnStatus = (UINT64)-1;
@@ -663,6 +675,8 @@
   ASSERT_EFI_ERROR (Status);
 
   if (CommGetProfileData->Header.ReturnStatus != 0) {
+    FreePool ((VOID *) (UINTN) CommGetProfileData->ProfileBuffer);
+    FreePool (CommBuffer);
     Print (L"GetProfileData - 0x%x\n", 
CommGetProfileData->Header.ReturnStatus);
     return EFI_SUCCESS;
   }
@@ -674,6 +688,7 @@
   Print (L"======= SmramProfile end =======\n\n\n");
 
   FreePool ((VOID *) (UINTN) CommGetProfileData->ProfileBuffer);
+  FreePool (CommBuffer);
 
   return EFI_SUCCESS;
 }

Modified: branches/UDK2014.SP1/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c
===================================================================
--- branches/UDK2014.SP1/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c        
2015-02-03 08:11:38 UTC (rev 16707)
+++ branches/UDK2014.SP1/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c        
2015-02-03 08:12:46 UTC (rev 16708)
@@ -817,6 +817,8 @@
   MEMORY_PROFILE_ALLOC_INFO_DATA    *AllocInfoData;
   EFI_MEMORY_TYPE                   ProfileMemoryIndex;
 
+  AllocInfoData = NULL;
+
   ContextData = GetMemoryProfileContext ();
   if (ContextData == NULL) {
     return FALSE;

Modified: branches/UDK2014.SP1/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c
===================================================================
--- branches/UDK2014.SP1/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c       
2015-02-03 08:11:38 UTC (rev 16707)
+++ branches/UDK2014.SP1/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c       
2015-02-03 08:12:46 UTC (rev 16708)
@@ -824,6 +824,8 @@
   MEMORY_PROFILE_ALLOC_INFO_DATA    *AllocInfoData;
   EFI_MEMORY_TYPE                   ProfileMemoryIndex;
 
+  AllocInfoData = NULL;
+
   ContextData = GetSmramProfileContext ();
   if (ContextData == NULL) {
     return FALSE;


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
edk2-commits mailing list
edk2-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to