]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c
IntelFrameworkModulePkg: Clean up source files
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / DeviceMngr / DeviceManager.c
index 6cb9d6b7ab07de5da771e4f26c430822a03a860e..c4dcf157a5a2d8ede44596823fe6d35bb9704001 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The platform device manager reference implementation\r
 \r
-Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -43,7 +43,7 @@ EFI_STRING  mSelectedMacAddrString;
 //\r
 // Which form Id need to be show.\r
 //\r
-EFI_FORM_ID      mNextShowFormId = DEVICE_MANAGER_FORM_ID;  \r
+EFI_FORM_ID      mNextShowFormId = DEVICE_MANAGER_FORM_ID;\r
 \r
 //\r
 // The Mac Address show in the NETWORK_DEVICE_LIST_FORM_ID\r
@@ -74,7 +74,7 @@ HII_VENDOR_DEVICE_PATH  mDeviceManagerHiiVendorDevicePath = {
   {\r
     END_DEVICE_PATH_TYPE,\r
     END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
-    { \r
+    {\r
       (UINT8) (END_DEVICE_PATH_LENGTH),\r
       (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
     }\r
@@ -96,7 +96,7 @@ HII_VENDOR_DEVICE_PATH  mDriverHealthHiiVendorDevicePath = {
   {\r
     END_DEVICE_PATH_TYPE,\r
       END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
-    { \r
+    {\r
       (UINT8) (END_DEVICE_PATH_LENGTH),\r
         (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
     }\r
@@ -208,8 +208,10 @@ InitializeDeviceManager (
 \r
   @param Handle          The HII handle.\r
   @param SetupClassGuid  The class guid specifies which form set will be displayed.\r
+  @param SkipCount       Skip some formsets which has processed before.\r
   @param FormSetTitle    Formset title string.\r
   @param FormSetHelp     Formset help string.\r
+  @param FormSetGuid     Return the formset guid for this formset.\r
 \r
   @retval  TRUE          The formset for given HII handle will be displayed.\r
   @return  FALSE         The formset for given HII handle will not be displayed.\r
@@ -219,8 +221,10 @@ BOOLEAN
 ExtractDisplayedHiiFormFromHiiHandle (\r
   IN      EFI_HII_HANDLE      Handle,\r
   IN      EFI_GUID            *SetupClassGuid,\r
+  IN      UINTN               SkipCount,\r
   OUT     EFI_STRING_ID       *FormSetTitle,\r
-  OUT     EFI_STRING_ID       *FormSetHelp\r
+  OUT     EFI_STRING_ID       *FormSetHelp,\r
+  OUT     EFI_GUID            **FormSetGuid\r
   )\r
 {\r
   EFI_STATUS                   Status;\r
@@ -236,7 +240,7 @@ ExtractDisplayedHiiFormFromHiiHandle (
   UINT8                        ClassGuidNum;\r
 \r
   ASSERT (Handle != NULL);\r
-  ASSERT (SetupClassGuid != NULL);  \r
+  ASSERT (SetupClassGuid != NULL);\r
   ASSERT (FormSetTitle != NULL);\r
   ASSERT (FormSetHelp != NULL);\r
 \r
@@ -259,7 +263,7 @@ ExtractDisplayedHiiFormFromHiiHandle (
   // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.\r
   //\r
   ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r
-  \r
+\r
   HiiPackageList = AllocatePool (BufferSize);\r
   ASSERT (HiiPackageList != NULL);\r
 \r
@@ -286,8 +290,14 @@ ExtractDisplayedHiiFormFromHiiHandle (
       Offset2 = sizeof (EFI_HII_PACKAGE_HEADER);\r
       while (Offset2 < PackageHeader.Length) {\r
         OpCodeData = Package + Offset2;\r
+        Offset2 += ((EFI_IFR_OP_HEADER *) OpCodeData)->Length;\r
 \r
         if (((EFI_IFR_OP_HEADER *) OpCodeData)->OpCode == EFI_IFR_FORM_SET_OP) {\r
+          if (SkipCount != 0) {\r
+            SkipCount --;\r
+            continue;\r
+          }\r
+\r
           if (((EFI_IFR_OP_HEADER *) OpCodeData)->Length > OFFSET_OF (EFI_IFR_FORM_SET, Flags)) {\r
             //\r
             // Find FormSet OpCode\r
@@ -298,6 +308,8 @@ ExtractDisplayedHiiFormFromHiiHandle (
               if (CompareGuid (SetupClassGuid, ClassGuid)) {\r
                 CopyMem (FormSetTitle, &((EFI_IFR_FORM_SET *) OpCodeData)->FormSetTitle, sizeof (EFI_STRING_ID));\r
                 CopyMem (FormSetHelp, &((EFI_IFR_FORM_SET *) OpCodeData)->Help, sizeof (EFI_STRING_ID));\r
+                *FormSetGuid = AllocateCopyPool (sizeof (EFI_GUID), &((EFI_IFR_FORM_SET *) OpCodeData)->Guid);\r
+                ASSERT (*FormSetGuid != NULL);\r
                 FreePool (HiiPackageList);\r
                 return TRUE;\r
               }\r
@@ -306,18 +318,15 @@ ExtractDisplayedHiiFormFromHiiHandle (
            } else {\r
              CopyMem (FormSetTitle, &((EFI_IFR_FORM_SET *) OpCodeData)->FormSetTitle, sizeof (EFI_STRING_ID));\r
              CopyMem (FormSetHelp, &((EFI_IFR_FORM_SET *) OpCodeData)->Help, sizeof (EFI_STRING_ID));\r
+             *FormSetGuid = AllocateCopyPool (sizeof (EFI_GUID), &((EFI_IFR_FORM_SET *) OpCodeData)->Guid);\r
+             ASSERT (*FormSetGuid != NULL);\r
              FreePool (HiiPackageList);\r
              return TRUE;\r
           }\r
         }\r
-        \r
-        //\r
-        // Go to next opcode\r
-        //\r
-        Offset2 += ((EFI_IFR_OP_HEADER *) OpCodeData)->Length;\r
       }\r
     }\r
-    \r
+\r
     //\r
     // Go to next package\r
     //\r
@@ -332,12 +341,12 @@ ExtractDisplayedHiiFormFromHiiHandle (
 /**\r
   Get the mac address string from the device path.\r
   if the device path has the vlan, get the vanid also.\r
-  \r
-  @param MacAddressNode              Device path begin with mac address \r
+\r
+  @param MacAddressNode              Device path begin with mac address\r
   @param PBuffer                     Output string buffer contain mac address.\r
 \r
 **/\r
-BOOLEAN \r
+BOOLEAN\r
 GetMacAddressString(\r
   IN  MAC_ADDR_DEVICE_PATH   *MacAddressNode,\r
   OUT CHAR16                 **PBuffer\r
@@ -371,20 +380,27 @@ GetMacAddressString(
   }\r
 \r
   *PBuffer = String;\r
-  StrCpy(String, L"MAC:");\r
+  StrCpyS (String, BufferLen / sizeof (CHAR16), L"MAC:");\r
   String += 4;\r
-  \r
+\r
   //\r
   // Convert the MAC address into a unicode string.\r
   //\r
   HwAddress = &MacAddressNode->MacAddress.Addr[0];\r
   for (Index = 0; Index < HwAddressSize; Index++) {\r
-    String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, *(HwAddress++), 2);\r
+    UnicodeValueToStringS (\r
+      String,\r
+      BufferLen - ((UINTN)String - (UINTN)*PBuffer),\r
+      PREFIX_ZERO | RADIX_HEX,\r
+      *(HwAddress++),\r
+      2\r
+      );\r
+    String += StrnLenS (String, (BufferLen - ((UINTN)String - (UINTN)*PBuffer)) / sizeof (CHAR16));\r
     if (Index < HwAddressSize - 1) {\r
       *String++ = L':';\r
     }\r
   }\r
-  \r
+\r
   //\r
   // If VLAN is configured, it will need extra 5 characters like "\0005".\r
   // Plus one unicode character for the null-terminator.\r
@@ -399,7 +415,14 @@ GetMacAddressString(
 \r
   if (VlanId != 0) {\r
     *String++ = L'\\';\r
-    String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, VlanId, 4);\r
+    UnicodeValueToStringS (\r
+      String,\r
+      BufferLen - ((UINTN)String - (UINTN)*PBuffer),\r
+      PREFIX_ZERO | RADIX_HEX,\r
+      VlanId,\r
+      4\r
+      );\r
+    String += StrnLenS (String, (BufferLen - ((UINTN)String - (UINTN)*PBuffer)) / sizeof (CHAR16));\r
   }\r
 \r
   //\r
@@ -419,7 +442,7 @@ GetMacAddressString(
   @retval  EFI_SUCCESS               Add the item is successful.\r
   @return  Other values if failed to Add the item.\r
 **/\r
-BOOLEAN \r
+BOOLEAN\r
 AddIdToMacDeviceList (\r
   IN  EFI_STRING        MacAddrString\r
   )\r
@@ -457,21 +480,21 @@ AddIdToMacDeviceList (
   } else {\r
     mMacDeviceList.MaxListLen += MAX_MAC_ADDRESS_NODE_LIST_LEN;\r
     if (mMacDeviceList.CurListLen != 0) {\r
-      TempDeviceList = (MENU_INFO_ITEM *)AllocateCopyPool (sizeof (MENU_INFO_ITEM) * mMacDeviceList.MaxListLen, (VOID *)mMacDeviceList.NodeList);\r
+      TempDeviceList = ReallocatePool (\r
+                         sizeof (MENU_INFO_ITEM) * mMacDeviceList.CurListLen,\r
+                         sizeof (MENU_INFO_ITEM) * mMacDeviceList.MaxListLen,\r
+                         mMacDeviceList.NodeList\r
+                         );\r
     } else {\r
       TempDeviceList = (MENU_INFO_ITEM *)AllocatePool (sizeof (MENU_INFO_ITEM) * mMacDeviceList.MaxListLen);\r
     }\r
-    \r
+\r
     if (TempDeviceList == NULL) {\r
       return FALSE;\r
     }\r
-    TempDeviceList[mMacDeviceList.CurListLen].PromptId = PromptId;  \r
+    TempDeviceList[mMacDeviceList.CurListLen].PromptId = PromptId;\r
     TempDeviceList[mMacDeviceList.CurListLen].QuestionId = (EFI_QUESTION_ID) (mMacDeviceList.CurListLen + NETWORK_DEVICE_LIST_KEY_OFFSET);\r
-    \r
-    if (mMacDeviceList.CurListLen > 0) {\r
-      FreePool(mMacDeviceList.NodeList);\r
-    }\r
-    \r
+\r
     mMacDeviceList.NodeList = TempDeviceList;\r
   }\r
   mMacDeviceList.CurListLen ++;\r
@@ -488,9 +511,9 @@ AddIdToMacDeviceList (
 \r
   @param    *Node           Input device which need to be check.\r
   @param    *NeedAddItem    Whether need to add the menu in the network device list.\r
-  \r
+\r
   @retval  TRUE             Has mac address device path.\r
-  @retval  FALSE            NOT Has mac address device path.  \r
+  @retval  FALSE            NOT Has mac address device path.\r
 \r
 **/\r
 BOOLEAN\r
@@ -502,7 +525,7 @@ IsMacAddressDevicePath (
   EFI_DEVICE_PATH_PROTOCOL   *DevicePath;\r
   CHAR16                     *Buffer;\r
   BOOLEAN                    ReturnVal;\r
-  \r
+\r
   ASSERT (Node != NULL);\r
   *NeedAddItem = FALSE;\r
   ReturnVal    = FALSE;\r
@@ -517,12 +540,12 @@ IsMacAddressDevicePath (
     if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&\r
        (DevicePathSubType (DevicePath) == MSG_MAC_ADDR_DP)) {\r
       ReturnVal = TRUE;\r
-      \r
+\r
       if (DEVICE_MANAGER_FORM_ID == mNextShowFormId) {\r
         *NeedAddItem = TRUE;\r
         break;\r
-      } \r
-      \r
+      }\r
+\r
       if (!GetMacAddressString((MAC_ADDR_DEVICE_PATH*)DevicePath, &Buffer)) {\r
         break;\r
       }\r
@@ -536,7 +559,7 @@ IsMacAddressDevicePath (
 \r
       if (NETWORK_DEVICE_LIST_FORM_ID == mNextShowFormId) {\r
         //\r
-        // Same handle may has two network child handle, so the questionid \r
+        // Same handle may has two network child handle, so the questionid\r
         // has the offset of SAME_HANDLE_KEY_OFFSET.\r
         //\r
         if (AddIdToMacDeviceList (Buffer)) {\r
@@ -544,7 +567,7 @@ IsMacAddressDevicePath (
         }\r
         break;\r
       }\r
-    } \r
+    }\r
     DevicePath = NextDevicePathNode (DevicePath);\r
   }\r
 \r
@@ -565,7 +588,7 @@ IsMacAddressDevicePath (
   @return  FALSE         Do not need to add the menu about the network.\r
 \r
 **/\r
-BOOLEAN \r
+BOOLEAN\r
 IsNeedAddNetworkMenu (\r
   IN      EFI_HII_HANDLE      Handle,\r
   OUT     UINTN               *ItemCount\r
@@ -573,7 +596,7 @@ IsNeedAddNetworkMenu (
 {\r
   EFI_STATUS     Status;\r
   UINTN          EntryCount;\r
-  UINTN          Index;  \r
+  UINTN          Index;\r
   EFI_HANDLE     DriverHandle;\r
   EFI_HANDLE     ControllerHandle;\r
   EFI_DEVICE_PATH_PROTOCOL   *DevicePath;\r
@@ -602,9 +625,9 @@ IsNeedAddNetworkMenu (
   }\r
   TmpDevicePath = DevicePath;\r
 \r
-  // \r
+  //\r
   // Check whether this device path include mac address device path.\r
-  // If this path has mac address path, get the value whether need \r
+  // If this path has mac address path, get the value whether need\r
   // add this info to the menu and return.\r
   // Else check more about the child handle devcie path.\r
   //\r
@@ -626,7 +649,7 @@ IsNeedAddNetworkMenu (
   }\r
 \r
   if (!IsDevicePathEnd (TmpDevicePath)) {\r
-    return FALSE;    \r
+    return FALSE;\r
   }\r
 \r
   //\r
@@ -665,7 +688,7 @@ IsNeedAddNetworkMenu (
         continue;\r
       }\r
 \r
-      // \r
+      //\r
       // Check whether this device path include mac address device path.\r
       //\r
       if (!IsMacAddressDevicePath(ChildDevicePath, &IsNeedAdd)) {\r
@@ -685,7 +708,7 @@ IsNeedAddNetworkMenu (
         } else {\r
           //\r
           // If need to update other form, return whether need to add to the menu.\r
-          //          \r
+          //\r
           goto Done;\r
         }\r
       }\r
@@ -694,9 +717,74 @@ IsNeedAddNetworkMenu (
 \r
 Done:\r
   if (OpenInfoBuffer != NULL) {\r
-    FreePool (OpenInfoBuffer);  \r
+    FreePool (OpenInfoBuffer);\r
+  }\r
+  return IsNeedAdd;\r
+}\r
+\r
+/**\r
+  Get HiiHandle total number.\r
+\r
+  @param   HiiHandles              The input HiiHandle array.\r
+\r
+  @retval  the Hiihandle count.\r
+\r
+**/\r
+UINTN\r
+GetHiiHandleCount (\r
+  IN EFI_HII_HANDLE              *HiiHandles\r
+  )\r
+{\r
+  UINTN  Index;\r
+\r
+  for (Index = 0; HiiHandles[Index] != NULL; Index++) {\r
   }\r
-  return IsNeedAdd; \r
+\r
+  return Index;\r
+}\r
+\r
+/**\r
+  Insert the new HiiHandle + FormsetGuid at the NewPair[InsertOffset].\r
+\r
+  @param   HiiHandles              The input HiiHandle array.\r
+  @param   GuidLists               The input form set guid lists.\r
+  @param   ArrayCount              The input array count, new array will be arraycount + 1 size.\r
+  @param   Offset                  The current used HiiHandle's Offset.\r
+  @param   FormSetGuid             The new found formset guid.\r
+\r
+**/\r
+VOID\r
+AdjustArrayData (\r
+  IN OUT EFI_HII_HANDLE              **HiiHandles,\r
+  IN OUT EFI_GUID                    ***GuidLists,\r
+  IN     UINTN                       ArrayCount,\r
+  IN     UINTN                       Offset,\r
+  IN     EFI_GUID                    *FormSetGuid\r
+  )\r
+{\r
+  EFI_HII_HANDLE              *NewHiiHandles;\r
+  EFI_GUID                    **NewGuidLists;\r
+\r
+  //\r
+  // +2 means include the new HiiHandle and the last empty NULL pointer.\r
+  //\r
+  NewHiiHandles = AllocateZeroPool ((ArrayCount + 2) * sizeof (EFI_HII_HANDLE));\r
+  ASSERT (NewHiiHandles != NULL);\r
+\r
+  CopyMem (NewHiiHandles, *HiiHandles, Offset * sizeof (EFI_HII_HANDLE));\r
+  NewHiiHandles[Offset] = NewHiiHandles[Offset - 1];\r
+  CopyMem (NewHiiHandles + Offset + 1, *HiiHandles + Offset, (ArrayCount - Offset) * sizeof (EFI_HII_HANDLE));\r
+\r
+  NewGuidLists = AllocateZeroPool ((ArrayCount + 2) * sizeof (EFI_GUID *));\r
+  ASSERT (NewGuidLists != NULL);\r
+\r
+  CopyMem (NewGuidLists, *GuidLists, Offset * sizeof (EFI_GUID *));\r
+  NewGuidLists[Offset] = FormSetGuid;\r
+\r
+  FreePool (*HiiHandles);\r
+  *HiiHandles = NewHiiHandles;\r
+  FreePool (*GuidLists);\r
+  *GuidLists = NewGuidLists;\r
 }\r
 \r
 /**\r
@@ -705,7 +793,7 @@ Done:
 \r
   This function create the dynamic content for device manager. It includes\r
   section header for all class of devices, one-of opcode to set VBIOS.\r
-  \r
+\r
   @retval  EFI_SUCCESS             Operation is successful.\r
   @return  Other values if failed to clean up the dynamic content from HII\r
            database.\r
@@ -736,7 +824,12 @@ CallDeviceManager (
   UINTN                       AddItemCount;\r
   UINTN                       NewStringLen;\r
   EFI_STRING                  NewStringTitle;\r
+  EFI_GUID                    **GuidLists;\r
+  UINTN                       HandleNum;\r
+  UINTN                       SkipCount;\r
+  EFI_GUID                    *FormSetGuid;\r
 \r
+  GuidLists     = NULL;\r
   HiiHandles    = NULL;\r
   Status        = EFI_SUCCESS;\r
   gCallbackKey  = 0;\r
@@ -744,6 +837,8 @@ CallDeviceManager (
   DriverHealthHandles = NULL;\r
   AddNetworkMenu = FALSE;\r
   AddItemCount   = 0;\r
+  SkipCount      = 0;\r
+  FormSetGuid    = NULL;\r
 \r
   //\r
   // Connect all prior to entering the platform setup menu.\r
@@ -788,7 +883,7 @@ CallDeviceManager (
     NewStringLen += (StrLen(String) + 2) * 2;\r
     NewStringTitle = AllocatePool (NewStringLen);\r
     UnicodeSPrint (NewStringTitle, NewStringLen, L"%s %s", String, mSelectedMacAddrString);\r
-    HiiSetString (HiiHandle, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE), NewStringTitle, NULL);    \r
+    HiiSetString (HiiHandle, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE), NewStringTitle, NULL);\r
     FreePool (String);\r
     FreePool (NewStringTitle);\r
   }\r
@@ -825,6 +920,10 @@ CallDeviceManager (
   HiiHandles = HiiGetHiiHandles (NULL);\r
   ASSERT (HiiHandles != NULL);\r
 \r
+  HandleNum = GetHiiHandleCount (HiiHandles);\r
+  GuidLists = AllocateZeroPool ((HandleNum + 1) * sizeof (EFI_GUID *));\r
+  ASSERT (GuidLists != NULL);\r
+\r
   //\r
   // Search for formset of each class type\r
   //\r
@@ -836,10 +935,21 @@ CallDeviceManager (
     //\r
     ASSERT(Index < MAX_KEY_SECTION_LEN);\r
 \r
-    if (!ExtractDisplayedHiiFormFromHiiHandle (HiiHandles[Index], &gEfiHiiPlatformSetupFormsetGuid, &FormSetTitle, &FormSetHelp)) {\r
+    if (!ExtractDisplayedHiiFormFromHiiHandle (HiiHandles[Index], &gEfiHiiPlatformSetupFormsetGuid, SkipCount, &FormSetTitle, &FormSetHelp, &FormSetGuid)) {\r
+      SkipCount = 0;\r
       continue;\r
     }\r
 \r
+    //\r
+    // One HiiHandle has more than one formset can be shown,\r
+    // Insert a new pair of HiiHandle + Guid to the HiiHandles and GuidLists list.\r
+    //\r
+    if (SkipCount > 0) {\r
+      AdjustArrayData (&HiiHandles, &GuidLists, HandleNum, Index + 1, FormSetGuid);\r
+      HandleNum ++;\r
+      Index ++;\r
+    }\r
+\r
     String = HiiGetString (HiiHandles[Index], FormSetTitle, NULL);\r
     if (String == NULL) {\r
       String = HiiGetString (HiiHandle, STR_MISSING_STRING, NULL);\r
@@ -858,7 +968,7 @@ CallDeviceManager (
 \r
     //\r
     // Network device process\r
-    // \r
+    //\r
     if (IsNeedAddNetworkMenu (HiiHandles[Index], &AddItemCount)) {\r
       if (mNextShowFormId == DEVICE_MANAGER_FORM_ID) {\r
         //\r
@@ -905,7 +1015,7 @@ CallDeviceManager (
       }\r
     } else {\r
       //\r
-      // \r
+      //\r
       // Not network device process, only need to show at device manger form.\r
       //\r
       if (mNextShowFormId == DEVICE_MANAGER_FORM_ID) {\r
@@ -919,6 +1029,12 @@ CallDeviceManager (
           );\r
       }\r
     }\r
+\r
+    //\r
+    // Try to find more formset in this HiiHandle.\r
+    //\r
+    SkipCount++;\r
+    Index--;\r
   }\r
 \r
   Status = gBS->LocateHandleBuffer (\r
@@ -994,7 +1110,7 @@ CallDeviceManager (
                              gFormBrowser2,\r
                              &HiiHandles[gCallbackKey - DEVICE_KEY_OFFSET],\r
                              1,\r
-                             NULL,\r
+                             GuidLists[gCallbackKey - DEVICE_KEY_OFFSET],\r
                              0,\r
                              NULL,\r
                              &ActionRequest\r
@@ -1012,7 +1128,7 @@ CallDeviceManager (
   }\r
 \r
   //\r
-  // Driver Health item chose. \r
+  // Driver Health item chose.\r
   //\r
   if (gCallbackKey == DEVICE_MANAGER_KEY_DRIVER_HEALTH) {\r
     CallDriverHealth ();\r
@@ -1036,7 +1152,7 @@ CallDeviceManager (
   // In this case, go from the network device list to the specify device.\r
   //\r
   if ((gCallbackKey < MAX_KEY_SECTION_LEN + NETWORK_DEVICE_LIST_KEY_OFFSET ) && (gCallbackKey >= NETWORK_DEVICE_LIST_KEY_OFFSET)) {\r
-         mNextShowFormId = NETWORK_DEVICE_FORM_ID;\r
+    mNextShowFormId = NETWORK_DEVICE_FORM_ID;\r
     gCallbackKey = FRONT_PAGE_KEY_DEVICE_MANAGER;\r
     goto Done;\r
   }\r
@@ -1062,6 +1178,13 @@ Done:
   HiiFreeOpCodeHandle (EndOpCodeHandle);\r
   FreePool (HiiHandles);\r
 \r
+  for (Index = 0; Index < HandleNum; Index++) {\r
+    if (GuidLists[Index] != NULL) {\r
+      FreePool (GuidLists[Index]);\r
+    }\r
+  }\r
+  FreePool (GuidLists);\r
+\r
   return Status;\r
 }\r
 \r
@@ -1114,10 +1237,10 @@ DriverHealthCallback (
 }\r
 \r
 /**\r
-  Collect and display the platform's driver health relative information, allow user to do interactive \r
+  Collect and display the platform's driver health relative information, allow user to do interactive\r
   operation while the platform is unhealthy.\r
 \r
-  This function display a form which divided into two parts. The one list all modules which has installed \r
+  This function display a form which divided into two parts. The one list all modules which has installed\r
   driver health protocol. The list usually contain driver name, controller name, and it's health info.\r
   While the driver name can't be retrieved, will use device path as backup. The other part of the form provide\r
   a choice to the user to repair all platform.\r
@@ -1128,7 +1251,7 @@ CallDriverHealth (
   VOID\r
   )\r
 {\r
-  EFI_STATUS                  Status; \r
+  EFI_STATUS                  Status;\r
   EFI_HII_HANDLE              HiiHandle;\r
   EFI_BROWSER_ACTION_REQUEST  ActionRequest;\r
   EFI_IFR_GUID_LABEL          *StartLabel;\r
@@ -1151,10 +1274,13 @@ CallDriverHealth (
   LIST_ENTRY                  *Link;\r
   EFI_DEVICE_PATH_PROTOCOL    *DriverDevicePath;\r
   BOOLEAN                     RebootRequired;\r
+  BOOLEAN                     IsControllerNameEmpty;\r
+  UINTN                       StringSize;\r
 \r
   Index               = 0;\r
-  DriverHealthInfo    = NULL;  \r
+  DriverHealthInfo    = NULL;\r
   DriverDevicePath    = NULL;\r
+  IsControllerNameEmpty = FALSE;\r
   InitializeListHead (&DriverHealthList);\r
 \r
   HiiHandle = gDeviceManagerPrivate.DriverHealthHiiHandle;\r
@@ -1226,14 +1352,8 @@ CallDriverHealth (
 \r
   Link = GetFirstNode (&DriverHealthList);\r
 \r
-  while (!IsNull (&DriverHealthList, Link)) {   \r
+  while (!IsNull (&DriverHealthList, Link)) {\r
     DriverHealthInfo = DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link);\r
-    \r
-    //\r
-    // Assume no line strings is longer than 512 bytes.\r
-    //\r
-    String = (EFI_STRING) AllocateZeroPool (0x200);\r
-    ASSERT (String != NULL);\r
 \r
     Status = DriverHealthGetDriverName (DriverHealthInfo->DriverHandle, &DriverName);\r
     if (EFI_ERROR (Status)) {\r
@@ -1243,37 +1363,49 @@ CallDriverHealth (
       DriverDevicePath = DevicePathFromHandle (DriverHealthInfo->DriverHandle);\r
       DriverName       = DevicePathToStr (DriverDevicePath);\r
     }\r
-    //\r
-    // Add the Driver name & Controller name into FormSetTitle string\r
-    // \r
-    StrnCat (String, DriverName, StrLen (DriverName));\r
-\r
+    StringSize = StrSize (DriverName);\r
 \r
     Status = DriverHealthGetControllerName (\r
-               DriverHealthInfo->DriverHandle, \r
-               DriverHealthInfo->ControllerHandle, \r
-               DriverHealthInfo->ChildHandle, \r
+               DriverHealthInfo->DriverHandle,\r
+               DriverHealthInfo->ControllerHandle,\r
+               DriverHealthInfo->ChildHandle,\r
                &ControllerName\r
                );\r
 \r
     if (!EFI_ERROR (Status)) {\r
-      //\r
-      // Can not get the Controller name, just let it empty.\r
-      //\r
-      StrnCat (String, L"    ", StrLen (L"    "));\r
-      StrnCat (String, ControllerName, StrLen (ControllerName));   \r
+      IsControllerNameEmpty = FALSE;\r
+      StringSize += StrLen (L"    ") * sizeof(CHAR16);\r
+      StringSize += StrLen (ControllerName) * sizeof(CHAR16);\r
+    } else {\r
+      IsControllerNameEmpty = TRUE;\r
     }\r
-   \r
+\r
     //\r
     // Add the message of the Module itself provided after the string item.\r
     //\r
     if ((DriverHealthInfo->MessageList != NULL) && (DriverHealthInfo->MessageList->StringId != 0)) {\r
-       StrnCat (String, L"    ", StrLen (L"    "));\r
        TmpString = HiiGetString (\r
-                     DriverHealthInfo->MessageList->HiiHandle, \r
-                     DriverHealthInfo->MessageList->StringId, \r
+                     DriverHealthInfo->MessageList->HiiHandle,\r
+                     DriverHealthInfo->MessageList->StringId,\r
                      NULL\r
                      );\r
+       ASSERT (TmpString != NULL);\r
+\r
+       StringSize += StrLen (L"    ") * sizeof(CHAR16);\r
+       StringSize += StrLen (TmpString) * sizeof(CHAR16);\r
+\r
+       String = (EFI_STRING) AllocateZeroPool (StringSize);\r
+       ASSERT (String != NULL);\r
+\r
+       StrCpyS (String, StringSize / sizeof(CHAR16), DriverName);\r
+       if (!IsControllerNameEmpty) {\r
+        StrCatS (String, StringSize / sizeof(CHAR16), L"    ");\r
+        StrCatS (String, StringSize / sizeof(CHAR16), ControllerName);\r
+       }\r
+\r
+       StrCatS (String, StringSize / sizeof(CHAR16), L"    ");\r
+       StrCatS (String, StringSize / sizeof(CHAR16), TmpString);\r
+\r
     } else {\r
       //\r
       // Update the string will be displayed base on the driver's health status\r
@@ -1298,10 +1430,22 @@ CallDriverHealth (
         TmpString = GetStringById (STRING_TOKEN (STR_DRIVER_HEALTH_HEALTHY));\r
         break;\r
       }\r
+      ASSERT (TmpString != NULL);\r
+\r
+      StringSize += StrLen (TmpString) * sizeof(CHAR16);\r
+\r
+      String = (EFI_STRING) AllocateZeroPool (StringSize);\r
+      ASSERT (String != NULL);\r
+\r
+      StrCpyS (String, StringSize / sizeof (CHAR16), DriverName);\r
+      if (!IsControllerNameEmpty) {\r
+        StrCatS (String, StringSize / sizeof (CHAR16), L"    ");\r
+        StrCatS (String, StringSize / sizeof (CHAR16), ControllerName);\r
+      }\r
+\r
+      StrCatS (String, StringSize / sizeof (CHAR16), TmpString);\r
     }\r
 \r
-    ASSERT (TmpString != NULL);\r
-    StrCat (String, TmpString);\r
     FreePool (TmpString);\r
 \r
     Token = HiiSetString (HiiHandle, 0, String, NULL);\r
@@ -1320,14 +1464,14 @@ CallDriverHealth (
     Index++;\r
     Link = GetNextNode (&DriverHealthList, Link);\r
   }\r
-   \r
+\r
   //\r
   // Add End Opcode for Subtitle\r
-  // \r
+  //\r
   HiiCreateEndOpCode (StartOpCodeHandle);\r
 \r
   HiiCreateSubTitleOpCode (StartOpCodeHandleRepair, STRING_TOKEN (STR_DRIVER_HEALTH_REPAIR_ALL), 0, 0, 1);\r
-  TokenHelp = HiiSetString (HiiHandle, 0, GetStringById( STRING_TOKEN (STR_DH_REPAIR_ALL_HELP)), NULL);  \r
+  TokenHelp = HiiSetString (HiiHandle, 0, GetStringById( STRING_TOKEN (STR_DH_REPAIR_ALL_HELP)), NULL);\r
 \r
   if (PlaformHealthStatusCheck ()) {\r
     //\r
@@ -1397,7 +1541,7 @@ CallDriverHealth (
   // We will have returned from processing a callback - user either hit ESC to exit, or selected\r
   // a target to display.\r
   // Process the diver health status states here.\r
-  // \r
+  //\r
   if (gCallbackKey >= DRIVER_HEALTH_KEY_OFFSET && gCallbackKey != DRIVER_HEALTH_REPAIR_ALL_KEY) {\r
     ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;\r
 \r
@@ -1408,7 +1552,7 @@ CallDriverHealth (
       //\r
       // Got the item relative node in the List\r
       //\r
-      if (Index == (gCallbackKey - DRIVER_HEALTH_KEY_OFFSET)) { \r
+      if (Index == (gCallbackKey - DRIVER_HEALTH_KEY_OFFSET)) {\r
         DriverHealthInfo = DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link);\r
         //\r
         // Process the driver's healthy status for the specify module\r
@@ -1416,7 +1560,7 @@ CallDriverHealth (
         RebootRequired = FALSE;\r
         ProcessSingleControllerHealth (\r
           DriverHealthInfo->DriverHealth,\r
-          DriverHealthInfo->ControllerHandle,      \r
+          DriverHealthInfo->ControllerHandle,\r
           DriverHealthInfo->ChildHandle,\r
           DriverHealthInfo->HealthStatus,\r
           &(DriverHealthInfo->MessageList),\r
@@ -1435,9 +1579,9 @@ CallDriverHealth (
     if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {\r
       EnableResetRequired ();\r
     }\r
-    \r
+\r
     //\r
-    // Force return to the form of Driver Health in Device Manager \r
+    // Force return to the form of Driver Health in Device Manager\r
     //\r
     gCallbackKey = DRIVER_HEALTH_RETURN_KEY;\r
   }\r
@@ -1447,12 +1591,12 @@ CallDriverHealth (
   //\r
   if (gCallbackKey == DRIVER_HEALTH_REPAIR_ALL_KEY) {\r
     ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;\r
-    \r
+\r
     PlatformRepairAll (&DriverHealthList);\r
 \r
     gCallbackKey = DRIVER_HEALTH_RETURN_KEY;\r
   }\r
-   \r
+\r
   //\r
   // Remove driver health packagelist from HII database.\r
   //\r
@@ -1471,13 +1615,13 @@ CallDriverHealth (
     if (DriverHealthInfo->MessageList != NULL) {\r
       FreePool(DriverHealthInfo->MessageList);\r
       FreePool (DriverHealthInfo);\r
-    }   \r
+    }\r
   }\r
 \r
   HiiFreeOpCodeHandle (StartOpCodeHandle);\r
-  HiiFreeOpCodeHandle (EndOpCodeHandle); \r
+  HiiFreeOpCodeHandle (EndOpCodeHandle);\r
   HiiFreeOpCodeHandle (StartOpCodeHandleRepair);\r
-  HiiFreeOpCodeHandle (EndOpCodeHandleRepair); \r
+  HiiFreeOpCodeHandle (EndOpCodeHandleRepair);\r
 \r
   if (gCallbackKey == DRIVER_HEALTH_RETURN_KEY) {\r
     //\r
@@ -1495,11 +1639,11 @@ CallDriverHealth (
   This function called by CheckAllControllersHealthStatus () function in order to process a specify\r
   contoller's health state.\r
 \r
-  @param DriverHealthList   A Pointer to the list contain all of the platform driver health information. \r
+  @param DriverHealthList   A Pointer to the list contain all of the platform driver health information.\r
   @param DriverHandle       The handle of driver.\r
   @param ControllerHandle   The class guid specifies which form set will be displayed.\r
-  @param ChildHandle        The handle of the child controller to retrieve the health \r
-                            status on.  This is an optional parameter that may be NULL. \r
+  @param ChildHandle        The handle of the child controller to retrieve the health\r
+                            status on.  This is an optional parameter that may be NULL.\r
   @param DriverHealth       A pointer to the EFI_DRIVER_HEALTH_PROTOCOL instance.\r
   @param HealthStatus       The health status of the controller.\r
 \r
@@ -1596,7 +1740,7 @@ GetSingleControllerHealthStatus (
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  DriverHealthInfo->Signature          = DEVICE_MANAGER_DRIVER_HEALTH_INFO_SIGNATURE; \r
+  DriverHealthInfo->Signature          = DEVICE_MANAGER_DRIVER_HEALTH_INFO_SIGNATURE;\r
   DriverHealthInfo->DriverHandle       = DriverHandle;\r
   DriverHealthInfo->ControllerHandle   = ControllerHandle;\r
   DriverHealthInfo->ChildHandle        = ChildHandle;\r
@@ -1611,12 +1755,12 @@ GetSingleControllerHealthStatus (
 }\r
 \r
 /**\r
-  Collects all the EFI Driver Health Protocols currently present in the EFI Handle Database, \r
-  and queries each EFI Driver Health Protocol to determine if one or more of the controllers \r
-  managed by each EFI Driver Health Protocol instance are not healthy.  \r
+  Collects all the EFI Driver Health Protocols currently present in the EFI Handle Database,\r
+  and queries each EFI Driver Health Protocol to determine if one or more of the controllers\r
+  managed by each EFI Driver Health Protocol instance are not healthy.\r
 \r
   @param DriverHealthList   A Pointer to the list contain all of the platform driver health\r
-                            information. \r
+                            information.\r
 \r
   @retval    EFI_NOT_FOUND         No controller in the platform install Driver Health Protocol.\r
   @retval    EFI_SUCCESS           All the controllers in the platform are healthy.\r
@@ -1628,7 +1772,7 @@ GetAllControllersHealthStatus (
   IN OUT LIST_ENTRY  *DriverHealthList\r
   )\r
 {\r
-  EFI_STATUS                 Status; \r
+  EFI_STATUS                 Status;\r
   UINTN                      NumHandles;\r
   EFI_HANDLE                 *DriverHealthHandles;\r
   EFI_DRIVER_HEALTH_PROTOCOL *DriverHealth;\r
@@ -1638,7 +1782,7 @@ GetAllControllersHealthStatus (
   UINTN                      HandleCount;\r
   UINTN                      ControllerIndex;\r
   UINTN                      ChildIndex;\r
\r
+\r
   //\r
   // Initialize local variables\r
   //\r
@@ -1666,7 +1810,7 @@ GetAllControllersHealthStatus (
 \r
   if (EFI_ERROR (Status) || DriverHealthHandles == NULL) {\r
     //\r
-    // If the list of Driver Health Protocol handles can not be retrieved, then \r
+    // If the list of Driver Health Protocol handles can not be retrieved, then\r
     // return EFI_OUT_OF_RESOURCES\r
     //\r
     return EFI_OUT_OF_RESOURCES;\r
@@ -1687,7 +1831,7 @@ GetAllControllersHealthStatus (
     //\r
     // Retrieve the Driver Health Protocol from DriverHandle\r
     //\r
-    Status = gBS->HandleProtocol ( \r
+    Status = gBS->HandleProtocol (\r
                     DriverHealthHandles[DriverHealthIndex],\r
                     &gEfiDriverHealthProtocolGuid,\r
                     (VOID **)&DriverHealth\r
@@ -1714,7 +1858,7 @@ GetAllControllersHealthStatus (
     }\r
 \r
     //\r
-    // If all the controllers managed by this Driver Health Protocol are healthy, then skip to the next \r
+    // If all the controllers managed by this Driver Health Protocol are healthy, then skip to the next\r
     // Driver Health Protocol handle\r
     //\r
     if (HealthStatus == EfiDriverHealthStatusHealthy) {\r
@@ -1738,7 +1882,7 @@ GetAllControllersHealthStatus (
         );\r
       if (EFI_ERROR (Status) || Handles == NULL) {\r
         //\r
-        // If all the handles in the handle database can not be retrieved, then \r
+        // If all the handles in the handle database can not be retrieved, then\r
         // return EFI_OUT_OF_RESOURCES\r
         //\r
         Status = EFI_OUT_OF_RESOURCES;\r
@@ -1815,7 +1959,7 @@ Done:
 \r
 \r
 /**\r
-  Check the healthy status of the platform, this function will return immediately while found one driver \r
+  Check the healthy status of the platform, this function will return immediately while found one driver\r
   in the platform are not healthy.\r
 \r
   @retval FALSE      at least one driver in the platform are not healthy.\r
@@ -1858,13 +2002,13 @@ PlaformHealthStatusCheck (
   }\r
   //\r
   // Assume all modules are healthy.\r
-  // \r
+  //\r
   AllHealthy = TRUE;\r
 \r
   //\r
   // Found one or more Handles.\r
   //\r
-  if (!EFI_ERROR (Status)) {    \r
+  if (!EFI_ERROR (Status)) {\r
     for (Index = 0; Index < NoHandles; Index++) {\r
       Status = gBS->HandleProtocol (\r
                       DriverHealthHandles[Index],\r
@@ -1889,7 +2033,7 @@ PlaformHealthStatusCheck (
            //\r
            // Return immediately one driver's status not in healthy.\r
            //\r
-           return FALSE;         \r
+           return FALSE;\r
          }\r
       }\r
     }\r
@@ -1898,20 +2042,20 @@ PlaformHealthStatusCheck (
 }\r
 \r
 /**\r
-  Processes a single controller using the EFI Driver Health Protocol associated with \r
+  Processes a single controller using the EFI Driver Health Protocol associated with\r
   that controller. This algorithm continues to query the GetHealthStatus() service until\r
-  one of the legal terminal states of the EFI Driver Health Protocol is reached. This may \r
+  one of the legal terminal states of the EFI Driver Health Protocol is reached. This may\r
   require the processing of HII Messages, HII Form, and invocation of repair operations.\r
 \r
   @param DriverHealth       A pointer to the EFI_DRIVER_HEALTH_PROTOCOL instance.\r
   @param ControllerHandle   The class guid specifies which form set will be displayed.\r
-  @param ChildHandle        The handle of the child controller to retrieve the health \r
-                            status on.  This is an optional parameter that may be NULL. \r
+  @param ChildHandle        The handle of the child controller to retrieve the health\r
+                            status on.  This is an optional parameter that may be NULL.\r
   @param HealthStatus       The health status of the controller.\r
-  @param MessageList        An array of warning or error messages associated \r
-                            with the controller specified by ControllerHandle and \r
+  @param MessageList        An array of warning or error messages associated\r
+                            with the controller specified by ControllerHandle and\r
                             ChildHandle.  This is an optional parameter that may be NULL.\r
-  @param FormHiiHandle      The HII handle for an HII form associated with the \r
+  @param FormHiiHandle      The HII handle for an HII form associated with the\r
                             controller specified by ControllerHandle and ChildHandle.\r
   @param RebootRequired     Indicate whether a reboot is required to repair the controller.\r
 **/\r
@@ -1928,11 +2072,11 @@ ProcessSingleControllerHealth (
 {\r
   EFI_STATUS                         Status;\r
   EFI_DRIVER_HEALTH_STATUS           LocalHealthStatus;\r
-  \r
+\r
   LocalHealthStatus = HealthStatus;\r
   //\r
   // If the module need to be repaired or reconfiguration,  will process it until\r
-  // reach a terminal status. The status from EfiDriverHealthStatusRepairRequired after repair \r
+  // reach a terminal status. The status from EfiDriverHealthStatusRepairRequired after repair\r
   // will be in (Health, Failed, Configuration Required).\r
   //\r
   while(LocalHealthStatus == EfiDriverHealthStatusConfigurationRequired ||\r
@@ -1943,13 +2087,13 @@ ProcessSingleControllerHealth (
                                DriverHealth,\r
                                ControllerHandle,\r
                                ChildHandle,\r
-                               (EFI_DRIVER_HEALTH_REPAIR_PROGRESS_NOTIFY) RepairNotify\r
+                               RepairNotify\r
                                );\r
     }\r
     //\r
-    // Via a form of the driver need to do configuration provided to process of status in \r
+    // Via a form of the driver need to do configuration provided to process of status in\r
     // EfiDriverHealthStatusConfigurationRequired. The status after configuration should be in\r
-    // (Healthy, Reboot Required, Failed, Reconnect Required, Repair Required).   \r
+    // (Healthy, Reboot Required, Failed, Reconnect Required, Repair Required).\r
     //\r
     if (LocalHealthStatus == EfiDriverHealthStatusConfigurationRequired) {\r
       if (FormHiiHandle != NULL) {\r
@@ -1983,9 +2127,9 @@ ProcessSingleControllerHealth (
 \r
     if (*MessageList != NULL) {\r
       ProcessMessages (*MessageList);\r
-    }  \r
+    }\r
   }\r
-  \r
+\r
   //\r
   // Health status in {Healthy, Failed} may also have Messages need to process\r
   //\r
@@ -2000,7 +2144,7 @@ ProcessSingleControllerHealth (
   if (LocalHealthStatus == EfiDriverHealthStatusRebootRequired) {\r
     *RebootRequired = TRUE;\r
   }\r
-  \r
+\r
   //\r
   // Do reconnect if need.\r
   //\r
@@ -2019,24 +2163,20 @@ ProcessSingleControllerHealth (
 \r
 \r
 /**\r
-  Platform specific notification function for controller repair operations.\r
-\r
-  If the driver for a controller support the Driver Health Protocol and the\r
-  current state of the controller is EfiDriverHealthStatusRepairRequired then\r
-  when the Repair() service of the Driver Health Protocol is called, this \r
-  platform specific notification function can display the progress of the repair\r
-  operation.  Some platforms may choose to not display anything, other may choose\r
-  to show the percentage complete on text consoles, and other may choose to render\r
-  a progress bar on text and graphical consoles.\r
-\r
-  This function displays the percentage of the repair operation that has been\r
-  completed on text consoles.  The percentage is Value / Limit * 100%.\r
-  \r
-  @param  Value               Value in the range 0..Limit the the repair has completed..\r
-  @param  Limit               The maximum value of Value\r
+  Reports the progress of a repair operation.\r
+\r
+  @param[in]  Value             A value between 0 and Limit that identifies the current\r
+                                progress of the repair operation.\r
+\r
+  @param[in]  Limit             The maximum value of Value for the current repair operation.\r
+                                For example, a driver that wants to specify progress in\r
+                                percent would use a Limit value of 100.\r
+\r
+  @retval EFI_SUCCESS           The progress of a repair operation is reported successfully.\r
 \r
 **/\r
-VOID\r
+EFI_STATUS\r
+EFIAPI\r
 RepairNotify (\r
   IN  UINTN Value,\r
   IN  UINTN Limit\r
@@ -2050,13 +2190,14 @@ RepairNotify (
     Percent = Value * 100 / Limit;\r
     Print(L"Repair Progress = %3d%%\n\r", Percent);\r
   }\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
   Processes a set of messages returned by the GetHealthStatus ()\r
   service of the EFI Driver Health Protocol\r
 \r
-  @param    MessageList  The MessageList point to messages need to processed.  \r
+  @param    MessageList  The MessageList point to messages need to processed.\r
 \r
 **/\r
 VOID\r
@@ -2078,9 +2219,9 @@ ProcessMessages (
                         );\r
     if (MessageString != NULL) {\r
       //\r
-      // User can customize the output. Just simply print out the MessageString like below. \r
+      // User can customize the output. Just simply print out the MessageString like below.\r
       // Also can use the HiiHandle to display message on the front page.\r
-      // \r
+      //\r
       // Print(L"%s\n",MessageString);\r
       // gBS->Stall (100000);\r
     }\r
@@ -2092,7 +2233,7 @@ ProcessMessages (
   Repair the whole platform.\r
 \r
   This function is the main entry for user choose "Repair All" in the front page.\r
-  It will try to do recovery job till all the driver health protocol installed modules \r
+  It will try to do recovery job till all the driver health protocol installed modules\r
   reach a terminal state.\r
 \r
   @param DriverHealthList   A Pointer to the list contain all of the platform driver health\r
@@ -2103,7 +2244,7 @@ VOID
 PlatformRepairAll (\r
   IN LIST_ENTRY  *DriverHealthList\r
   )\r
-{ \r
+{\r
   DRIVER_HEALTH_INFO          *DriverHealthInfo;\r
   LIST_ENTRY                  *Link;\r
   BOOLEAN                     RebootRequired;\r
@@ -2122,7 +2263,7 @@ PlatformRepairAll (
     //\r
     ASSERT (DriverHealthInfo != NULL);\r
 \r
-    ProcessSingleControllerHealth ( \r
+    ProcessSingleControllerHealth (\r
       DriverHealthInfo->DriverHealth,\r
       DriverHealthInfo->ControllerHandle,\r
       DriverHealthInfo->ChildHandle,\r
@@ -2140,22 +2281,22 @@ PlatformRepairAll (
 \r
 /**\r
 \r
-  Select the best matching language according to front page policy for best user experience. \r
-  \r
-  This function supports both ISO 639-2 and RFC 4646 language codes, but language \r
-  code types may not be mixed in a single call to this function. \r
+  Select the best matching language according to front page policy for best user experience.\r
+\r
+  This function supports both ISO 639-2 and RFC 4646 language codes, but language\r
+  code types may not be mixed in a single call to this function.\r
 \r
   @param  SupportedLanguages   A pointer to a Null-terminated ASCII string that\r
-                               contains a set of language codes in the format \r
+                               contains a set of language codes in the format\r
                                specified by Iso639Language.\r
   @param  Iso639Language       If TRUE, then all language codes are assumed to be\r
                                in ISO 639-2 format.  If FALSE, then all language\r
                                codes are assumed to be in RFC 4646 language format.\r
 \r
   @retval NULL                 The best matching language could not be found in SupportedLanguages.\r
-  @retval NULL                 There are not enough resources available to return the best matching \r
+  @retval NULL                 There are not enough resources available to return the best matching\r
                                language.\r
-  @retval Other                A pointer to a Null-terminated ASCII string that is the best matching \r
+  @retval Other                A pointer to a Null-terminated ASCII string that is the best matching\r
                                language in SupportedLanguages.\r
 **/\r
 CHAR8 *\r
@@ -2167,7 +2308,7 @@ DriverHealthSelectBestLanguage (
   CHAR8           *LanguageVariable;\r
   CHAR8           *BestLanguage;\r
 \r
-  LanguageVariable =  GetEfiGlobalVariable (Iso639Language ? L"Lang" : L"PlatformLang");\r
+  GetEfiGlobalVariable2 (Iso639Language ? L"Lang" : L"PlatformLang", (VOID**)&LanguageVariable, NULL);\r
 \r
   BestLanguage = GetBestLanguage(\r
                    SupportedLanguages,\r
@@ -2193,7 +2334,7 @@ DriverHealthSelectBestLanguage (
   @param  ProtocolGuid         A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.\r
   @param  DriverBindingHandle  The handle on which the Component Name (2) protocol instance is retrieved.\r
   @param  ComponentName        A pointer to the Component Name (2) protocol interface.\r
-  @param  SupportedLanguage    The best suitable language that matches the SupportedLangues interface for the \r
+  @param  SupportedLanguage    The best suitable language that matches the SupportedLangues interface for the\r
                                located Component Name (2) instance.\r
 \r
   @retval EFI_SUCCESS          The Component Name (2) protocol instance is successfully located and we find\r
@@ -2270,8 +2411,8 @@ GetDriverNameWorker (
   EFI_COMPONENT_NAME_PROTOCOL    *ComponentName;\r
 \r
   //\r
-  // Retrieve Component Name (2) protocol instance on the driver binding handle and \r
-  // find the best language this instance supports. \r
+  // Retrieve Component Name (2) protocol instance on the driver binding handle and\r
+  // find the best language this instance supports.\r
   //\r
   Status = GetComponentNameWorker (\r
              ProtocolGuid,\r
@@ -2282,7 +2423,7 @@ GetDriverNameWorker (
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
\r
+\r
   //\r
   // Get the driver name from Component Name (2) protocol instance on the driver binging handle.\r
   //\r
@@ -2292,7 +2433,7 @@ GetDriverNameWorker (
                             DriverName\r
                             );\r
   FreePool (BestLanguage);\r
\r
+\r
   return Status;\r
 }\r
 \r
@@ -2301,7 +2442,7 @@ GetDriverNameWorker (
   This function gets driver name from Component Name 2 protocol interface and Component Name protocol interface\r
   in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the driver name.\r
   If the attempt fails, it then gets the driver name from EFI 1.1 Component Name protocol for backward\r
-  compatibility support. \r
+  compatibility support.\r
 \r
   @param  DriverBindingHandle  The handle on which the Component Name (2) protocol instance is retrieved.\r
   @param  DriverName           A pointer to the Unicode string to return. This Unicode string is the name\r
@@ -2342,7 +2483,7 @@ DriverHealthGetDriverName (
   This function gets controller name from Component Name 2 protocol interface and Component Name protocol interface\r
   in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the controller name.\r
   If the attempt fails, it then gets the controller name from EFI 1.1 Component Name protocol for backward\r
-  compatibility support. \r
+  compatibility support.\r
 \r
   @param  ProtocolGuid         A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.\r
   @param  DriverBindingHandle  The handle on which the Component Name (2) protocol instance is retrieved.\r
@@ -2375,8 +2516,8 @@ GetControllerNameWorker (
   EFI_COMPONENT_NAME_PROTOCOL    *ComponentName;\r
 \r
   //\r
-  // Retrieve Component Name (2) protocol instance on the driver binding handle and \r
-  // find the best language this instance supports. \r
+  // Retrieve Component Name (2) protocol instance on the driver binding handle and\r
+  // find the best language this instance supports.\r
   //\r
   Status = GetComponentNameWorker (\r
              ProtocolGuid,\r
@@ -2406,9 +2547,9 @@ GetControllerNameWorker (
 /**\r
 \r
   This function gets controller name from Component Name 2 protocol interface and Component Name protocol interface\r
-  in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the controller name. \r
+  in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the controller name.\r
   If the attempt fails, it then gets the controller name from EFI 1.1 Component Name protocol for backward\r
-  compatibility support. \r
+  compatibility support.\r
 \r
   @param  DriverBindingHandle  The handle on which the Component Name (2) protocol instance is retrieved.\r
   @param  ControllerHandle     The handle of a controller that the driver specified by This is managing.\r