]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeCoreMemoryAllocationLib/MemoryAllocationLib.c
MdeModulePkg: Apply uncrustify changes
[mirror_edk2.git] / MdeModulePkg / Library / DxeCoreMemoryAllocationLib / MemoryAllocationLib.c
index cecf2ddbe73ccdccf246356a70b33a3eef6701eb..e813e87f24701ea05bde8a01762e7aabcc808b8f 100644 (file)
@@ -8,10 +8,8 @@
 \r
 **/\r
 \r
-\r
 #include <PiDxe.h>\r
 \r
-\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/DebugLib.h>\r
@@ -49,7 +47,8 @@ InternalAllocatePages (
   if (EFI_ERROR (Status)) {\r
     return NULL;\r
   }\r
-  return (VOID *) (UINTN) Memory;\r
+\r
+  return (VOID *)(UINTN)Memory;\r
 }\r
 \r
 /**\r
@@ -76,7 +75,7 @@ AllocatePages (
   Buffer = InternalAllocatePages (EfiBootServicesData, Pages);\r
   if (Buffer != NULL) {\r
     MemoryProfileLibRecord (\r
-      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),\r
+      (PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),\r
       MEMORY_PROFILE_ACTION_LIB_ALLOCATE_PAGES,\r
       EfiBootServicesData,\r
       Buffer,\r
@@ -84,6 +83,7 @@ AllocatePages (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -111,7 +111,7 @@ AllocateRuntimePages (
   Buffer = InternalAllocatePages (EfiRuntimeServicesData, Pages);\r
   if (Buffer != NULL) {\r
     MemoryProfileLibRecord (\r
-      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),\r
+      (PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),\r
       MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_PAGES,\r
       EfiRuntimeServicesData,\r
       Buffer,\r
@@ -119,6 +119,7 @@ AllocateRuntimePages (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -146,7 +147,7 @@ AllocateReservedPages (
   Buffer = InternalAllocatePages (EfiReservedMemoryType, Pages);\r
   if (Buffer != NULL) {\r
     MemoryProfileLibRecord (\r
-      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),\r
+      (PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),\r
       MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_PAGES,\r
       EfiReservedMemoryType,\r
       Buffer,\r
@@ -154,6 +155,7 @@ AllocateReservedPages (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -184,7 +186,7 @@ FreePages (
   EFI_STATUS  Status;\r
 \r
   ASSERT (Pages != 0);\r
-  Status = CoreFreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);\r
+  Status = CoreFreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, Pages);\r
   ASSERT_EFI_ERROR (Status);\r
 }\r
 \r
@@ -228,23 +230,25 @@ InternalAllocateAlignedPages (
   if (Pages == 0) {\r
     return NULL;\r
   }\r
+\r
   if (Alignment > EFI_PAGE_SIZE) {\r
     //\r
     // Calculate the total number of pages since alignment is larger than page size.\r
     //\r
-    AlignmentMask  = Alignment - 1;\r
-    RealPages      = Pages + EFI_SIZE_TO_PAGES (Alignment);\r
+    AlignmentMask = Alignment - 1;\r
+    RealPages     = Pages + EFI_SIZE_TO_PAGES (Alignment);\r
     //\r
     // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.\r
     //\r
     ASSERT (RealPages > Pages);\r
 \r
-    Status         = CoreAllocatePages (AllocateAnyPages, MemoryType, RealPages, &Memory);\r
+    Status = CoreAllocatePages (AllocateAnyPages, MemoryType, RealPages, &Memory);\r
     if (EFI_ERROR (Status)) {\r
       return NULL;\r
     }\r
-    AlignedMemory  = ((UINTN) Memory + AlignmentMask) & ~AlignmentMask;\r
-    UnalignedPages = EFI_SIZE_TO_PAGES (AlignedMemory - (UINTN) Memory);\r
+\r
+    AlignedMemory  = ((UINTN)Memory + AlignmentMask) & ~AlignmentMask;\r
+    UnalignedPages = EFI_SIZE_TO_PAGES (AlignedMemory - (UINTN)Memory);\r
     if (UnalignedPages > 0) {\r
       //\r
       // Free first unaligned page(s).\r
@@ -252,6 +256,7 @@ InternalAllocateAlignedPages (
       Status = CoreFreePages (Memory, UnalignedPages);\r
       ASSERT_EFI_ERROR (Status);\r
     }\r
+\r
     Memory         = AlignedMemory + EFI_PAGES_TO_SIZE (Pages);\r
     UnalignedPages = RealPages - Pages - UnalignedPages;\r
     if (UnalignedPages > 0) {\r
@@ -269,9 +274,11 @@ InternalAllocateAlignedPages (
     if (EFI_ERROR (Status)) {\r
       return NULL;\r
     }\r
-    AlignedMemory  = (UINTN) Memory;\r
+\r
+    AlignedMemory = (UINTN)Memory;\r
   }\r
-  return (VOID *) AlignedMemory;\r
+\r
+  return (VOID *)AlignedMemory;\r
 }\r
 \r
 /**\r
@@ -304,7 +311,7 @@ AllocateAlignedPages (
   Buffer = InternalAllocateAlignedPages (EfiBootServicesData, Pages, Alignment);\r
   if (Buffer != NULL) {\r
     MemoryProfileLibRecord (\r
-      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),\r
+      (PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),\r
       MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_PAGES,\r
       EfiBootServicesData,\r
       Buffer,\r
@@ -312,6 +319,7 @@ AllocateAlignedPages (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -345,7 +353,7 @@ AllocateAlignedRuntimePages (
   Buffer = InternalAllocateAlignedPages (EfiRuntimeServicesData, Pages, Alignment);\r
   if (Buffer != NULL) {\r
     MemoryProfileLibRecord (\r
-      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),\r
+      (PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),\r
       MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_RUNTIME_PAGES,\r
       EfiRuntimeServicesData,\r
       Buffer,\r
@@ -353,6 +361,7 @@ AllocateAlignedRuntimePages (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -386,7 +395,7 @@ AllocateAlignedReservedPages (
   Buffer = InternalAllocateAlignedPages (EfiReservedMemoryType, Pages, Alignment);\r
   if (Buffer != NULL) {\r
     MemoryProfileLibRecord (\r
-      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),\r
+      (PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),\r
       MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_RESERVED_PAGES,\r
       EfiReservedMemoryType,\r
       Buffer,\r
@@ -394,6 +403,7 @@ AllocateAlignedReservedPages (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -424,7 +434,7 @@ FreeAlignedPages (
   EFI_STATUS  Status;\r
 \r
   ASSERT (Pages != 0);\r
-  Status = CoreFreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);\r
+  Status = CoreFreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, Pages);\r
   ASSERT_EFI_ERROR (Status);\r
 }\r
 \r
@@ -456,6 +466,7 @@ InternalAllocatePool (
   if (EFI_ERROR (Status)) {\r
     Memory = NULL;\r
   }\r
+\r
   return Memory;\r
 }\r
 \r
@@ -482,7 +493,7 @@ AllocatePool (
   Buffer = InternalAllocatePool (EfiBootServicesData, AllocationSize);\r
   if (Buffer != NULL) {\r
     MemoryProfileLibRecord (\r
-      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),\r
+      (PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),\r
       MEMORY_PROFILE_ACTION_LIB_ALLOCATE_POOL,\r
       EfiBootServicesData,\r
       Buffer,\r
@@ -490,6 +501,7 @@ AllocatePool (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -516,7 +528,7 @@ AllocateRuntimePool (
   Buffer = InternalAllocatePool (EfiRuntimeServicesData, AllocationSize);\r
   if (Buffer != NULL) {\r
     MemoryProfileLibRecord (\r
-      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),\r
+      (PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),\r
       MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_POOL,\r
       EfiRuntimeServicesData,\r
       Buffer,\r
@@ -524,6 +536,7 @@ AllocateRuntimePool (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -550,7 +563,7 @@ AllocateReservedPool (
   Buffer = InternalAllocatePool (EfiReservedMemoryType, AllocationSize);\r
   if (Buffer != NULL) {\r
     MemoryProfileLibRecord (\r
-      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),\r
+      (PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),\r
       MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_POOL,\r
       EfiReservedMemoryType,\r
       Buffer,\r
@@ -558,6 +571,7 @@ AllocateReservedPool (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -587,6 +601,7 @@ InternalAllocateZeroPool (
   if (Memory != NULL) {\r
     Memory = ZeroMem (Memory, AllocationSize);\r
   }\r
+\r
   return Memory;\r
 }\r
 \r
@@ -614,7 +629,7 @@ AllocateZeroPool (
   Buffer = InternalAllocateZeroPool (EfiBootServicesData, AllocationSize);\r
   if (Buffer != NULL) {\r
     MemoryProfileLibRecord (\r
-      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),\r
+      (PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),\r
       MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ZERO_POOL,\r
       EfiBootServicesData,\r
       Buffer,\r
@@ -622,6 +637,7 @@ AllocateZeroPool (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -649,7 +665,7 @@ AllocateRuntimeZeroPool (
   Buffer = InternalAllocateZeroPool (EfiRuntimeServicesData, AllocationSize);\r
   if (Buffer != NULL) {\r
     MemoryProfileLibRecord (\r
-      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),\r
+      (PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),\r
       MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_ZERO_POOL,\r
       EfiRuntimeServicesData,\r
       Buffer,\r
@@ -657,6 +673,7 @@ AllocateRuntimeZeroPool (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -684,7 +701,7 @@ AllocateReservedZeroPool (
   Buffer = InternalAllocateZeroPool (EfiReservedMemoryType, AllocationSize);\r
   if (Buffer != NULL) {\r
     MemoryProfileLibRecord (\r
-      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),\r
+      (PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),\r
       MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_ZERO_POOL,\r
       EfiReservedMemoryType,\r
       Buffer,\r
@@ -692,6 +709,7 @@ AllocateReservedZeroPool (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -722,12 +740,13 @@ InternalAllocateCopyPool (
   VOID  *Memory;\r
 \r
   ASSERT (Buffer != NULL);\r
-  ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));\r
+  ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN)Buffer + 1));\r
 \r
   Memory = InternalAllocatePool (PoolType, AllocationSize);\r
   if (Memory != NULL) {\r
-     Memory = CopyMem (Memory, Buffer, AllocationSize);\r
+    Memory = CopyMem (Memory, Buffer, AllocationSize);\r
   }\r
+\r
   return Memory;\r
 }\r
 \r
@@ -760,7 +779,7 @@ AllocateCopyPool (
   NewBuffer = InternalAllocateCopyPool (EfiBootServicesData, AllocationSize, Buffer);\r
   if (NewBuffer != NULL) {\r
     MemoryProfileLibRecord (\r
-      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),\r
+      (PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),\r
       MEMORY_PROFILE_ACTION_LIB_ALLOCATE_COPY_POOL,\r
       EfiBootServicesData,\r
       NewBuffer,\r
@@ -768,6 +787,7 @@ AllocateCopyPool (
       NULL\r
       );\r
   }\r
+\r
   return NewBuffer;\r
 }\r
 \r
@@ -800,7 +820,7 @@ AllocateRuntimeCopyPool (
   NewBuffer = InternalAllocateCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer);\r
   if (NewBuffer != NULL) {\r
     MemoryProfileLibRecord (\r
-      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),\r
+      (PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),\r
       MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_COPY_POOL,\r
       EfiRuntimeServicesData,\r
       NewBuffer,\r
@@ -808,6 +828,7 @@ AllocateRuntimeCopyPool (
       NULL\r
       );\r
   }\r
+\r
   return NewBuffer;\r
 }\r
 \r
@@ -840,7 +861,7 @@ AllocateReservedCopyPool (
   NewBuffer = InternalAllocateCopyPool (EfiReservedMemoryType, AllocationSize, Buffer);\r
   if (NewBuffer != NULL) {\r
     MemoryProfileLibRecord (\r
-      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),\r
+      (PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),\r
       MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_COPY_POOL,\r
       EfiRuntimeServicesData,\r
       NewBuffer,\r
@@ -848,6 +869,7 @@ AllocateReservedCopyPool (
       NULL\r
       );\r
   }\r
+\r
   return NewBuffer;\r
 }\r
 \r
@@ -884,10 +906,11 @@ InternalReallocatePool (
   VOID  *NewBuffer;\r
 \r
   NewBuffer = InternalAllocateZeroPool (PoolType, NewSize);\r
-  if (NewBuffer != NULL && OldBuffer != NULL) {\r
+  if ((NewBuffer != NULL) && (OldBuffer != NULL)) {\r
     CopyMem (NewBuffer, OldBuffer, MIN (OldSize, NewSize));\r
     FreePool (OldBuffer);\r
   }\r
+\r
   return NewBuffer;\r
 }\r
 \r
@@ -925,7 +948,7 @@ ReallocatePool (
   Buffer = InternalReallocatePool (EfiBootServicesData, OldSize, NewSize, OldBuffer);\r
   if (Buffer != NULL) {\r
     MemoryProfileLibRecord (\r
-      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),\r
+      (PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),\r
       MEMORY_PROFILE_ACTION_LIB_REALLOCATE_POOL,\r
       EfiBootServicesData,\r
       Buffer,\r
@@ -933,6 +956,7 @@ ReallocatePool (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -970,7 +994,7 @@ ReallocateRuntimePool (
   Buffer = InternalReallocatePool (EfiRuntimeServicesData, OldSize, NewSize, OldBuffer);\r
   if (Buffer != NULL) {\r
     MemoryProfileLibRecord (\r
-      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),\r
+      (PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),\r
       MEMORY_PROFILE_ACTION_LIB_REALLOCATE_RUNTIME_POOL,\r
       EfiRuntimeServicesData,\r
       Buffer,\r
@@ -978,6 +1002,7 @@ ReallocateRuntimePool (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -1015,7 +1040,7 @@ ReallocateReservedPool (
   Buffer = InternalReallocatePool (EfiReservedMemoryType, OldSize, NewSize, OldBuffer);\r
   if (Buffer != NULL) {\r
     MemoryProfileLibRecord (\r
-      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),\r
+      (PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),\r
       MEMORY_PROFILE_ACTION_LIB_REALLOCATE_RESERVED_POOL,\r
       EfiReservedMemoryType,\r
       Buffer,\r
@@ -1023,6 +1048,7 @@ ReallocateReservedPool (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -1043,12 +1069,11 @@ ReallocateReservedPool (
 VOID\r
 EFIAPI\r
 FreePool (\r
-  IN VOID   *Buffer\r
+  IN VOID  *Buffer\r
   )\r
 {\r
-  EFI_STATUS    Status;\r
+  EFI_STATUS  Status;\r
 \r
   Status = CoreFreePool (Buffer);\r
   ASSERT_EFI_ERROR (Status);\r
 }\r
-\r