]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/GenericBdsLib/BdsMisc.c
DuplicateDevicePath() function use wrong comment same as AppendDevicePath() function.
[mirror_edk2.git] / MdeModulePkg / Library / GenericBdsLib / BdsMisc.c
index 994f90ed0d81c6e81a8c6d10211b6e902fb0a5ca..acf61ebcb6627a371ee3d466a7bd06fb0ad83743 100644 (file)
@@ -59,8 +59,8 @@ BdsLibGetTimeout (
 }\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
@@ -166,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
@@ -204,7 +204,7 @@ BdsLibGetFreeOptionNumber (
     if (OptionBuffer == NULL) {\r
       break;\r
     }\r
-    Index ++;\r
+    Index++;\r
   } while (TRUE);\r
 \r
   return ((UINT16) Index);\r
@@ -270,11 +270,14 @@ BdsLibRegisterNewOption (
                     &gEfiGlobalVariableGuid,\r
                     &TempOptionSize\r
                     );\r
-\r
   //\r
-  // Compare with current option variable\r
+  // Compare with current option variable if the previous option is set in global variable.\r
   //\r
   for (Index = 0; Index < TempOptionSize / sizeof (UINT16); Index++) {\r
+    //\r
+    // TempOptionPtr must not be NULL if we have non-zero TempOptionSize.\r
+    //\r
+    ASSERT (TempOptionPtr != NULL);\r
 \r
     if (*VariableName == 'B') {\r
       UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", TempOptionPtr[Index]);\r
@@ -336,8 +339,10 @@ BdsLibRegisterNewOption (
 \r
   if (UpdateDescription) {\r
     //\r
-    // The number in option#### to be updated\r
+    // The number in option#### to be updated. \r
+    // In this case, we must have non-NULL TempOptionPtr.\r
     //\r
+    ASSERT (TempOptionPtr != NULL);\r
     RegisterOptionNumber = TempOptionPtr[Index];\r
   } else {\r
     //\r
@@ -364,7 +369,9 @@ BdsLibRegisterNewOption (
   //\r
   if (EFI_ERROR (Status) || UpdateDescription) {\r
     FreePool (OptionPtr);\r
-    FreePool (TempOptionPtr);\r
+    if (TempOptionPtr != NULL) {\r
+      FreePool (TempOptionPtr);\r
+    }\r
     return Status;\r
   }\r
 \r
@@ -386,17 +393,22 @@ BdsLibRegisterNewOption (
                     sizeof (UINT16),\r
                     &BootOrderEntry\r
                     );\r
-    FreePool (TempOptionPtr);\r
+    if (TempOptionPtr != NULL) {\r
+      FreePool (TempOptionPtr);\r
+    }\r
     return Status;\r
   }\r
-\r
+  \r
+  //\r
+  // TempOptionPtr must not be NULL if TempOptionSize is not zero.\r
+  //\r
+  ASSERT (TempOptionPtr != NULL);\r
   //\r
   // Append the new option number to the original option order\r
   //\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
@@ -504,11 +516,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
@@ -591,6 +608,7 @@ BdsLibBuildOptionFromVar (
     }\r
 \r
     Option              = BdsLibVariableToOption (BdsCommonOptionList, OptionName);\r
+    ASSERT (Option != NULL);\r
     Option->BootCurrent = OptionOrder[Index];\r
 \r
   }\r
@@ -627,8 +645,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
@@ -741,8 +759,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
@@ -756,7 +774,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
@@ -823,7 +841,8 @@ BdsLibOutputStrings (
       break;\r
     }\r
   }\r
-\r
+  \r
+  VA_END(Args);\r
   return Status;\r
 }\r
 \r
@@ -972,12 +991,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
@@ -1151,7 +1170,7 @@ BdsSetMemoryTypeInformationVariable (
              &gEfiMemoryTypeInformationGuid,\r
              (VOID **) &CurrentMemoryTypeInformation\r
              );\r
-  if (EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status) || CurrentMemoryTypeInformation == NULL) {\r
     return;\r
   }\r
 \r
@@ -1225,8 +1244,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