]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/BdsDxe/BootMaint/BootOption.c
Remove over specific information from BdsDxe module.
[mirror_edk2.git] / MdeModulePkg / Universal / BdsDxe / BootMaint / BootOption.c
index 8baff7bb4cfe34fd63a33526e95ac866f818c743..85ba61707faa4afa5cec427deeb1b196f6065098 100644 (file)
@@ -24,7 +24,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
   @param MenuType        The Menu type to be created.\r
 \r
-\r
   @retval NULL           If failed to create the menu.\r
   @return                The menu.\r
 \r
@@ -37,6 +36,9 @@ BOpt_CreateMenuEntry (
   BM_MENU_ENTRY *MenuEntry;\r
   UINTN         ContextSize;\r
 \r
+  //\r
+  // Get context size according to menu type\r
+  //\r
   switch (MenuType) {\r
   case BM_LOAD_CONTEXT_SELECT:\r
     ContextSize = sizeof (BM_LOAD_CONTEXT);\r
@@ -65,13 +67,15 @@ BOpt_CreateMenuEntry (
   default:\r
     ContextSize = 0;\r
     break;\r
-\r
   }\r
 \r
-  if (0 == ContextSize) {\r
+  if (ContextSize == 0) {\r
     return NULL;\r
   }\r
 \r
+  //\r
+  // Create new menu entry\r
+  //\r
   MenuEntry = AllocateZeroPool (sizeof (BM_MENU_ENTRY));\r
   if (NULL == MenuEntry) {\r
     return MenuEntry;\r
@@ -79,9 +83,8 @@ BOpt_CreateMenuEntry (
 \r
   MenuEntry->VariableContext = AllocateZeroPool (ContextSize);\r
   if (NULL == MenuEntry->VariableContext) {\r
-    SafeFreePool (MenuEntry);\r
-    MenuEntry = NULL;\r
-    return MenuEntry;\r
+    FreePool (MenuEntry);\r
+    return NULL;\r
   }\r
 \r
   MenuEntry->Signature        = BM_MENU_ENTRY_SIGNATURE;\r
@@ -94,8 +97,6 @@ BOpt_CreateMenuEntry (
 \r
   @param MenuEntry   A pointer to BM_MENU_ENTRY.\r
 \r
-  @retval VOID\r
-\r
 **/\r
 VOID\r
 BOpt_DestroyMenuEntry (\r
@@ -115,59 +116,65 @@ BOpt_DestroyMenuEntry (
   switch (MenuEntry->ContextSelection) {\r
   case BM_LOAD_CONTEXT_SELECT:\r
     LoadContext = (BM_LOAD_CONTEXT *) MenuEntry->VariableContext;\r
-    SafeFreePool (LoadContext->FilePathList);\r
-    SafeFreePool (LoadContext->LoadOption);\r
-    SafeFreePool (LoadContext->OptionalData);\r
-    SafeFreePool (LoadContext);\r
+    FreePool (LoadContext->FilePathList);\r
+    FreePool (LoadContext->LoadOption);\r
+    if (LoadContext->OptionalData != NULL) {\r
+      FreePool (LoadContext->OptionalData);\r
+    }\r
+    FreePool (LoadContext);\r
     break;\r
 \r
   case BM_FILE_CONTEXT_SELECT:\r
     FileContext = (BM_FILE_CONTEXT *) MenuEntry->VariableContext;\r
 \r
     if (!FileContext->IsRoot) {\r
-      SafeFreePool (FileContext->DevicePath);\r
+      FreePool (FileContext->DevicePath);\r
     } else {\r
       if (FileContext->FHandle != NULL) {\r
         FileContext->FHandle->Close (FileContext->FHandle);\r
       }\r
     }\r
 \r
-    SafeFreePool (FileContext->FileName);\r
-    SafeFreePool (FileContext->Info);\r
-    SafeFreePool (FileContext);\r
+    if (FileContext->FileName != NULL) {\r
+      FreePool (FileContext->FileName);\r
+    }\r
+    if (FileContext->Info != NULL) {\r
+      FreePool (FileContext->Info);\r
+    }\r
+    FreePool (FileContext);\r
     break;\r
 \r
   case BM_CONSOLE_CONTEXT_SELECT:\r
     ConsoleContext = (BM_CONSOLE_CONTEXT *) MenuEntry->VariableContext;\r
-    SafeFreePool (ConsoleContext->DevicePath);\r
-    SafeFreePool (ConsoleContext);\r
+    FreePool (ConsoleContext->DevicePath);\r
+    FreePool (ConsoleContext);\r
     break;\r
 \r
   case BM_TERMINAL_CONTEXT_SELECT:\r
     TerminalContext = (BM_TERMINAL_CONTEXT *) MenuEntry->VariableContext;\r
-    SafeFreePool (TerminalContext->DevicePath);\r
-    SafeFreePool (TerminalContext);\r
+    FreePool (TerminalContext->DevicePath);\r
+    FreePool (TerminalContext);\r
     break;\r
 \r
   case BM_HANDLE_CONTEXT_SELECT:\r
     HandleContext = (BM_HANDLE_CONTEXT *) MenuEntry->VariableContext;\r
-    SafeFreePool (HandleContext);\r
+    FreePool (HandleContext);\r
     break;\r
 \r
   case BM_LEGACY_DEV_CONTEXT_SELECT:\r
     LegacyDevContext = (BM_LEGACY_DEVICE_CONTEXT *) MenuEntry->VariableContext;\r
-    SafeFreePool (LegacyDevContext);\r
+    FreePool (LegacyDevContext);\r
 \r
   default:\r
     break;\r
   }\r
 \r
-  SafeFreePool (MenuEntry->DisplayString);\r
+  FreePool (MenuEntry->DisplayString);\r
   if (NULL != MenuEntry->HelpString) {\r
-    SafeFreePool (MenuEntry->HelpString);\r
+    FreePool (MenuEntry->HelpString);\r
   }\r
 \r
-  SafeFreePool (MenuEntry);\r
+  FreePool (MenuEntry);\r
 }\r
 \r
 /**\r
@@ -277,7 +284,7 @@ BOpt_FindFileSystem (
       if (BlkIo->Media->RemovableMedia) {\r
         Buffer = AllocateZeroPool (BlkIo->Media->BlockSize);\r
         if (NULL == Buffer) {\r
-          SafeFreePool (BlkIoHandle);\r
+          FreePool (BlkIoHandle);\r
           return EFI_OUT_OF_RESOURCES;\r
         }\r
 \r
@@ -288,10 +295,10 @@ BOpt_FindFileSystem (
                 BlkIo->Media->BlockSize,\r
                 Buffer\r
                 );\r
-        SafeFreePool (Buffer);\r
+        FreePool (Buffer);\r
       }\r
     }\r
-    SafeFreePool (BlkIoHandle);\r
+    FreePool (BlkIoHandle);\r
   }\r
 \r
   //\r
@@ -331,7 +338,7 @@ BOpt_FindFileSystem (
       //\r
       MenuEntry = BOpt_CreateMenuEntry (BM_FILE_CONTEXT_SELECT);\r
       if (NULL == MenuEntry) {\r
-        SafeFreePool (SimpleFsHandle);\r
+        FreePool (SimpleFsHandle);\r
         return EFI_OUT_OF_RESOURCES;\r
       }\r
 \r
@@ -389,7 +396,7 @@ BOpt_FindFileSystem (
   }\r
 \r
   if (NoSimpleFsHandles != 0) {\r
-    SafeFreePool (SimpleFsHandle);\r
+    FreePool (SimpleFsHandle);\r
   }\r
   //\r
   // Searching for handles that support Load File protocol\r
@@ -406,7 +413,7 @@ BOpt_FindFileSystem (
     for (Index = 0; Index < NoLoadFileHandles; Index++) {\r
       MenuEntry = BOpt_CreateMenuEntry (BM_FILE_CONTEXT_SELECT);\r
       if (NULL == MenuEntry) {\r
-        SafeFreePool (LoadFileHandle);\r
+        FreePool (LoadFileHandle);\r
         return EFI_OUT_OF_RESOURCES;\r
       }\r
 \r
@@ -437,7 +444,7 @@ BOpt_FindFileSystem (
   }\r
 \r
   if (NoLoadFileHandles != 0) {\r
-    SafeFreePool (LoadFileHandle);\r
+    FreePool (LoadFileHandle);\r
   }\r
 \r
   //\r
@@ -501,12 +508,9 @@ BOpt_FindFileSystem (
 }\r
 \r
 /**\r
-  Free resources allocated in Allocate Rountine\r
+  Free resources allocated in Allocate Rountine.\r
 \r
   @param FreeMenu        Menu to be freed\r
-\r
-  @return VOID\r
-\r
 **/\r
 VOID\r
 BOpt_FreeMenu (\r
@@ -531,10 +535,11 @@ BOpt_FreeMenu (
   All files and sub-directories in current directory\r
   will be stored in DirectoryMenu for future use.\r
 \r
-  @param FileOption  Pointer for Dir to explore.\r
+  @param CallbackData  The BMM context data.\r
+  @param MenuEntry     The Menu Entry.\r
 \r
-  @retval TRUE         Get files from current dir successfully.\r
-  @retval FALSE        Can't get files from current dir.\r
+  @retval EFI_SUCCESS         Get files from current dir successfully.\r
+  @return Other value if can't get files from current dir.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -677,15 +682,13 @@ BOpt_FindFiles (
   }\r
 \r
   DirectoryMenu.MenuNumber = OptionNumber;\r
-  SafeFreePool (DirInfo);\r
+  FreePool (DirInfo);\r
   return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
   Build the LegacyFDMenu LegacyHDMenu LegacyCDMenu according to LegacyBios.GetBbsInfo().\r
 \r
-  @param VOID\r
-\r
   @retval EFI_SUCCESS The function complete successfully.\r
   @retval EFI_OUT_OF_RESOURCES No enough memory to complete this function.\r
 \r
@@ -824,10 +827,6 @@ BOpt_GetLegacyOptions (
 /**\r
   Free out resouce allocated from Legacy Boot Options.\r
 \r
-  @param VOID.\r
-\r
-  @return VOID.\r
-\r
 **/\r
 VOID\r
 BOpt_FreeLegacyOptions (\r
@@ -846,7 +845,7 @@ BOpt_FreeLegacyOptions (
   Build the BootOptionMenu according to BootOrder Variable.\r
   This Routine will access the Boot#### to get EFI_LOAD_OPTION.\r
 \r
-  @param None\r
+  @param CallbackData The BMM context data.\r
 \r
   @return The number of the Var Boot####.\r
 \r
@@ -905,7 +904,7 @@ BOpt_GetBootOptions (
 \r
   if (BootNext != NULL) {\r
     if (BootNextSize != sizeof (UINT16)) {\r
-      SafeFreePool (BootNext);\r
+      FreePool (BootNext);\r
       BootNext = NULL;\r
     }\r
   }\r
@@ -930,7 +929,7 @@ BOpt_GetBootOptions (
     }\r
 \r
     CopyMem (LoadOption, LoadOptionFromVar, BootOptionSize);\r
-    SafeFreePool (LoadOptionFromVar);\r
+    FreePool (LoadOptionFromVar);\r
 \r
     if (BootNext != NULL) {\r
       BootNextFlag = (BOOLEAN) (*BootNext == BootOrderList[Index]);\r
@@ -939,7 +938,7 @@ BOpt_GetBootOptions (
     }\r
 \r
     if (0 == (*((UINT32 *) LoadOption) & LOAD_OPTION_ACTIVE)) {\r
-      SafeFreePool (LoadOption);\r
+      FreePool (LoadOption);\r
       continue;\r
     }\r
     //\r
@@ -1061,8 +1060,12 @@ BOpt_GetBootOptions (
     MenuCount++;\r
   }\r
 \r
-  SafeFreePool (BootNext);\r
-  SafeFreePool (BootOrderList);\r
+  if (BootNext != NULL) {\r
+    FreePool (BootNext);\r
+  }\r
+  if (BootOrderList != NULL) {\r
+    FreePool (BootOrderList);\r
+  }\r
   BootOptionMenu.MenuNumber = MenuCount;\r
   return MenuCount;\r
 }\r
@@ -1087,6 +1090,7 @@ BOpt_AppendFileName (
   UINTN   Size1;\r
   UINTN   Size2;\r
   CHAR16  *Str;\r
+  CHAR16  *TmpStr;\r
   CHAR16  *Ptr;\r
   CHAR16  *LastSlash;\r
 \r
@@ -1095,6 +1099,9 @@ BOpt_AppendFileName (
   Str   = AllocateZeroPool (Size1 + Size2 + sizeof (CHAR16));\r
   ASSERT (Str != NULL);\r
 \r
+  TmpStr = AllocateZeroPool (Size1 + Size2 + sizeof (CHAR16)); \r
+  ASSERT (TmpStr != NULL);\r
+\r
   StrCat (Str, Str1);\r
   if (!((*Str == '\\') && (*(Str + 1) == 0))) {\r
     StrCat (Str, L"\\");\r
@@ -1111,13 +1118,25 @@ BOpt_AppendFileName (
       // DO NOT convert the .. if it is at the end of the string. This will\r
       // break the .. behavior in changing directories.\r
       //\r
-      StrCpy (LastSlash, Ptr + 3);\r
+\r
+      //\r
+      // Use TmpStr as a backup, as StrCpy in BaseLib does not handle copy of two strings \r
+      // that overlap.\r
+      //\r
+      StrCpy (TmpStr, Ptr + 3);\r
+      StrCpy (LastSlash, TmpStr);\r
       Ptr = LastSlash;\r
     } else if (*Ptr == '\\' && *(Ptr + 1) == '.' && *(Ptr + 2) == '\\') {\r
       //\r
       // Convert a "\.\" to a "\"\r
       //\r
-      StrCpy (Ptr, Ptr + 2);\r
+\r
+      //\r
+      // Use TmpStr as a backup, as StrCpy in BaseLib does not handle copy of two strings \r
+      // that overlap.\r
+      //\r
+      StrCpy (TmpStr, Ptr + 2);\r
+      StrCpy (Ptr, TmpStr);\r
       Ptr = LastSlash;\r
     } else if (*Ptr == '\\') {\r
       LastSlash = Ptr;\r
@@ -1126,6 +1145,8 @@ BOpt_AppendFileName (
     Ptr++;\r
   }\r
 \r
+  FreePool (TmpStr);\r
+  \r
   return Str;\r
 }\r
 \r
@@ -1242,8 +1263,6 @@ BOpt_IsEfiApp (
   All valid handles in the system except those consume SimpleFs, LoadFile\r
   are stored in DriverMenu for future use.\r
 \r
-  @param VOID \r
-\r
   @retval EFI_SUCCESS The function complets successfully.\r
   @return Other value if failed to build the DriverMenu.\r
 \r
@@ -1309,7 +1328,7 @@ BOpt_FindDrivers (
 \r
     NewMenuEntry = BOpt_CreateMenuEntry (BM_HANDLE_CONTEXT_SELECT);\r
     if (NULL == NewMenuEntry) {\r
-      SafeFreePool (DevicePathHandle);\r
+      FreePool (DevicePathHandle);\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
 \r
@@ -1323,7 +1342,10 @@ BOpt_FindDrivers (
     InsertTailList (&DriverMenu.Head, &NewMenuEntry->Link);\r
 \r
   }\r
-  SafeFreePool (DevicePathHandle);\r
+\r
+  if (DevicePathHandle != NULL) {\r
+    FreePool (DevicePathHandle);\r
+  }\r
 \r
   DriverMenu.MenuNumber = OptionNumber;\r
   return EFI_SUCCESS;\r
@@ -1333,8 +1355,6 @@ BOpt_FindDrivers (
 \r
   Get the Option Number that has not been allocated for use.\r
 \r
-  @param VOID\r
-\r
   @return The available Option Number.\r
 \r
 **/\r
@@ -1409,8 +1429,6 @@ BOpt_GetBootOptionNumber (
 \r
   Get the Option Number that is not in use.\r
 \r
-  @param VOID\r
-\r
   @return The unused Option Number.\r
 \r
 **/\r
@@ -1540,7 +1558,7 @@ BOpt_GetDriverOptions (
     }\r
 \r
     CopyMem (LoadOption, LoadOptionFromVar, DriverOptionSize);\r
-    SafeFreePool (LoadOptionFromVar);\r
+    FreePool (LoadOptionFromVar);\r
 \r
     NewMenuEntry = BOpt_CreateMenuEntry (BM_LOAD_CONTEXT_SELECT);\r
     if (NULL == NewMenuEntry) {\r
@@ -1626,7 +1644,9 @@ BOpt_GetDriverOptions (
 \r
   }\r
 \r
-  SafeFreePool (DriverOrderList);\r
+  if (DriverOrderList != NULL) {\r
+    FreePool (DriverOrderList);\r
+  }\r
   DriverOptionMenu.MenuNumber = Index;\r
   return EFI_SUCCESS;\r
 \r