]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Mem/Pool.c
Fix several code review minor comments:
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Mem / Pool.c
index f0af2b88004493ecf3b4564b283d203aca888955..2764a8ef9ff3f50680c21d9a4b772245bdec5484 100644 (file)
@@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 **/\r
 \r
-#include <DxeMain.h>\r
+#include "DxeMain.h"\r
 \r
 #define POOL_FREE_SIGNATURE   EFI_SIGNATURE_32('p','f','r','0')\r
 typedef struct {\r
@@ -66,15 +66,17 @@ typedef struct {
     EFI_MEMORY_TYPE  MemoryType;\r
     LIST_ENTRY       FreeList[MAX_POOL_LIST];\r
     LIST_ENTRY       Link;\r
-} POOL; \r
-\r
-\r
-POOL            PoolHead[EfiMaxMemoryType];\r
-LIST_ENTRY      PoolHeadList;\r
+} POOL;\r
 \r
 //\r
+// Pool header for each memory type.\r
 //\r
+POOL            mPoolHead[EfiMaxMemoryType];\r
+\r
 //\r
+// List of pool header to search for the appropriate memory type.\r
+//\r
+LIST_ENTRY      mPoolHeadList = INITIALIZE_LIST_HEAD_VARIABLE (mPoolHeadList);\r
 \r
 \r
 /**\r
@@ -90,21 +92,20 @@ CoreInitializePool (
   UINTN  Index;\r
 \r
   for (Type=0; Type < EfiMaxMemoryType; Type++) {\r
-    PoolHead[Type].Signature  = 0;\r
-    PoolHead[Type].Used       = 0;\r
-    PoolHead[Type].MemoryType = (EFI_MEMORY_TYPE) Type;\r
+    mPoolHead[Type].Signature  = 0;\r
+    mPoolHead[Type].Used       = 0;\r
+    mPoolHead[Type].MemoryType = (EFI_MEMORY_TYPE) Type;\r
     for (Index=0; Index < MAX_POOL_LIST; Index++) {\r
-        InitializeListHead (&PoolHead[Type].FreeList[Index]);\r
+        InitializeListHead (&mPoolHead[Type].FreeList[Index]);\r
     }\r
   }\r
-  InitializeListHead (&PoolHeadList);\r
 }\r
 \r
 \r
 /**\r
   Look up pool head for specified memory type.\r
 \r
-  @param  MemoryType             Memory type of which pool head is looked for \r
+  @param  MemoryType             Memory type of which pool head is looked for\r
 \r
   @return Pointer of Corresponding pool head.\r
 \r
@@ -119,12 +120,12 @@ LookupPoolHead (
   UINTN           Index;\r
 \r
   if (MemoryType >= 0 && MemoryType < EfiMaxMemoryType) {\r
-    return &PoolHead[MemoryType];\r
+    return &mPoolHead[MemoryType];\r
   }\r
 \r
   if (MemoryType < 0) {\r
 \r
-    for (Link = PoolHeadList.ForwardLink; Link != &PoolHeadList; Link = Link->ForwardLink) {\r
+    for (Link = mPoolHeadList.ForwardLink; Link != &mPoolHeadList; Link = Link->ForwardLink) {\r
       Pool = CR(Link, POOL, Link, POOL_SIGNATURE);\r
       if (Pool->MemoryType == MemoryType) {\r
         return Pool;\r
@@ -143,7 +144,7 @@ LookupPoolHead (
       InitializeListHead (&Pool->FreeList[Index]);\r
     }\r
 \r
-    InsertHeadList (&PoolHeadList, &Pool->Link);\r
+    InsertHeadList (&mPoolHeadList, &Pool->Link);\r
 \r
     return Pool;\r
   }\r
@@ -151,19 +152,18 @@ LookupPoolHead (
   return NULL;\r
 }\r
 \r
\r
 \r
 \r
 /**\r
   Allocate pool of a particular type.\r
 \r
-  @param  PoolType               Type of pool to allocate \r
-  @param  Size                   The amount of pool to allocate \r
-  @param  Buffer                 The address to return a pointer to the allocated \r
-                                 pool \r
+  @param  PoolType               Type of pool to allocate\r
+  @param  Size                   The amount of pool to allocate\r
+  @param  Buffer                 The address to return a pointer to the allocated\r
+                                 pool\r
 \r
-  @retval EFI_INVALID_PARAMETER  PoolType not valid \r
-  @retval EFI_OUT_OF_RESOURCES   Size exceeds max pool size or allocation failed. \r
+  @retval EFI_INVALID_PARAMETER  PoolType not valid\r
+  @retval EFI_OUT_OF_RESOURCES   Size exceeds max pool size or allocation failed.\r
   @retval EFI_SUCCESS            Pool successfully allocated.\r
 \r
 **/\r
@@ -184,9 +184,9 @@ CoreAllocatePool (
        PoolType == EfiConventionalMemory) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   *Buffer = NULL;\r
-  \r
+\r
   //\r
   // If size is too large, fail it\r
   // Base on the EFI spec, return status of EFI_OUT_OF_RESOURCES\r
@@ -214,8 +214,8 @@ CoreAllocatePool (
   Internal function to allocate pool of a particular type.\r
   Caller must have the memory lock held\r
 \r
-  @param  PoolType               Type of pool to allocate \r
-  @param  Size                   The amount of pool to allocate \r
+  @param  PoolType               Type of pool to allocate\r
+  @param  Size                   The amount of pool to allocate\r
 \r
   @return The allocate pool, or NULL\r
 \r
@@ -235,7 +235,6 @@ CoreAllocatePoolI (
   UINTN       Index;\r
   UINTN       FSize;\r
   UINTN       Offset;\r
-  UINTN       Adjustment;\r
   UINTN       NoPages;\r
 \r
   ASSERT_LOCKED (&gMemoryLock);\r
@@ -243,13 +242,13 @@ CoreAllocatePoolI (
   //\r
   // Adjust the size by the pool header & tail overhead\r
   //\r
-  \r
+\r
   //\r
   // Adjusting the Size to be of proper alignment so that\r
   // we don't get an unaligned access fault later when\r
   // pool_Tail is being initialized\r
   //\r
-  ALIGN_VARIABLE (Size, Adjustment);\r
+  Size = ALIGN_VARIABLE (Size);\r
 \r
   Size += POOL_OVERHEAD;\r
   Index = SIZE_TO_LIST(Size);\r
@@ -292,7 +291,7 @@ CoreAllocatePoolI (
       FSize = LIST_TO_SIZE(Index);\r
 \r
       while (Offset + FSize <= DEFAULT_PAGE_ALLOCATION) {\r
-        Free = (POOL_FREE *) &NewPage[Offset];          \r
+        Free = (POOL_FREE *) &NewPage[Offset];\r
         Free->Signature = POOL_FREE_SIGNATURE;\r
         Free->Index     = (UINT32)Index;\r
         InsertHeadList (&Pool->FreeList[Index], &Free->Link);\r
@@ -318,7 +317,7 @@ Done:
   Buffer = NULL;\r
 \r
   if (Head != NULL) {\r
-    \r
+\r
     //\r
     // If we have a pool buffer, fill in the header & tail info\r
     //\r
@@ -331,14 +330,13 @@ Done:
     Buffer          = Head->Data;\r
     DEBUG_CLEAR_MEMORY (Buffer, Size - POOL_OVERHEAD);\r
 \r
-    DEBUG (\r
-      (DEBUG_POOL,\r
-      "AllocatePoolI: Type %x, Addr %x (len %x) %,d\n",\r
-       PoolType, \r
-       Buffer, \r
-       Size - POOL_OVERHEAD, \r
-      Pool->Used)\r
-      );\r
+    DEBUG ((\r
+      DEBUG_POOL,\r
+      "AllocatePoolI: Type %x, Addr %p (len %lx) %,ld\n", PoolType,\r
+      Buffer,\r
+      (UINT64)(Size - POOL_OVERHEAD),\r
+      (UINT64) Pool->Used\r
+      ));\r
 \r
     //\r
     // Account the allocation\r
@@ -346,21 +344,20 @@ Done:
     Pool->Used += Size;\r
 \r
   } else {\r
-    DEBUG ((DEBUG_ERROR | DEBUG_POOL, "AllocatePool: failed to allocate %d bytes\n", Size));\r
+    DEBUG ((DEBUG_ERROR | DEBUG_POOL, "AllocatePool: failed to allocate %ld bytes\n", (UINT64) Size));\r
   }\r
 \r
   return Buffer;\r
 }\r
-  \r
 \r
 \r
 \r
 /**\r
   Frees pool.\r
 \r
-  @param  Buffer                 The allocated pool entry to free \r
+  @param  Buffer                 The allocated pool entry to free\r
 \r
-  @retval EFI_INVALID_PARAMETER  Buffer is not a valid value. \r
+  @retval EFI_INVALID_PARAMETER  Buffer is not a valid value.\r
   @retval EFI_SUCCESS            Pool successfully freed.\r
 \r
 **/\r
@@ -372,7 +369,7 @@ CoreFreePool (
 {\r
   EFI_STATUS Status;\r
 \r
-  if (NULL == Buffer) {\r
+  if (Buffer == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -388,9 +385,9 @@ CoreFreePool (
   Internal function to free a pool entry.\r
   Caller must have the memory lock held\r
 \r
-  @param  Buffer                 The allocated pool entry to free \r
+  @param  Buffer                 The allocated pool entry to free\r
 \r
-  @retval EFI_INVALID_PARAMETER  Buffer not valid \r
+  @retval EFI_INVALID_PARAMETER  Buffer not valid\r
   @retval EFI_SUCCESS            Buffer successfully freed.\r
 \r
 **/\r
@@ -411,19 +408,19 @@ CoreFreePoolI (
   UINTN       Offset;\r
   BOOLEAN     AllFree;\r
 \r
-  ASSERT(NULL != Buffer);\r
+  ASSERT(Buffer != NULL);\r
   //\r
   // Get the head & tail of the pool entry\r
   //\r
   Head = CR (Buffer, POOL_HEAD, Data, POOL_HEAD_SIGNATURE);\r
-  ASSERT(NULL != Head);\r
+  ASSERT(Head != NULL);\r
 \r
   if (Head->Signature != POOL_HEAD_SIGNATURE) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   Tail = HEAD_TO_TAIL (Head);\r
-  ASSERT(NULL != Tail);\r
+  ASSERT(Tail != NULL);\r
 \r
   //\r
   // Debug\r
@@ -449,10 +446,10 @@ CoreFreePoolI (
     return EFI_INVALID_PARAMETER;\r
   }\r
   Pool->Used -= Size;\r
-  DEBUG ((DEBUG_POOL, "FreePool: %x (len %x) %,d\n", Head->Data, Head->Size - POOL_OVERHEAD, Pool->Used));\r
+  DEBUG ((DEBUG_POOL, "FreePool: %p (len %lx) %,ld\n", Head->Data, (UINT64)(Head->Size - POOL_OVERHEAD), (UINT64) Pool->Used));\r
 \r
   //\r
-  // Determine the pool list \r
+  // Determine the pool list\r
   //\r
   Index = SIZE_TO_LIST(Size);\r
   DEBUG_CLEAR_MEMORY (Head, Size);\r
@@ -475,18 +472,18 @@ CoreFreePoolI (
     // Put the pool entry onto the free pool list\r
     //\r
     Free = (POOL_FREE *) Head;\r
-    ASSERT(NULL != Free);\r
+    ASSERT(Free != NULL);\r
     Free->Signature = POOL_FREE_SIGNATURE;\r
     Free->Index     = (UINT32)Index;\r
     InsertHeadList (&Pool->FreeList[Index], &Free->Link);\r
 \r
     //\r
-    // See if all the pool entries in the same page as Free are freed pool \r
+    // See if all the pool entries in the same page as Free are freed pool\r
     // entries\r
     //\r
     NewPage = (CHAR8 *)((UINTN)Free & ~((DEFAULT_PAGE_ALLOCATION) -1));\r
     Free = (POOL_FREE *) &NewPage[0];\r
-    ASSERT(NULL != Free);\r
+    ASSERT(Free != NULL);\r
 \r
     if (Free->Signature == POOL_FREE_SIGNATURE) {\r
 \r
@@ -494,12 +491,12 @@ CoreFreePoolI (
 \r
       AllFree = TRUE;\r
       Offset = 0;\r
-      \r
+\r
       while ((Offset < DEFAULT_PAGE_ALLOCATION) && (AllFree)) {\r
         FSize = LIST_TO_SIZE(Index);\r
         while (Offset + FSize <= DEFAULT_PAGE_ALLOCATION) {\r
           Free = (POOL_FREE *) &NewPage[Offset];\r
-          ASSERT(NULL != Free);\r
+          ASSERT(Free != NULL);\r
           if (Free->Signature != POOL_FREE_SIGNATURE) {\r
             AllFree = FALSE;\r
           }\r
@@ -511,20 +508,20 @@ CoreFreePoolI (
       if (AllFree) {\r
 \r
         //\r
-        // All of the pool entries in the same page as Free are free pool \r
+        // All of the pool entries in the same page as Free are free pool\r
         // entries\r
         // Remove all of these pool entries from the free loop lists.\r
         //\r
         Free = (POOL_FREE *) &NewPage[0];\r
-        ASSERT(NULL != Free);\r
+        ASSERT(Free != NULL);\r
         Index = Free->Index;\r
         Offset = 0;\r
-        \r
+\r
         while (Offset < DEFAULT_PAGE_ALLOCATION) {\r
           FSize = LIST_TO_SIZE(Index);\r
           while (Offset + FSize <= DEFAULT_PAGE_ALLOCATION) {\r
             Free = (POOL_FREE *) &NewPage[Offset];\r
-            ASSERT(NULL != Free);\r
+            ASSERT(Free != NULL);\r
             RemoveEntryList (&Free->Link);\r
             Offset += FSize;\r
           }\r
@@ -540,7 +537,7 @@ CoreFreePoolI (
   }\r
 \r
   //\r
-  // If this is an OS specific memory type, then check to see if the last \r
+  // If this is an OS specific memory type, then check to see if the last\r
   // portion of that memory type has been freed.  If it has, then free the\r
   // list entry for that memory type\r
   //\r