]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/GenericBdsLib/BdsMisc.c
Add some ASSERT()s.
[mirror_edk2.git] / MdeModulePkg / Library / GenericBdsLib / BdsMisc.c
index 56b9f8537ee0ed0bb0c22d8de0aec61c3e28b30c..5779aec725c66acc9904598d1fedcb88fa4ce62b 100644 (file)
@@ -45,33 +45,22 @@ BdsLibGetTimeout (
   //\r
   Size    = sizeof (UINT16);\r
   Status  = gRT->GetVariable (L"Timeout", &gEfiGlobalVariableGuid, NULL, &Size, &Timeout);\r
-  if (!EFI_ERROR (Status)) {\r
-    return Timeout;\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // According to UEFI 2.0 spec, it should treat the Timeout value as 0xffff\r
+    // (default value PcdPlatformBootTimeOutDefault) when L"Timeout" variable is not present.\r
+    // To make the current EFI Automatic-Test activity possible, platform can choose other value\r
+    // for automatic boot when the variable is not present.\r
+    //\r
+    Timeout = PcdGet16 (PcdPlatformBootTimeOutDefault);\r
   }\r
-  //\r
-  // To make the current EFI Automatic-Test activity possible, just add\r
-  // following code to make AutoBoot enabled when this variable is not\r
-  // present.\r
-  // This code should be removed later.\r
-  //\r
-  Timeout = PcdGet16 (PcdPlatformBootTimeOutDefault);\r
 \r
-  //\r
-  // Notes: Platform should set default variable if non exists on all error cases!!!\r
-  //\r
-  Status = gRT->SetVariable (\r
-                  L"Timeout",\r
-                  &gEfiGlobalVariableGuid,\r
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
-                  sizeof (UINT16),\r
-                  &Timeout\r
-                  );\r
   return Timeout;\r
 }\r
 \r
 /**\r
-  The function will go through the driver optoin link list, load and start\r
-  every driver the driver optoin device path point to.\r
+  The function will go through the driver option link list, load and start\r
+  every driver the driver option device path point to.\r
 \r
   @param  BdsDriverLists        The header of the current driver option link list\r
 \r
@@ -177,7 +166,7 @@ BdsLibLoadDrivers (
 \r
 /**\r
   Get the Option Number that does not used.\r
-  Try to locate the specific option variable one by one untile find a free number.\r
+  Try to locate the specific option variable one by one utile find a free number.\r
 \r
   @param  VariableName          Indicate if the boot#### or driver#### option\r
 \r
@@ -215,7 +204,7 @@ BdsLibGetFreeOptionNumber (
     if (OptionBuffer == NULL) {\r
       break;\r
     }\r
-    Index ++;\r
+    Index++;\r
   } while (TRUE);\r
 \r
   return ((UINT16) Index);\r
@@ -281,7 +270,7 @@ BdsLibRegisterNewOption (
                     &gEfiGlobalVariableGuid,\r
                     &TempOptionSize\r
                     );\r
-\r
+  ASSERT (TempOptionPtr != NULL);\r
   //\r
   // Compare with current option variable\r
   //\r
@@ -315,25 +304,27 @@ BdsLibRegisterNewOption (
         //\r
         // Got the option, so just return\r
         //\r
-        SafeFreePool (OptionPtr);\r
-        SafeFreePool (TempOptionPtr);\r
+        FreePool (OptionPtr);\r
+        FreePool (TempOptionPtr);\r
         return EFI_SUCCESS;\r
       } else {\r
         //\r
         // Option description changed, need update.\r
         //\r
         UpdateDescription = TRUE;\r
-        SafeFreePool (OptionPtr);\r
+        FreePool (OptionPtr);\r
         break;\r
       }\r
     }\r
 \r
-    SafeFreePool (OptionPtr);\r
+    FreePool (OptionPtr);\r
   }\r
 \r
   OptionSize          = sizeof (UINT32) + sizeof (UINT16) + StrSize (String);\r
   OptionSize          += GetDevicePathSize (DevicePath);\r
   OptionPtr           = AllocateZeroPool (OptionSize);\r
+  ASSERT (OptionPtr != NULL);\r
+  \r
   TempPtr             = OptionPtr;\r
   *(UINT32 *) TempPtr = LOAD_OPTION_ACTIVE;\r
   TempPtr             += sizeof (UINT32);\r
@@ -372,12 +363,14 @@ BdsLibRegisterNewOption (
   // Return if only need to update a changed description or fail to set option.\r
   //\r
   if (EFI_ERROR (Status) || UpdateDescription) {\r
-    SafeFreePool (OptionPtr);\r
-    SafeFreePool (TempOptionPtr);\r
+    FreePool (OptionPtr);\r
+    if (TempOptionPtr != NULL) {\r
+      FreePool (TempOptionPtr);\r
+    }\r
     return Status;\r
   }\r
 \r
-  SafeFreePool (OptionPtr);\r
+  FreePool (OptionPtr);\r
 \r
   //\r
   // Update the option order variable\r
@@ -395,7 +388,9 @@ BdsLibRegisterNewOption (
                     sizeof (UINT16),\r
                     &BootOrderEntry\r
                     );\r
-    SafeFreePool (TempOptionPtr);\r
+    if (TempOptionPtr != NULL) {\r
+      FreePool (TempOptionPtr);\r
+    }\r
     return Status;\r
   }\r
 \r
@@ -404,6 +399,8 @@ BdsLibRegisterNewOption (
   //\r
   OrderItemNum = (TempOptionSize / sizeof (UINT16)) + 1 ;\r
   OptionOrderPtr = AllocateZeroPool ( OrderItemNum * sizeof (UINT16));\r
+  ASSERT (OptionOrderPtr!= NULL);\r
+  \r
   CopyMem (OptionOrderPtr, TempOptionPtr, (OrderItemNum - 1) * sizeof (UINT16));\r
 \r
   OptionOrderPtr[Index] = RegisterOptionNumber;\r
@@ -415,8 +412,8 @@ BdsLibRegisterNewOption (
                   OrderItemNum * sizeof (UINT16),\r
                   OptionOrderPtr\r
                   );\r
-  SafeFreePool (TempOptionPtr);\r
-  SafeFreePool (OptionOrderPtr);\r
+  FreePool (TempOptionPtr);\r
+  FreePool (OptionOrderPtr);\r
 \r
   return Status;\r
 }\r
@@ -511,11 +508,16 @@ BdsLibVariableToOption (
 \r
   Option->Signature   = BDS_LOAD_OPTION_SIGNATURE;\r
   Option->DevicePath  = AllocateZeroPool (GetDevicePathSize (DevicePath));\r
+  ASSERT(Option->DevicePath != NULL);\r
   CopyMem (Option->DevicePath, DevicePath, GetDevicePathSize (DevicePath));\r
+\r
   Option->Attribute   = Attribute;\r
   Option->Description = AllocateZeroPool (StrSize (Description));\r
+  ASSERT(Option->Description != NULL);\r
   CopyMem (Option->Description, Description, StrSize (Description));\r
+\r
   Option->LoadOptions = AllocateZeroPool (LoadOptionsSize);\r
+  ASSERT(Option->LoadOptions != NULL);\r
   CopyMem (Option->LoadOptions, LoadOptions, LoadOptionsSize);\r
   Option->LoadOptionsSize = LoadOptionsSize;\r
 \r
@@ -536,12 +538,12 @@ BdsLibVariableToOption (
   //\r
   if ((Option->Attribute & LOAD_OPTION_ACTIVE) == LOAD_OPTION_ACTIVE) {\r
     InsertTailList (BdsCommonOptionList, &Option->Link);\r
-    SafeFreePool (Variable);\r
+    FreePool (Variable);\r
     return Option;\r
   }\r
 \r
-  SafeFreePool (Variable);\r
-  SafeFreePool (Option);\r
+  FreePool (Variable);\r
+  FreePool (Option);\r
   return NULL;\r
 \r
 }\r
@@ -598,11 +600,12 @@ BdsLibBuildOptionFromVar (
     }\r
 \r
     Option              = BdsLibVariableToOption (BdsCommonOptionList, OptionName);\r
+    ASSERT (Option != NULL);\r
     Option->BootCurrent = OptionOrder[Index];\r
 \r
   }\r
 \r
-  SafeFreePool (OptionOrder);\r
+  FreePool (OptionOrder);\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -634,8 +637,8 @@ BdsLibGetBootMode (
   @param  VendorGuid            GUID part of EFI variable name\r
   @param  VariableSize          Returns the size of the EFI variable that was read\r
 \r
-  @return Dynamically allocated memory that contains a copy of the EFI variable.\r
-  @return Caller is responsible freeing the buffer.\r
+  @return                       Dynamically allocated memory that contains a copy of the EFI variable\r
+                                Caller is responsible freeing the buffer.\r
   @retval NULL                  Variable was not read\r
 \r
 **/\r
@@ -727,9 +730,11 @@ BdsLibDelPartMatchInstance (
       //\r
       TempNewDevicePath = NewDevicePath;\r
       NewDevicePath = AppendDevicePathInstance (NewDevicePath, Instance);\r
-      SafeFreePool(TempNewDevicePath);\r
+      if (TempNewDevicePath != NULL) {\r
+        FreePool(TempNewDevicePath);\r
+      }\r
     }\r
-    SafeFreePool(Instance);\r
+    FreePool(Instance);\r
     Instance = GetNextDevicePathInstance (&Multi, &InstanceSize);\r
     InstanceSize  -= END_DEVICE_PATH_LENGTH;\r
   }\r
@@ -746,8 +751,8 @@ BdsLibDelPartMatchInstance (
   @param  Single                A pointer to a single-instance device path data\r
                                 structure.\r
 \r
-  @retval TRUE                  If the Single is contained within Multi\r
-  @retval FALSE                 The Single is not match within Multi\r
+  @retval TRUE                  If the Single device path is contained within Multi device path.\r
+  @retval FALSE                 The Single device path is not match within Multi device path.\r
 \r
 **/\r
 BOOLEAN\r
@@ -761,7 +766,7 @@ BdsLibMatchDevicePaths (
   EFI_DEVICE_PATH_PROTOCOL  *DevicePathInst;\r
   UINTN                     Size;\r
 \r
-  if (Multi != NULL || Single  != NULL) {\r
+  if (Multi == NULL || Single  == NULL) {\r
     return FALSE;\r
   }\r
 \r
@@ -777,11 +782,11 @@ BdsLibMatchDevicePaths (
     // return success\r
     //\r
     if (CompareMem (Single, DevicePathInst, Size) == 0) {\r
-      SafeFreePool (DevicePathInst);\r
+      FreePool (DevicePathInst);\r
       return TRUE;\r
     }\r
 \r
-    SafeFreePool (DevicePathInst);\r
+    FreePool (DevicePathInst);\r
     DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r
   }\r
 \r
@@ -828,7 +833,8 @@ BdsLibOutputStrings (
       break;\r
     }\r
   }\r
-\r
+  \r
+  VA_END(Args);\r
   return Status;\r
 }\r
 \r
@@ -963,8 +969,8 @@ SetupResetReminder (
         IfrLibCreatePopUp (2, &Key, StringBuffer1, StringBuffer2);\r
       } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));\r
 \r
-      SafeFreePool (StringBuffer1);\r
-      SafeFreePool (StringBuffer2);\r
+      FreePool (StringBuffer1);\r
+      FreePool (StringBuffer2);\r
       //\r
       // If the user hits the YES Response key, reset\r
       //\r
@@ -977,12 +983,12 @@ SetupResetReminder (
 }\r
 \r
 /**\r
-  Get the headers (dos, image, optional header) from an image.\r
+  Get the headers (dos, image, optional header) from an image\r
 \r
   @param  Device                SimpleFileSystem device handle\r
   @param  FileName              File name for the image\r
   @param  DosHeader             Pointer to dos header\r
-  @param  Hdr                   Pointer to optional header\r
+  @param  Hdr                   The buffer in which to return the PE32, PE32+, or TE header.\r
 \r
   @retval EFI_SUCCESS           Successfully get the machine type.\r
   @retval EFI_NOT_FOUND         The file is not found.\r
@@ -1025,6 +1031,7 @@ BdsLibGetImageHeader (
                      &Root\r
                      );\r
   if (EFI_ERROR (Status)) {\r
+    Root = NULL;\r
     goto Done;\r
   }\r
 \r
@@ -1053,13 +1060,14 @@ BdsLibGetImageHeader (
       break;\r
     }\r
     if (Status != EFI_BUFFER_TOO_SMALL) {\r
+      FreePool (Info);\r
       goto Done;\r
     }\r
-    SafeFreePool (Info);\r
+    FreePool (Info);\r
   } while (TRUE);\r
 \r
   FileSize = Info->FileSize;\r
-  SafeFreePool (Info);\r
+  FreePool (Info);\r
 \r
   //\r
   // Read dos header\r
@@ -1228,8 +1236,8 @@ BdsSetMemoryTypeInformationVariable (
 }\r
 \r
 /**\r
-  This routine register a function to adjust the different type memory page number just before booting\r
-  and save the updated info into the variable for next boot to use.\r
+  This routine register a function to adjust the different type memory page number\r
+  just before booting and save the updated info into the variable for next boot to use.\r
 \r
 **/\r
 VOID\r