]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
Fix a potential bug that GetLanguages() API may return incorrect languages in a strin...
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / ConfigRouting.c
index 59c2b15109cf1fe31e88d7ae7ac0faec1e0ba620..d55fdf436671511e688f2bbbb6b8ca81d237a800 100644 (file)
@@ -1,4 +1,5 @@
 /** @file\r
+Implementation of interfaces function for EFI_HII_CONFIG_ROUTING_PROTOCOL.\r
 \r
 Copyright (c) 2007 - 2008, Intel Corporation\r
 All rights reserved. This program and the accompanying materials\r
@@ -9,17 +10,6 @@ http://opensource.org/licenses/bsd-license.php
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-Module Name:\r
-\r
-    ConfigRouting.c\r
-\r
-Abstract:\r
-\r
-    Implementation for EFI_HII_CONFIG_ROUTING_PROTOCOL.\r
-\r
-Revision History\r
-\r
-\r
 **/\r
 \r
 \r
@@ -127,193 +117,19 @@ GetDevicePath (
   Length /= 2;\r
   *DevicePath = (UINT8 *) AllocateZeroPool (Length);\r
   if (*DevicePath == NULL) {\r
-    SafeFreePool (DevicePathString);\r
+    FreePool (DevicePathString);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
   HexStringToBufInReverseOrder (*DevicePath, &Length, DevicePathString);\r
 \r
-  SafeFreePool (DevicePathString);\r
+  FreePool (DevicePathString);\r
 \r
   return EFI_SUCCESS;\r
 \r
 }\r
 \r
 \r
-/**\r
-  Extract Storage from all Form Packages in current hii database.\r
-\r
-  This is a internal function.\r
-\r
-  @param  HiiDatabase            EFI_HII_DATABASE_PROTOCOL instance.\r
-  @param  StorageListHead        Storage link List head.\r
-\r
-  @retval EFI_NOT_FOUND          There is no form package in current hii database.\r
-  @retval EFI_INVALID_PARAMETER  Any parameter is invalid.\r
-  @retval EFI_SUCCESS            All existing storage is exported.\r
-\r
-**/\r
-EFI_STATUS\r
-ExportAllStorage (\r
-  IN EFI_HII_DATABASE_PROTOCOL     *HiiDatabase,\r
-  IN OUT LIST_ENTRY                *StorageListHead\r
-)\r
-{\r
-  EFI_STATUS                   Status;\r
-  UINTN                        BufferSize;\r
-  UINTN                        HandleCount;\r
-  EFI_HII_HANDLE               *HandleBuffer;\r
-  UINTN                        Index;\r
-  UINTN                        Index2;\r
-  EFI_HII_PACKAGE_LIST_HEADER  *HiiPackageList;\r
-  EFI_HII_PACKAGE_HEADER       *Package;\r
-  UINT8                        *OpCodeData;\r
-  UINT8                        Operand;\r
-  UINT32                       Offset;\r
-  HII_FORMSET_STORAGE          *Storage;\r
-  EFI_HII_HANDLE               HiiHandle;\r
-  EFI_HANDLE                   DriverHandle;\r
-  CHAR8                        *AsciiString;\r
-  UINT32                       PackageListLength;\r
-  EFI_HII_PACKAGE_HEADER       PackageHeader;\r
-\r
-  //\r
-  // Find the package list which contains Form package.\r
-  //\r
-  BufferSize   = 0;\r
-  HandleBuffer = NULL;\r
-  Status = HiiListPackageLists (\r
-             HiiDatabase,\r
-             EFI_HII_PACKAGE_FORM,\r
-             NULL,\r
-             &BufferSize,\r
-             HandleBuffer\r
-             );\r
-  if (Status == EFI_BUFFER_TOO_SMALL) {\r
-    HandleBuffer = AllocateZeroPool (BufferSize);\r
-    ASSERT (HandleBuffer != NULL);\r
-\r
-    Status = HiiListPackageLists (\r
-               HiiDatabase,\r
-               EFI_HII_PACKAGE_FORM,\r
-               NULL,\r
-               &BufferSize,\r
-               HandleBuffer\r
-               );\r
-  }\r
-  if (EFI_ERROR (Status)) {\r
-    SafeFreePool (HandleBuffer);\r
-    return Status;\r
-  }\r
-\r
-  HandleCount = BufferSize / sizeof (EFI_HII_HANDLE);\r
-  for (Index = 0; Index < HandleCount; Index++) {\r
-    HiiHandle = HandleBuffer[Index];\r
-\r
-    BufferSize     = 0;\r
-    HiiPackageList = NULL;\r
-    Status = HiiExportPackageLists (HiiDatabase, HiiHandle, &BufferSize, HiiPackageList);\r
-    if (Status == EFI_BUFFER_TOO_SMALL) {\r
-      HiiPackageList = AllocateZeroPool (BufferSize);\r
-      ASSERT (HiiPackageList != NULL);\r
-      Status = HiiExportPackageLists (HiiDatabase, HiiHandle, &BufferSize, HiiPackageList);\r
-    }\r
-    if (EFI_ERROR (Status)) {\r
-      SafeFreePool (HandleBuffer);\r
-      SafeFreePool (HiiPackageList);\r
-      return Status;\r
-    }\r
-\r
-    //\r
-    // Get Form package from this HII package List\r
-    //\r
-    Offset  = sizeof (EFI_HII_PACKAGE_LIST_HEADER);\r
-    CopyMem (&PackageListLength, &HiiPackageList->PackageLength, sizeof (UINT32));\r
-    Package = NULL;\r
-    ZeroMem (&PackageHeader, sizeof (EFI_HII_PACKAGE_HEADER));\r
-\r
-    while (Offset < PackageListLength) {\r
-      Package = (EFI_HII_PACKAGE_HEADER *) (((UINT8 *) HiiPackageList) + Offset);\r
-      CopyMem (&PackageHeader, Package, sizeof (EFI_HII_PACKAGE_HEADER));\r
-      if (PackageHeader.Type == EFI_HII_PACKAGE_FORM) {\r
-        break;\r
-      }\r
-      Offset += PackageHeader.Length;\r
-    }\r
-    if (Offset >= PackageListLength) {\r
-      //\r
-      // Error here: No Form package found in this Package List\r
-      //\r
-      ASSERT (FALSE);\r
-    }\r
-\r
-    //\r
-    // Search Storage definition in this Form package\r
-    //\r
-    Offset = sizeof (EFI_HII_PACKAGE_HEADER);\r
-    while (Offset < PackageHeader.Length) {\r
-      OpCodeData = ((UINT8 *) Package) + Offset;\r
-      Offset += ((EFI_IFR_OP_HEADER *) OpCodeData)->Length;\r
-\r
-      Operand = ((EFI_IFR_OP_HEADER *) OpCodeData)->OpCode;\r
-\r
-      if ((Operand == EFI_IFR_VARSTORE_OP) ||\r
-          (Operand == EFI_IFR_VARSTORE_NAME_VALUE_OP) ||\r
-          (Operand == EFI_IFR_VARSTORE_EFI_OP)) {\r
-\r
-        Storage = AllocateZeroPool (sizeof (HII_FORMSET_STORAGE));\r
-        ASSERT (Storage != NULL);\r
-        InsertTailList (StorageListHead, &Storage->Entry);\r
-\r
-        Storage->Signature = HII_FORMSET_STORAGE_SIGNATURE;\r
-        Storage->HiiHandle = HiiHandle;\r
-\r
-        Status = HiiGetPackageListHandle (HiiDatabase, HiiHandle, &DriverHandle);\r
-        if (EFI_ERROR (Status)) {\r
-          SafeFreePool (HandleBuffer);\r
-          SafeFreePool (HiiPackageList);\r
-          SafeFreePool (Storage);\r
-          return Status;\r
-        }\r
-        Storage->DriverHandle = DriverHandle;\r
-\r
-        if (Operand == EFI_IFR_VARSTORE_OP) {\r
-          Storage->Type = EFI_HII_VARSTORE_BUFFER;\r
-\r
-          CopyMem (&Storage->Guid, &((EFI_IFR_VARSTORE *) OpCodeData)->Guid, sizeof (EFI_GUID));\r
-          CopyMem (&Storage->Size, &((EFI_IFR_VARSTORE *) OpCodeData)->Size, sizeof (UINT16));\r
-\r
-          AsciiString = (CHAR8 *) ((EFI_IFR_VARSTORE *) OpCodeData)->Name;\r
-          Storage->Name = AllocateZeroPool (AsciiStrSize (AsciiString) * 2);\r
-          ASSERT (Storage->Name != NULL);\r
-          for (Index2 = 0; AsciiString[Index2] != 0; Index2++) {\r
-            Storage->Name[Index2] = (CHAR16) AsciiString[Index2];\r
-          }\r
-          //\r
-          // Append '\0' to the end of the unicode string.\r
-          //\r
-          Storage->Name[Index2] = 0;\r
-        } else if (Operand == EFI_IFR_VARSTORE_NAME_VALUE_OP) {\r
-          Storage->Type = EFI_HII_VARSTORE_NAME_VALUE;\r
-\r
-          CopyMem (&Storage->Guid, &((EFI_IFR_VARSTORE_NAME_VALUE *) OpCodeData)->Guid, sizeof (EFI_GUID));\r
-        } else if (Operand == EFI_IFR_VARSTORE_EFI_OP) {\r
-          Storage->Type = EFI_HII_VARSTORE_EFI_VARIABLE;\r
-\r
-          CopyMem (&Storage->Guid, &((EFI_IFR_VARSTORE_EFI *) OpCodeData)->Guid, sizeof (EFI_GUID));\r
-        }\r
-      }\r
-    }\r
-\r
-    SafeFreePool (HiiPackageList);\r
-  }\r
-\r
-  SafeFreePool (HandleBuffer);\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
 /**\r
   Generate a sub string then output it.\r
 \r
@@ -444,44 +260,6 @@ OutputConfigBody (
 \r
 }\r
 \r
-\r
-/**\r
-  Adjusts the size of a previously allocated buffer.\r
-\r
-\r
-  @param OldPool         A pointer to the buffer whose size is being adjusted.\r
-  @param OldSize         The size of the current buffer.\r
-  @param NewSize         The size of the new buffer.\r
-\r
-  @return The new buffer allocated.\r
-\r
-**/\r
-VOID *\r
-ReallocatePool (\r
-  IN VOID                          *OldPool,\r
-  IN UINTN                         OldSize,\r
-  IN UINTN                         NewSize\r
-  )\r
-{\r
-  VOID  *NewPool;\r
-\r
-  NewPool = NULL;\r
-  if (NewSize != 0) {\r
-    NewPool = AllocateZeroPool (NewSize);\r
-  }\r
-\r
-  if (OldPool != NULL) {\r
-    if (NewPool != NULL) {\r
-      CopyMem (NewPool, OldPool, OldSize < NewSize ? OldSize : NewSize);\r
-    }\r
-\r
-    gBS->FreePool (OldPool);\r
-  }\r
-\r
-  return NewPool;\r
-}\r
-\r
-\r
 /**\r
   Append a string to a multi-string format.\r
 \r
@@ -520,12 +298,12 @@ AppendToMultiString (
   if (MultiStringSize + AppendStringSize > MAX_STRING_LENGTH ||\r
       MultiStringSize > MAX_STRING_LENGTH) {\r
     *MultiString = (EFI_STRING) ReallocatePool (\r
-                                  (VOID *) (*MultiString),\r
                                   MultiStringSize,\r
-                                  MultiStringSize + AppendStringSize\r
+                                  MultiStringSize + AppendStringSize,\r
+                                  (VOID *) (*MultiString)\r
                                   );\r
+    ASSERT (*MultiString != NULL);\r
   }\r
-\r
   //\r
   // Append the incoming string\r
   //\r
@@ -603,7 +381,9 @@ GetValueOfNumber (
   Status  = EFI_SUCCESS;\r
 \r
 Exit:\r
-  SafeFreePool (Str);\r
+  if (Str != NULL) {\r
+    FreePool (Str);\r
+  }\r
   return Status;\r
 }\r
 \r
@@ -670,17 +450,7 @@ HiiConfigRoutingExtractConfig (
   EFI_HII_CONFIG_ACCESS_PROTOCOL      *ConfigAccess;\r
   EFI_STRING                          AccessProgress;\r
   EFI_STRING                          AccessResults;\r
-  UINTN                               RemainSize;\r
-  EFI_STRING                          TmpPtr;\r
-\r
-  //\r
-  // For size reduction, please define PcdSupportFullConfigRoutingProtocol \r
-  // as FALSE. But this renders the system to not 100% compliant with\r
-  // UEFI 2.1. Use this with caution.\r
-  //\r
-  if (!FeaturePcdGet (PcdSupportFullConfigRoutingProtocol)) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
+  BOOLEAN                             FirstElement;\r
 \r
   if (This == NULL || Progress == NULL || Results == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -703,6 +473,8 @@ HiiConfigRoutingExtractConfig (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  FirstElement = TRUE;\r
+\r
   //\r
   // Allocate a fix length of memory to store Results. Reallocate memory for\r
   // Results if this fix length is insufficient.\r
@@ -738,7 +510,7 @@ HiiConfigRoutingExtractConfig (
     //\r
     Status = GetDevicePath (ConfigRequest, (UINT8 **) &DevicePath);\r
     if (EFI_ERROR (Status)) {\r
-      SafeFreePool (ConfigRequest);\r
+      FreePool (ConfigRequest);\r
       return Status;\r
     }\r
 \r
@@ -765,7 +537,7 @@ HiiConfigRoutingExtractConfig (
       }\r
     }\r
 \r
-    SafeFreePool (DevicePath);\r
+    FreePool (DevicePath);\r
 \r
     if (DriverHandle == NULL) {\r
       //\r
@@ -773,7 +545,7 @@ HiiConfigRoutingExtractConfig (
       // Set Progress to the 'G' in "GUID" of the routing header.\r
       //\r
       *Progress = StringPtr;\r
-      SafeFreePool (ConfigRequest);\r
+      FreePool (ConfigRequest);\r
       return EFI_NOT_FOUND;\r
     }\r
 \r
@@ -798,23 +570,30 @@ HiiConfigRoutingExtractConfig (
       // AccessProgress indicates the parsing progress on <ConfigRequest>.\r
       // Map it to the progress on <MultiConfigRequest> then return it.\r
       //\r
-      RemainSize = StrSize (AccessProgress);\r
-      for (TmpPtr = StringPtr; CompareMem (TmpPtr, AccessProgress, RemainSize) != 0; TmpPtr++);\r
-      *Progress = TmpPtr;\r
-\r
-      SafeFreePool (ConfigRequest);\r
+      *Progress = StrStr (StringPtr, AccessProgress);\r
+      FreePool (ConfigRequest);\r
       return Status;\r
     }\r
 \r
     //\r
-    // Attach this <ConfigAltResp> to a <MultiConfigAltResp>\r
+    // Attach this <ConfigAltResp> to a <MultiConfigAltResp>. There is a '&'\r
+    // which seperates the first <ConfigAltResp> and the following ones.\r
     //\r
     ASSERT (*AccessProgress == 0);\r
+\r
+    if (!FirstElement) {\r
+      Status = AppendToMultiString (Results, L"&");\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
+    \r
     Status = AppendToMultiString (Results, AccessResults);\r
     ASSERT_EFI_ERROR (Status);\r
-    SafeFreePool (AccessResults);\r
+\r
+    FirstElement = FALSE;\r
+    \r
+    FreePool (AccessResults);\r
     AccessResults = NULL;\r
-    SafeFreePool (ConfigRequest);\r
+    FreePool (ConfigRequest);\r
     ConfigRequest = NULL;\r
 \r
     //\r
@@ -865,43 +644,17 @@ HiiConfigRoutingExportConfig (
   )\r
 {\r
   EFI_STATUS                          Status;\r
-  HII_DATABASE_PRIVATE_DATA           *Private;\r
-  LIST_ENTRY                          StorageListHdr;\r
-  HII_FORMSET_STORAGE                 *Storage;\r
-  LIST_ENTRY                          *Link;\r
-  EFI_DEVICE_PATH_PROTOCOL            *DevicePath;\r
-  UINTN                               Length;\r
-  EFI_STRING                          PathHdr;\r
-  UINTN                               PathHdrSize;\r
-  EFI_STRING                          ConfigRequest;\r
-  UINTN                               RequestSize;\r
-  EFI_STRING                          StringPtr;\r
   EFI_HII_CONFIG_ACCESS_PROTOCOL      *ConfigAccess;\r
-  EFI_STRING                          AccessProgress;\r
-  EFI_STRING                          AccessResults;\r
-\r
-  //\r
-  // For size reduction, please define PcdSupportFullConfigRoutingProtocol \r
-  // as FALSE. But this renders the system to not 100% compliant with\r
-  // UEFI 2.1. Use this with caution.\r
-  //\r
-  if (!FeaturePcdGet (PcdSupportFullConfigRoutingProtocol)) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
+  EFI_STRING                          AccessResults;   \r
+  UINTN                               Index;\r
+  EFI_HANDLE                          *ConfigAccessHandles;\r
+  UINTN                               NumberConfigAccessHandles;\r
+  BOOLEAN                             FirstElement;\r
 \r
   if (This == NULL || Results == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  Private = CONFIG_ROUTING_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
-\r
-  InitializeListHead (&StorageListHdr);\r
-\r
-  Status = ExportAllStorage (&Private->HiiDatabase, &StorageListHdr);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
   //\r
   // Allocate a fix length of memory to store Results. Reallocate memory for\r
   // Results if this fix length is insufficient.\r
@@ -911,157 +664,58 @@ HiiConfigRoutingExportConfig (
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  //\r
-  // Parsing all formset storages.\r
-  //\r
-  for (Link = StorageListHdr.ForwardLink; Link != &StorageListHdr; Link = Link->ForwardLink) {\r
-    Storage = CR (Link, HII_FORMSET_STORAGE, Entry, HII_FORMSET_STORAGE_SIGNATURE);\r
-    //\r
-    // Find the corresponding device path instance\r
-    //\r
-    Status = gBS->HandleProtocol (\r
-                    Storage->DriverHandle,\r
-                    &gEfiDevicePathProtocolGuid,\r
-                    (VOID **) &DevicePath\r
-                    );\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\r
-    //\r
-    // Convert the device path binary to hex UNICODE %02x bytes in the same order\r
-    // as the device path resides in RAM memory.\r
-    //\r
-    Length      = GetDevicePathSize (DevicePath);\r
-    PathHdrSize = (Length * 2 + 1) * sizeof (CHAR16);\r
-    PathHdr     = (EFI_STRING) AllocateZeroPool (PathHdrSize);\r
-    if (PathHdr == NULL) {\r
-      return EFI_OUT_OF_RESOURCES;\r
-    }\r
-    Status = BufInReverseOrderToHexString (PathHdr, (UINT8 *) DevicePath, Length);\r
-    ASSERT_EFI_ERROR (Status);\r
-\r
-    //\r
-    // Generate a <ConfigRequest> with one <ConfigHdr> and zero <RequestElement>.\r
-    // It means extract all possible configurations from this specific driver.\r
-    //\r
-    RequestSize = (StrLen (L"GUID=&NAME=&PATH=") + 32) * sizeof (CHAR16) + PathHdrSize;\r
-    if (Storage->Name != NULL) {\r
-      RequestSize += StrLen (Storage->Name) * 4 * sizeof (CHAR16);\r
-    }\r
-    \r
-    ConfigRequest = (EFI_STRING) AllocateZeroPool (RequestSize);\r
-    if (ConfigRequest == NULL) {\r
-      SafeFreePool (PathHdr);\r
-      return EFI_OUT_OF_RESOURCES;\r
-    }\r
-\r
-    //\r
-    // Add <GuidHdr>\r
-    // <GuidHdr> ::= 'GUID='<Guid>\r
-    // Convert <Guid> in the same order as it resides in RAM memory.\r
-    //\r
-    StringPtr = ConfigRequest;\r
-    StrnCpy (StringPtr, L"GUID=", StrLen (L"GUID="));\r
-    StringPtr += StrLen (L"GUID=");\r
-\r
-    Status = BufInReverseOrderToHexString (StringPtr, (UINT8 *) (&Storage->Guid), sizeof (EFI_GUID));\r
-    ASSERT_EFI_ERROR (Status);\r
-    \r
-    StringPtr += 32;\r
-    ASSERT (*StringPtr == 0);\r
-    *StringPtr = L'&';\r
-    StringPtr++;\r
-\r
-    //\r
-    // Add <NameHdr>\r
-    // <NameHdr> ::= 'NAME='<String>\r
-    //\r
-    StrnCpy (StringPtr, L"NAME=", StrLen (L"NAME="));\r
-    StringPtr += StrLen (L"NAME=");\r
-\r
-    if (Storage->Name != NULL) {\r
-      Length = (StrLen (Storage->Name) * 4 + 1) * sizeof (CHAR16);\r
-      Status = UnicodeToConfigString (StringPtr, &Length, Storage->Name);\r
-      ASSERT_EFI_ERROR (Status);\r
-      StringPtr += StrLen (Storage->Name) * 4;\r
-    }\r
-    \r
-    *StringPtr = L'&';\r
-    StringPtr++;\r
-\r
-    //\r
-    // Add <PathHdr>\r
-    // <PathHdr> ::= '<PATH=>'<UEFI binary represented as hex UNICODE %02x>\r
-    //\r
-    StrnCpy (StringPtr, L"PATH=", StrLen (L"PATH="));\r
-    StringPtr += StrLen (L"PATH=");\r
-    StrCpy (StringPtr, PathHdr);\r
+  NumberConfigAccessHandles = 0;\r
+  Status = gBS->LocateHandleBuffer (\r
+             ByProtocol,\r
+             &gEfiHiiConfigAccessProtocolGuid,\r
+             NULL,\r
+             &NumberConfigAccessHandles,\r
+             &ConfigAccessHandles\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
 \r
-    SafeFreePool (PathHdr);\r
-    PathHdr = NULL;\r
+  FirstElement = TRUE;\r
 \r
-    //\r
-    // BUGBUG: The "Implementation note" of ExportConfig() in UEFI spec makes the\r
-    // code somewhat complex. Let's TBD here whether a <ConfigRequest> or a <ConfigHdr>\r
-    // is required to call ConfigAccess.ExtractConfig().\r
-    //\r
-    // Here we use <ConfigHdr> to call ConfigAccess instance. It requires ConfigAccess\r
-    // to handle such kind of "ConfigRequest". It is not supported till now.\r
-    //\r
-    // Either the ExportConfig will be updated or the ConfigAccess.ExtractConfig()\r
-    // will be updated as soon as the decision is made.\r
-\r
-    //\r
-    // Route the request to corresponding ConfigAccess protocol to extract settings.\r
-    //\r
+  for (Index = 0; Index < NumberConfigAccessHandles; Index++) {\r
     Status = gBS->HandleProtocol (\r
-                    Storage->DriverHandle,\r
+                    ConfigAccessHandles[Index],\r
                     &gEfiHiiConfigAccessProtocolGuid,\r
-                    (VOID **)  &ConfigAccess\r
+                    (VOID **) &ConfigAccess\r
                     );\r
-    ASSERT_EFI_ERROR (Status);\r
+    if (EFI_ERROR (Status)) {\r
+      continue;\r
+    }\r
 \r
     Status = ConfigAccess->ExtractConfig (\r
                              ConfigAccess,\r
-                             ConfigRequest,\r
-                             &AccessProgress,\r
+                             NULL,\r
+                             NULL,\r
                              &AccessResults\r
                              );\r
-    if (EFI_ERROR (Status)) {\r
-      SafeFreePool (ConfigRequest);\r
-      SafeFreePool (AccessResults);\r
-      return EFI_INVALID_PARAMETER;\r
-    }\r
-\r
-    //\r
-    // Attach this <ConfigAltResp> to a <MultiConfigAltResp>\r
-    //\r
-    ASSERT (*AccessProgress == 0);\r
-    Status = AppendToMultiString (Results, AccessResults);\r
-    ASSERT_EFI_ERROR (Status);\r
-    SafeFreePool (AccessResults);\r
-    AccessResults = NULL;\r
-    SafeFreePool (ConfigRequest);\r
-    ConfigRequest = NULL;\r
-\r
-  }\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Attach this <ConfigAltResp> to a <MultiConfigAltResp>. There is a '&'\r
+      // which seperates the first <ConfigAltResp> and the following ones.      \r
+      //\r
+      if (!FirstElement) {\r
+        Status = AppendToMultiString (Results, L"&");\r
+        ASSERT_EFI_ERROR (Status);\r
+      }\r
+      \r
+      Status = AppendToMultiString (Results, AccessResults);\r
+      ASSERT_EFI_ERROR (Status);\r
 \r
-  //\r
-  // Free the exported storage resource\r
-  //\r
-  while (!IsListEmpty (&StorageListHdr)) {\r
-    Storage = CR (\r
-                StorageListHdr.ForwardLink,\r
-                HII_FORMSET_STORAGE,\r
-                Entry,\r
-                HII_FORMSET_STORAGE_SIGNATURE\r
-                );\r
-    RemoveEntryList (&Storage->Entry);\r
-    SafeFreePool (Storage->Name);\r
-    SafeFreePool (Storage);\r
+      FirstElement = FALSE;\r
+      \r
+      FreePool (AccessResults);\r
+      AccessResults = NULL;\r
+    }\r
   }\r
+  FreePool (ConfigAccessHandles);\r
 \r
-  return EFI_SUCCESS;\r
+  return EFI_SUCCESS;  \r
 }\r
 \r
 \r
@@ -1111,17 +765,6 @@ HiiConfigRoutingRouteConfig (
   EFI_HANDLE                          DriverHandle;\r
   EFI_HII_CONFIG_ACCESS_PROTOCOL      *ConfigAccess;\r
   EFI_STRING                          AccessProgress;\r
-  UINTN                               RemainSize;\r
-  EFI_STRING                          TmpPtr;\r
-\r
-  //\r
-  // For size reduction, please define PcdSupportFullConfigRoutingProtocol \r
-  // as FALSE. But this renders the system to not 100% compliant with\r
-  // UEFI 2.1. Use this with caution.\r
-  //\r
-  if (!FeaturePcdGet (PcdSupportFullConfigRoutingProtocol)) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
 \r
   if (This == NULL || Progress == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -1173,7 +816,7 @@ HiiConfigRoutingRouteConfig (
     //\r
     Status = GetDevicePath (ConfigResp, (UINT8 **) &DevicePath);\r
     if (EFI_ERROR (Status)) {\r
-      SafeFreePool (ConfigResp);\r
+      FreePool (ConfigResp);\r
       return Status;\r
     }\r
 \r
@@ -1200,7 +843,7 @@ HiiConfigRoutingRouteConfig (
       }\r
     }\r
 \r
-    SafeFreePool (DevicePath);\r
+    FreePool (DevicePath);\r
 \r
     if (DriverHandle == NULL) {\r
       //\r
@@ -1208,7 +851,7 @@ HiiConfigRoutingRouteConfig (
       // Set Progress to the 'G' in "GUID" of the routing header.\r
       //\r
       *Progress = StringPtr;\r
-      SafeFreePool (ConfigResp);\r
+      FreePool (ConfigResp);\r
       return EFI_NOT_FOUND;\r
     }\r
 \r
@@ -1233,15 +876,13 @@ HiiConfigRoutingRouteConfig (
       // AccessProgress indicates the parsing progress on <ConfigResp>.\r
       // Map it to the progress on <MultiConfigResp> then return it.\r
       //\r
-      RemainSize = StrSize (AccessProgress);\r
-      for (TmpPtr = StringPtr; CompareMem (TmpPtr, AccessProgress, RemainSize) != 0; TmpPtr++);\r
-      *Progress = TmpPtr;\r
+      *Progress = StrStr (StringPtr, AccessProgress);\r
 \r
-      SafeFreePool (ConfigResp);\r
+      FreePool (ConfigResp);\r
       return Status;\r
     }\r
 \r
-    SafeFreePool (ConfigResp);\r
+    FreePool (ConfigResp);\r
     ConfigResp = NULL;\r
 \r
     //\r
@@ -1408,7 +1049,7 @@ HiiBlockToConfig (
       TmpBuffer,\r
       (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)\r
       );\r
-    SafeFreePool (TmpBuffer);\r
+    FreePool (TmpBuffer);\r
 \r
     StringPtr += Length;\r
     if (StrnCmp (StringPtr, L"&WIDTH=", StrLen (L"&WIDTH=")) != 0) {\r
@@ -1432,7 +1073,7 @@ HiiBlockToConfig (
       TmpBuffer,\r
       (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)\r
       );\r
-    SafeFreePool (TmpBuffer);\r
+    FreePool (TmpBuffer);\r
 \r
     StringPtr += Length;\r
     if (*StringPtr != 0 && *StringPtr != L'&') {\r
@@ -1471,7 +1112,7 @@ HiiBlockToConfig (
     ASSERT_EFI_ERROR (Status);\r
     ToLower (ValueStr);\r
 \r
-    SafeFreePool (Value);\r
+    FreePool (Value);\r
     Value = NULL;\r
 \r
     //\r
@@ -1493,8 +1134,8 @@ HiiBlockToConfig (
 \r
     AppendToMultiString (Config, ConfigElement);\r
 \r
-    SafeFreePool (ConfigElement);\r
-    SafeFreePool (ValueStr);\r
+    FreePool (ConfigElement);\r
+    FreePool (ValueStr);\r
     ConfigElement = NULL;\r
     ValueStr = NULL;\r
 \r
@@ -1519,11 +1160,16 @@ HiiBlockToConfig (
   return EFI_SUCCESS;\r
 \r
 Exit:\r
-\r
-  SafeFreePool (*Config);\r
-  SafeFreePool (ValueStr);\r
-  SafeFreePool (Value);\r
-  SafeFreePool (ConfigElement);\r
+  FreePool (*Config);\r
+  if (ValueStr != NULL) {\r
+    FreePool (ValueStr);\r
+  }\r
+  if (Value != NULL) {\r
+    FreePool (Value);\r
+  }\r
+  if (ConfigElement != NULL) {\r
+    FreePool (ConfigElement);\r
+  }\r
 \r
   return Status;\r
 \r
@@ -1648,7 +1294,7 @@ HiiConfigToBlock (
     // Get Offset\r
     //\r
     Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
-    if (Status == EFI_OUT_OF_RESOURCES) {\r
+    if (EFI_ERROR (Status)) {\r
       *Progress = ConfigResp;\r
       goto Exit;\r
     }\r
@@ -1658,7 +1304,7 @@ HiiConfigToBlock (
       TmpBuffer,\r
       (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)\r
       );\r
-    SafeFreePool (TmpBuffer);\r
+    FreePool (TmpBuffer);\r
 \r
     StringPtr += Length;\r
     if (StrnCmp (StringPtr, L"&WIDTH=", StrLen (L"&WIDTH=")) != 0) {\r
@@ -1682,7 +1328,7 @@ HiiConfigToBlock (
       TmpBuffer,\r
       (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)\r
       );\r
-    SafeFreePool (TmpBuffer);\r
+    FreePool (TmpBuffer);\r
 \r
     StringPtr += Length;\r
     if (StrnCmp (StringPtr, L"&VALUE=", StrLen (L"&VALUE=")) != 0) {\r
@@ -1696,7 +1342,7 @@ HiiConfigToBlock (
     // Get Value\r
     //\r
     Status = GetValueOfNumber (StringPtr, &Value, &Length);\r
-    if (Status == EFI_OUT_OF_RESOURCES) {\r
+    if (EFI_ERROR (Status)) {\r
       *Progress = ConfigResp;\r
       goto Exit;\r
     }\r
@@ -1719,7 +1365,7 @@ HiiConfigToBlock (
     CopyMem (Block + Offset, Value, Width);\r
     *BlockSize = Offset + Width - 1;\r
 \r
-    SafeFreePool (Value);\r
+    FreePool (Value);\r
     Value = NULL;\r
 \r
     //\r
@@ -1743,7 +1389,9 @@ HiiConfigToBlock (
 \r
 Exit:\r
 \r
-  SafeFreePool (Value);\r
+  if (Value != NULL) {\r
+    FreePool (Value);\r
+  }\r
   return Status;\r
 }\r
 \r
@@ -1815,15 +1463,6 @@ HiiGetAltCfg (
   BOOLEAN                             NameFlag;\r
   BOOLEAN                             PathFlag;\r
 \r
-  //\r
-  // For size reduction, please define PcdSupportFullConfigRoutingProtocol \r
-  // as FALSE. But this renders the system to not 100% compliant with\r
-  // UEFI 2.1. Use this with caution.\r
-  //\r
-  if (!FeaturePcdGet (PcdSupportFullConfigRoutingProtocol)) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
   HdrStart = NULL;\r
   HdrEnd   = NULL;\r
   GuidStr  = NULL;\r
@@ -1968,7 +1607,7 @@ HiiGetAltCfg (
 \r
 Exit:\r
 \r
-  if (!EFI_ERROR (Status)) {\r
+  if (!EFI_ERROR (Status) && (Result != NULL)) {\r
     //\r
     // Copy the <ConfigHdr> and <ConfigBody>\r
     //\r
@@ -1983,11 +1622,21 @@ Exit:
     }\r
   }\r
 \r
-  SafeFreePool (GuidStr);\r
-  SafeFreePool (NameStr);\r
-  SafeFreePool (PathStr);\r
-  SafeFreePool (AltIdStr);\r
-  SafeFreePool (Result);\r
+  if (GuidStr != NULL) {\r
+    FreePool (GuidStr);\r
+  }\r
+  if (NameStr != NULL) {\r
+    FreePool (NameStr);\r
+  }\r
+  if (PathStr != NULL) {\r
+    FreePool (PathStr);\r
+  }\r
+  if (AltIdStr != NULL) {\r
+    FreePool (AltIdStr);\r
+  }\r
+  if (Result != NULL) {\r
+    FreePool (Result);\r
+  }\r
 \r
   return Status;\r
 \r