]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
Remove SafeFreePool from MemoryAllocationLib as this API's name is misleading. Its...
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / ConfigRouting.c
index d7ae31057370135f9676dce8bcf1cad8dff5fc9b..aed93be1f03f7e2c0db37f5e9025d5d9aee27c76 100644 (file)
@@ -25,8 +25,6 @@ Revision History
 \r
 #include "HiiDatabase.h"\r
 \r
-#ifndef _DISABLE_UNUSED_HII_PROTOCOLS_\r
-\r
 /**\r
   Calculate the number of Unicode characters of the incoming Configuration string,\r
   not including NULL terminator.\r
@@ -129,13 +127,13 @@ 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
-  HexStringToBuffer (*DevicePath, &Length, DevicePathString);\r
+  HexStringToBufInReverseOrder (*DevicePath, &Length, DevicePathString);\r
 \r
-  SafeFreePool (DevicePathString);\r
+  FreePool (DevicePathString);\r
 \r
   return EFI_SUCCESS;\r
 \r
@@ -204,7 +202,9 @@ ExportAllStorage (
                );\r
   }\r
   if (EFI_ERROR (Status)) {\r
-    SafeFreePool (HandleBuffer);\r
+    if (HandleBuffer != NULL) {\r
+      FreePool (HandleBuffer);\r
+    }\r
     return Status;\r
   }\r
 \r
@@ -221,8 +221,8 @@ ExportAllStorage (
       Status = HiiExportPackageLists (HiiDatabase, HiiHandle, &BufferSize, HiiPackageList);\r
     }\r
     if (EFI_ERROR (Status)) {\r
-      SafeFreePool (HandleBuffer);\r
-      SafeFreePool (HiiPackageList);\r
+      FreePool (HandleBuffer);\r
+      FreePool (HiiPackageList);\r
       return Status;\r
     }\r
 \r
@@ -272,9 +272,9 @@ ExportAllStorage (
 \r
         Status = HiiGetPackageListHandle (HiiDatabase, HiiHandle, &DriverHandle);\r
         if (EFI_ERROR (Status)) {\r
-          SafeFreePool (HandleBuffer);\r
-          SafeFreePool (HiiPackageList);\r
-          SafeFreePool (Storage);\r
+          FreePool (HandleBuffer);\r
+          FreePool (HiiPackageList);\r
+          FreePool (Storage);\r
           return Status;\r
         }\r
         Storage->DriverHandle = DriverHandle;\r
@@ -307,10 +307,10 @@ ExportAllStorage (
       }\r
     }\r
 \r
-    SafeFreePool (HiiPackageList);\r
+    FreePool (HiiPackageList);\r
   }\r
 \r
-  SafeFreePool (HandleBuffer);\r
+  FreePool (HandleBuffer);\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -368,7 +368,7 @@ GenerateSubStr (
 \r
   switch (Flag) {\r
   case 1:\r
-    Status = BufferToHexString (StringHeader, (UINT8 *) Buffer, BufferLen);\r
+    Status = BufInReverseOrderToHexString (StringHeader, (UINT8 *) Buffer, BufferLen);\r
     break;\r
   case 2:\r
     Status = UnicodeToConfigString (StringHeader, &Length, (CHAR16 *) Buffer);\r
@@ -447,8 +447,6 @@ OutputConfigBody (
 }\r
 \r
 \r
-#endif\r
-\r
 /**\r
   Adjusts the size of a previously allocated buffer.\r
 \r
@@ -607,7 +605,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
@@ -660,8 +660,6 @@ HiiConfigRoutingExtractConfig (
   OUT EFI_STRING                             *Results\r
   )\r
 {\r
-#ifndef _DISABLE_UNUSED_HII_PROTOCOLS_\r
-\r
   HII_DATABASE_PRIVATE_DATA           *Private;\r
   EFI_STRING                          StringPtr;\r
   EFI_STRING                          ConfigRequest;\r
@@ -670,6 +668,7 @@ HiiConfigRoutingExtractConfig (
   EFI_STATUS                          Status;\r
   LIST_ENTRY                          *Link;\r
   HII_DATABASE_RECORD                 *Database;\r
+  UINT8                               *DevicePathPkg;\r
   UINT8                               *CurrentDevicePath;\r
   EFI_HANDLE                          DriverHandle;\r
   EFI_HII_CONFIG_ACCESS_PROTOCOL      *ConfigAccess;\r
@@ -678,6 +677,15 @@ HiiConfigRoutingExtractConfig (
   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 || Results == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -734,7 +742,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
@@ -747,8 +755,9 @@ HiiConfigRoutingExtractConfig (
          Link = Link->ForwardLink\r
         ) {\r
       Database = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);\r
-      CurrentDevicePath = Database->PackageList->DevicePathPkg + sizeof (EFI_HII_PACKAGE_HEADER);\r
-      if (CurrentDevicePath != NULL) {\r
+   \r
+      if ((DevicePathPkg = Database->PackageList->DevicePathPkg) != NULL) {\r
+        CurrentDevicePath = DevicePathPkg + sizeof (EFI_HII_PACKAGE_HEADER);\r
         if (CompareMem (\r
               DevicePath,\r
               CurrentDevicePath,\r
@@ -760,7 +769,7 @@ HiiConfigRoutingExtractConfig (
       }\r
     }\r
 \r
-    SafeFreePool (DevicePath);\r
+    FreePool (DevicePath);\r
 \r
     if (DriverHandle == NULL) {\r
       //\r
@@ -768,7 +777,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
@@ -797,7 +806,7 @@ HiiConfigRoutingExtractConfig (
       for (TmpPtr = StringPtr; CompareMem (TmpPtr, AccessProgress, RemainSize) != 0; TmpPtr++);\r
       *Progress = TmpPtr;\r
 \r
-      SafeFreePool (ConfigRequest);\r
+      FreePool (ConfigRequest);\r
       return Status;\r
     }\r
 \r
@@ -807,9 +816,9 @@ HiiConfigRoutingExtractConfig (
     ASSERT (*AccessProgress == 0);\r
     Status = AppendToMultiString (Results, AccessResults);\r
     ASSERT_EFI_ERROR (Status);\r
-    SafeFreePool (AccessResults);\r
+    FreePool (AccessResults);\r
     AccessResults = NULL;\r
-    SafeFreePool (ConfigRequest);\r
+    FreePool (ConfigRequest);\r
     ConfigRequest = NULL;\r
 \r
     //\r
@@ -826,9 +835,6 @@ HiiConfigRoutingExtractConfig (
   }\r
 \r
   return EFI_SUCCESS;\r
-#else\r
-  return EFI_UNSUPPORTED;\r
-#endif\r
 \r
 }\r
 \r
@@ -862,8 +868,6 @@ HiiConfigRoutingExportConfig (
   OUT EFI_STRING                             *Results\r
   )\r
 {\r
-#ifndef _DISABLE_UNUSED_HII_PROTOCOLS_\r
-\r
   EFI_STATUS                          Status;\r
   HII_DATABASE_PRIVATE_DATA           *Private;\r
   LIST_ENTRY                          StorageListHdr;\r
@@ -879,7 +883,15 @@ HiiConfigRoutingExportConfig (
   EFI_HII_CONFIG_ACCESS_PROTOCOL      *ConfigAccess;\r
   EFI_STRING                          AccessProgress;\r
   EFI_STRING                          AccessResults;\r
-  UINTN                               TmpSize;\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 || Results == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -929,19 +941,21 @@ HiiConfigRoutingExportConfig (
     if (PathHdr == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
-    Status = BufferToHexString (PathHdr, (UINT8 *) DevicePath, Length);\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
-    TmpSize = StrLen (L"GUID=&NAME=&PATH=");\r
-    RequestSize   = (TmpSize + 32 +  StrLen (Storage->Name) * 4)\r
-                     * sizeof (CHAR16) + PathHdrSize;\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
+      FreePool (PathHdr);\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
 \r
@@ -954,7 +968,7 @@ HiiConfigRoutingExportConfig (
     StrnCpy (StringPtr, L"GUID=", StrLen (L"GUID="));\r
     StringPtr += StrLen (L"GUID=");\r
 \r
-    Status = BufferToHexString (StringPtr, (UINT8 *) (&Storage->Guid), sizeof (EFI_GUID));\r
+    Status = BufInReverseOrderToHexString (StringPtr, (UINT8 *) (&Storage->Guid), sizeof (EFI_GUID));\r
     ASSERT_EFI_ERROR (Status);\r
     \r
     StringPtr += 32;\r
@@ -969,10 +983,12 @@ HiiConfigRoutingExportConfig (
     StrnCpy (StringPtr, L"NAME=", StrLen (L"NAME="));\r
     StringPtr += StrLen (L"NAME=");\r
 \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
+    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
@@ -985,7 +1001,7 @@ HiiConfigRoutingExportConfig (
     StringPtr += StrLen (L"PATH=");\r
     StrCpy (StringPtr, PathHdr);\r
 \r
-    SafeFreePool (PathHdr);\r
+    FreePool (PathHdr);\r
     PathHdr = NULL;\r
 \r
     //\r
@@ -1009,6 +1025,8 @@ HiiConfigRoutingExportConfig (
                     );\r
     ASSERT_EFI_ERROR (Status);\r
 \r
+    AccessProgress = NULL;\r
+    AccessResults  = NULL;\r
     Status = ConfigAccess->ExtractConfig (\r
                              ConfigAccess,\r
                              ConfigRequest,\r
@@ -1016,8 +1034,13 @@ HiiConfigRoutingExportConfig (
                              &AccessResults\r
                              );\r
     if (EFI_ERROR (Status)) {\r
-      SafeFreePool (ConfigRequest);\r
-      SafeFreePool (AccessResults);\r
+      FreePool (ConfigRequest);\r
+      if (AccessProgress != NULL) {\r
+        FreePool (AccessProgress);\r
+      }\r
+      if (AccessResults != NULL) {\r
+        FreePool (AccessResults);\r
+      }\r
       return EFI_INVALID_PARAMETER;\r
     }\r
 \r
@@ -1027,9 +1050,9 @@ HiiConfigRoutingExportConfig (
     ASSERT (*AccessProgress == 0);\r
     Status = AppendToMultiString (Results, AccessResults);\r
     ASSERT_EFI_ERROR (Status);\r
-    SafeFreePool (AccessResults);\r
+    FreePool (AccessResults);\r
     AccessResults = NULL;\r
-    SafeFreePool (ConfigRequest);\r
+    FreePool (ConfigRequest);\r
     ConfigRequest = NULL;\r
 \r
   }\r
@@ -1045,14 +1068,11 @@ HiiConfigRoutingExportConfig (
                 HII_FORMSET_STORAGE_SIGNATURE\r
                 );\r
     RemoveEntryList (&Storage->Entry);\r
-    SafeFreePool (Storage->Name);\r
-    SafeFreePool (Storage);\r
+    FreePool (Storage->Name);\r
+    FreePool (Storage);\r
   }\r
 \r
   return EFI_SUCCESS;\r
-#else\r
-  return EFI_UNSUPPORTED;\r
-#endif\r
 }\r
 \r
 \r
@@ -1089,8 +1109,6 @@ HiiConfigRoutingRouteConfig (
   OUT EFI_STRING                             *Progress\r
   )\r
 {\r
-#ifndef _DISABLE_UNUSED_HII_PROTOCOLS_\r
-\r
   HII_DATABASE_PRIVATE_DATA           *Private;\r
   EFI_STRING                          StringPtr;\r
   EFI_STRING                          ConfigResp;\r
@@ -1099,6 +1117,7 @@ HiiConfigRoutingRouteConfig (
   EFI_DEVICE_PATH_PROTOCOL            *DevicePath;\r
   LIST_ENTRY                          *Link;\r
   HII_DATABASE_RECORD                 *Database;\r
+  UINT8                               *DevicePathPkg;\r
   UINT8                               *CurrentDevicePath;\r
   EFI_HANDLE                          DriverHandle;\r
   EFI_HII_CONFIG_ACCESS_PROTOCOL      *ConfigAccess;\r
@@ -1106,6 +1125,15 @@ HiiConfigRoutingRouteConfig (
   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
   }\r
@@ -1156,7 +1184,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
@@ -1169,8 +1197,9 @@ HiiConfigRoutingRouteConfig (
          Link = Link->ForwardLink\r
         ) {\r
       Database = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);\r
-      CurrentDevicePath = Database->PackageList->DevicePathPkg + sizeof (EFI_HII_PACKAGE_HEADER);\r
-      if (CurrentDevicePath != NULL) {\r
+\r
+      if ((DevicePathPkg = Database->PackageList->DevicePathPkg) != NULL) {\r
+        CurrentDevicePath = DevicePathPkg + sizeof (EFI_HII_PACKAGE_HEADER);\r
         if (CompareMem (\r
               DevicePath,\r
               CurrentDevicePath,\r
@@ -1182,7 +1211,7 @@ HiiConfigRoutingRouteConfig (
       }\r
     }\r
 \r
-    SafeFreePool (DevicePath);\r
+    FreePool (DevicePath);\r
 \r
     if (DriverHandle == NULL) {\r
       //\r
@@ -1190,7 +1219,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
@@ -1219,11 +1248,11 @@ HiiConfigRoutingRouteConfig (
       for (TmpPtr = StringPtr; CompareMem (TmpPtr, AccessProgress, RemainSize) != 0; TmpPtr++);\r
       *Progress = TmpPtr;\r
 \r
-      SafeFreePool (ConfigResp);\r
+      FreePool (ConfigResp);\r
       return Status;\r
     }\r
 \r
-    SafeFreePool (ConfigResp);\r
+    FreePool (ConfigResp);\r
     ConfigResp = NULL;\r
 \r
     //\r
@@ -1240,9 +1269,6 @@ HiiConfigRoutingRouteConfig (
   }\r
 \r
   return EFI_SUCCESS;\r
-#else\r
-  return EFI_UNSUPPORTED;\r
-#endif\r
 }\r
 \r
 \r
@@ -1347,7 +1373,19 @@ HiiBlockToConfig (
     Status = EFI_INVALID_PARAMETER;\r
     goto Exit;\r
   }\r
-  while (*StringPtr++ != L'&');\r
+\r
+  while (*StringPtr != L'&' && *StringPtr != 0) {\r
+    StringPtr++;\r
+  }\r
+  if (*StringPtr == 0) {\r
+    *Progress = StringPtr;\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto Exit;\r
+  }\r
+  //\r
+  // Skip '&'\r
+  //\r
+  StringPtr++;\r
 \r
   //\r
   // Copy <ConfigHdr> and an additional '&' to <ConfigResp>\r
@@ -1381,7 +1419,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
@@ -1405,7 +1443,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
@@ -1444,7 +1482,7 @@ HiiBlockToConfig (
     ASSERT_EFI_ERROR (Status);\r
     ToLower (ValueStr);\r
 \r
-    SafeFreePool (Value);\r
+    FreePool (Value);\r
     Value = NULL;\r
 \r
     //\r
@@ -1466,8 +1504,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
@@ -1492,11 +1530,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) {\r
+    FreePool (ConfigElement);\r
+  }\r
 \r
   return Status;\r
 \r
@@ -1596,7 +1639,19 @@ HiiConfigToBlock (
     Status = EFI_INVALID_PARAMETER;\r
     goto Exit;\r
   }\r
-  while (*StringPtr++ != L'&');\r
+\r
+  while (*StringPtr != L'&' && *StringPtr != 0) {\r
+    StringPtr++;\r
+  }\r
+  if (*StringPtr == 0) {\r
+    *Progress = StringPtr;\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto Exit;\r
+  }\r
+  //\r
+  // Skip '&'\r
+  //\r
+  StringPtr++;\r
 \r
   //\r
   // Parse each <ConfigElement> if exists\r
@@ -1619,7 +1674,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
@@ -1643,7 +1698,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
@@ -1680,7 +1735,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
@@ -1704,7 +1759,9 @@ HiiConfigToBlock (
 \r
 Exit:\r
 \r
-  SafeFreePool (Value);\r
+  if (Value != NULL) {\r
+    FreePool (Value);\r
+  }\r
   return Status;\r
 }\r
 \r
@@ -1761,8 +1818,6 @@ HiiGetAltCfg (
   OUT EFI_STRING                               *AltCfgResp\r
   )\r
 {\r
-#ifndef _DISABLE_UNUSED_HII_PROTOCOLS_\r
-\r
   EFI_STATUS                          Status;\r
   EFI_STRING                          StringPtr;\r
   EFI_STRING                          HdrStart;\r
@@ -1778,6 +1833,15 @@ 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
@@ -1937,18 +2001,24 @@ 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
-#else\r
-  return EFI_UNSUPPORTED;\r
-#endif\r
-\r
 }\r
 \r
 \r