]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/UefiMemoryAllocationProfileLib/MemoryAllocationLib.c
MdeModulePkg: Apply uncrustify changes
[mirror_edk2.git] / MdeModulePkg / Library / UefiMemoryAllocationProfileLib / MemoryAllocationLib.c
index ca63df00a2a97375a725b42ddf4888db7a7680c5..38c95b9eb72c305fbe94fd885c2c871bd585fcc3 100644 (file)
@@ -7,10 +7,8 @@
 \r
 **/\r
 \r
-\r
 #include <Uefi.h>\r
 \r
-\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
@@ -48,7 +46,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
@@ -75,7 +74,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
@@ -83,6 +82,7 @@ AllocatePages (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -110,7 +110,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
@@ -118,6 +118,7 @@ AllocateRuntimePages (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -145,7 +146,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
@@ -153,6 +154,7 @@ AllocateReservedPages (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -180,10 +182,10 @@ FreePages (
   IN UINTN  Pages\r
   )\r
 {\r
-  EFI_STATUS        Status;\r
+  EFI_STATUS  Status;\r
 \r
   ASSERT (Pages != 0);\r
-  Status = gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);\r
+  Status = gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, Pages);\r
   ASSERT_EFI_ERROR (Status);\r
 }\r
 \r
@@ -227,23 +229,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         = gBS->AllocatePages (AllocateAnyPages, MemoryType, RealPages, &Memory);\r
+    Status = gBS->AllocatePages (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
@@ -251,6 +255,7 @@ InternalAllocateAlignedPages (
       Status = gBS->FreePages (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
@@ -268,9 +273,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
@@ -303,7 +310,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
@@ -311,6 +318,7 @@ AllocateAlignedPages (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -344,7 +352,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
@@ -352,6 +360,7 @@ AllocateAlignedRuntimePages (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -385,7 +394,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
@@ -393,6 +402,7 @@ AllocateAlignedReservedPages (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -423,7 +433,7 @@ FreeAlignedPages (
   EFI_STATUS  Status;\r
 \r
   ASSERT (Pages != 0);\r
-  Status = gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);\r
+  Status = gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, Pages);\r
   ASSERT_EFI_ERROR (Status);\r
 }\r
 \r
@@ -453,6 +463,7 @@ InternalAllocatePool (
   if (EFI_ERROR (Status)) {\r
     Memory = NULL;\r
   }\r
+\r
   return Memory;\r
 }\r
 \r
@@ -479,7 +490,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
@@ -487,6 +498,7 @@ AllocatePool (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -513,7 +525,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
@@ -521,6 +533,7 @@ AllocateRuntimePool (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -547,7 +560,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
@@ -555,6 +568,7 @@ AllocateReservedPool (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -584,6 +598,7 @@ InternalAllocateZeroPool (
   if (Memory != NULL) {\r
     Memory = ZeroMem (Memory, AllocationSize);\r
   }\r
+\r
   return Memory;\r
 }\r
 \r
@@ -611,7 +626,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
@@ -619,6 +634,7 @@ AllocateZeroPool (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -646,7 +662,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
@@ -654,6 +670,7 @@ AllocateRuntimeZeroPool (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -681,7 +698,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
@@ -689,6 +706,7 @@ AllocateReservedZeroPool (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -719,12 +737,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
@@ -757,7 +776,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
@@ -765,6 +784,7 @@ AllocateCopyPool (
       NULL\r
       );\r
   }\r
+\r
   return NewBuffer;\r
 }\r
 \r
@@ -797,7 +817,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
@@ -805,6 +825,7 @@ AllocateRuntimeCopyPool (
       NULL\r
       );\r
   }\r
+\r
   return NewBuffer;\r
 }\r
 \r
@@ -837,7 +858,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
@@ -845,6 +866,7 @@ AllocateReservedCopyPool (
       NULL\r
       );\r
   }\r
+\r
   return NewBuffer;\r
 }\r
 \r
@@ -881,10 +903,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
@@ -922,7 +945,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
@@ -930,6 +953,7 @@ ReallocatePool (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -967,7 +991,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
@@ -975,6 +999,7 @@ ReallocateRuntimePool (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -1012,7 +1037,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
@@ -1020,6 +1045,7 @@ ReallocateReservedPool (
       NULL\r
       );\r
   }\r
+\r
   return Buffer;\r
 }\r
 \r
@@ -1040,12 +1066,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 = gBS->FreePool (Buffer);\r
   ASSERT_EFI_ERROR (Status);\r
 }\r
-\r