]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/UefiHiiLib/HiiLib.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Library / UefiHiiLib / HiiLib.c
index b740d43aad4b387ee507047f62f2de326b319598..564169bc144b71811be1feb48255ced87b59615c 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   HII Library implementation that uses DXE protocols and services.\r
 \r
-  Copyright (c) 2006 - 2017, 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
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  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
+  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -44,7 +38,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR16 mConfigHdrTemplate[] = L"GUID=0000000
 EFI_FORM_BROWSER2_PROTOCOL  *mUefiFormBrowser2 = NULL;\r
 \r
 //\r
-// Template used to mark the end of a list of packages \r
+// Template used to mark the end of a list of packages\r
 //\r
 GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_HII_PACKAGE_HEADER  mEndOfPakageList = {\r
   sizeof (EFI_HII_PACKAGE_HEADER),\r
@@ -85,7 +79,7 @@ InternalHiiExtractGuidFromHiiHandle (
 \r
   Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &BufferSize, HiiPackageList);\r
   ASSERT (Status != EFI_NOT_FOUND);\r
-  \r
+\r
   if (Status == EFI_BUFFER_TOO_SMALL) {\r
     HiiPackageList = AllocatePool (BufferSize);\r
     ASSERT (HiiPackageList != NULL);\r
@@ -115,7 +109,7 @@ InternalHiiExtractGuidFromHiiHandle (
   If an empty list of packages is passed in, then NULL is returned.  If the size of\r
   the list of package is 0, then NULL is returned.\r
 \r
-  The variable arguments are pointers which point to package header that defined \r
+  The variable arguments are pointers which point to package header that defined\r
   by UEFI VFR compiler and StringGather tool.\r
 \r
   #pragma pack (push, 1)\r
@@ -124,13 +118,13 @@ InternalHiiExtractGuidFromHiiHandle (
     EFI_HII_PACKAGE_HEADER  PackageHeader;\r
   } EDKII_AUTOGEN_PACKAGES_HEADER;\r
   #pragma pack (pop)\r
-  \r
+\r
   @param[in]  PackageListGuid  The GUID of the package list.\r
-  @param[in]  DeviceHandle     If not NULL, the Device Handle on which \r
+  @param[in]  DeviceHandle     If not NULL, the Device Handle on which\r
                                an instance of DEVICE_PATH_PROTOCOL is installed.\r
-                               This Device Handle uniquely defines the device that \r
+                               This Device Handle uniquely defines the device that\r
                                the added packages are associated with.\r
-  @param[in]  ...              The variable argument list that contains pointers \r
+  @param[in]  ...              The variable argument list that contains pointers\r
                                to packages terminated by a NULL.\r
 \r
   @retval NULL   A HII Handle has already been registered in the HII Database with\r
@@ -168,7 +162,7 @@ HiiAddPackages (
   VA_END (Args);\r
 \r
   //\r
-  // If there are no packages in the variable argument list or all the packages \r
+  // If there are no packages in the variable argument list or all the packages\r
   // are empty, then return a NULL HII Handle\r
   //\r
   if (Length == 0) {\r
@@ -176,7 +170,7 @@ HiiAddPackages (
   }\r
 \r
   //\r
-  // Add the length of the Package List Header and the terminating Package Header \r
+  // Add the length of the Package List Header and the terminating Package Header\r
   //\r
   Length += sizeof (EFI_HII_PACKAGE_LIST_HEADER) + sizeof (EFI_HII_PACKAGE_HEADER);\r
 \r
@@ -222,9 +216,9 @@ HiiAddPackages (
   // Register the package list with the HII Database\r
   //\r
   Status = gHiiDatabase->NewPackageList (\r
-                           gHiiDatabase, \r
-                           PackageListHeader, \r
-                           DeviceHandle, \r
+                           gHiiDatabase,\r
+                           PackageListHeader,\r
+                           DeviceHandle,\r
                            &HiiHandle\r
                            );\r
   if (EFI_ERROR (Status)) {\r
@@ -272,12 +266,12 @@ HiiRemovePackages (
   This function allocates the returned array using AllocatePool().\r
   The caller is responsible for freeing the array with FreePool().\r
 \r
-  @param[in]  PackageListGuid  An optional parameter that is used to request \r
+  @param[in]  PackageListGuid  An optional parameter that is used to request\r
                                HII Handles associated with a specific\r
                                Package List GUID.  If this parameter is NULL,\r
                                then all the HII Handles in the HII Database\r
                                are returned.  If this parameter is not NULL,\r
-                               then zero or more HII Handles associated with \r
+                               then zero or more HII Handles associated with\r
                                PackageListGuid are returned.\r
 \r
   @retval NULL   No HII handles were found in the HII database\r
@@ -312,14 +306,14 @@ HiiGetHiiHandles (
                            );\r
 \r
   //\r
-  // If ListPackageLists() returns EFI_SUCCESS for a zero size, \r
-  // then there are no HII handles in the HII database.  If ListPackageLists() \r
-  // returns an error other than EFI_BUFFER_TOO_SMALL, then there are no HII \r
+  // If ListPackageLists() returns EFI_SUCCESS for a zero size,\r
+  // then there are no HII handles in the HII database.  If ListPackageLists()\r
+  // returns an error other than EFI_BUFFER_TOO_SMALL, then there are no HII\r
   // handles in the HII database.\r
   //\r
   if (Status != EFI_BUFFER_TOO_SMALL) {\r
     //\r
-    // Return NULL if the size can not be retrieved, or if there are no HII \r
+    // Return NULL if the size can not be retrieved, or if there are no HII\r
     // handles in the HII Database\r
     //\r
     return NULL;\r
@@ -364,7 +358,7 @@ HiiGetHiiHandles (
       Status = InternalHiiExtractGuidFromHiiHandle (HiiHandleBuffer[Index1], &Guid);\r
       ASSERT_EFI_ERROR (Status);\r
       if (CompareGuid (&Guid, PackageListGuid)) {\r
-        HiiHandleBuffer[Index2++] = HiiHandleBuffer[Index1];       \r
+        HiiHandleBuffer[Index2++] = HiiHandleBuffer[Index1];\r
       }\r
     }\r
     if (Index2 > 0) {\r
@@ -379,7 +373,7 @@ HiiGetHiiHandles (
 \r
 /**\r
   This function allows a caller to extract the form set opcode form the Hii Handle.\r
-  The returned buffer is allocated using AllocatePool().The caller is responsible \r
+  The returned buffer is allocated using AllocatePool().The caller is responsible\r
   for freeing the allocated buffer using FreePool().\r
 \r
   @param Handle            The HII handle.\r
@@ -464,20 +458,24 @@ HiiGetFormSetFromHiiHandle(
       }\r
 \r
       if (FormSetBuffer != NULL){\r
-        TempBuffer = AllocateCopyPool (TempSize + ((EFI_IFR_OP_HEADER *) OpCodeData)->Length, FormSetBuffer);\r
-        FreePool(FormSetBuffer);\r
-        FormSetBuffer = NULL;\r
+        TempBuffer = ReallocatePool (\r
+                       TempSize,\r
+                       TempSize + ((EFI_IFR_OP_HEADER *) OpCodeData)->Length,\r
+                       FormSetBuffer\r
+                       );\r
         if (TempBuffer == NULL) {\r
           Status = EFI_OUT_OF_RESOURCES;\r
           goto Done;\r
         }\r
         CopyMem (TempBuffer + TempSize,  OpCodeData, ((EFI_IFR_OP_HEADER *) OpCodeData)->Length);\r
+        FormSetBuffer = NULL;\r
       } else {\r
-        TempBuffer = AllocateCopyPool (TempSize + ((EFI_IFR_OP_HEADER *) OpCodeData)->Length, OpCodeData);\r
+        TempBuffer = AllocatePool (TempSize + ((EFI_IFR_OP_HEADER *) OpCodeData)->Length);\r
         if (TempBuffer == NULL) {\r
           Status = EFI_OUT_OF_RESOURCES;\r
           goto Done;\r
         }\r
+        CopyMem (TempBuffer, OpCodeData, ((EFI_IFR_OP_HEADER *) OpCodeData)->Length);\r
       }\r
       TempSize += ((EFI_IFR_OP_HEADER *) OpCodeData)->Length;\r
       FormSetBuffer = TempBuffer;\r
@@ -499,7 +497,7 @@ Done:
 }\r
 \r
 /**\r
-  Converts all hex dtring characters in range ['A'..'F'] to ['a'..'f'] for \r
+  Converts all hex dtring characters in range ['A'..'F'] to ['a'..'f'] for\r
   hex digits that appear between a '=' and a '&' in a config string.\r
 \r
   If ConfigString is NULL, then ASSERT().\r
@@ -537,7 +535,7 @@ InternalHiiLowerConfigString (
 }\r
 \r
 /**\r
-  Uses the BlockToConfig() service of the Config Routing Protocol to \r
+  Uses the BlockToConfig() service of the Config Routing Protocol to\r
   convert <ConfigRequest> and a buffer to a <ConfigResp>\r
 \r
   If ConfigRequest is NULL, then ASSERT().\r
@@ -584,14 +582,14 @@ InternalHiiBlockToConfig (
 }\r
 \r
 /**\r
-  Uses the BrowserCallback() service of the Form Browser Protocol to retrieve \r
-  or set uncommitted data.  If sata i being retrieved, then the buffer is \r
-  allocated using AllocatePool().  The caller is then responsible for freeing \r
+  Uses the BrowserCallback() service of the Form Browser Protocol to retrieve\r
+  or set uncommitted data.  If sata i being retrieved, then the buffer is\r
+  allocated using AllocatePool().  The caller is then responsible for freeing\r
   the buffer using FreePool().\r
 \r
-  @param[in]  VariableGuid    Pointer to an EFI_GUID structure.  This is an optional \r
+  @param[in]  VariableGuid    Pointer to an EFI_GUID structure.  This is an optional\r
                               parameter that may be NULL.\r
-  @param[in]  VariableName    Pointer to a Null-terminated Unicode string.  This \r
+  @param[in]  VariableName    Pointer to a Null-terminated Unicode string.  This\r
                               is an optional parameter that may be NULL.\r
   @param[in]  SetResultsData  If not NULL, then this parameter specified the buffer\r
                               of uncommited data to set.  If this parameter is NULL,\r
@@ -644,7 +642,7 @@ InternalHiiBrowserCallback (
                               VariableGuid,\r
                               VariableName\r
                               );\r
-    \r
+\r
     if (!EFI_ERROR (Status)) {\r
       //\r
       // No Resluts Data, only allocate one char for '\0'\r
@@ -685,23 +683,23 @@ InternalHiiBrowserCallback (
 }\r
 \r
 /**\r
-  Allocates and returns a Null-terminated Unicode <ConfigHdr> string using routing \r
+  Allocates and returns a Null-terminated Unicode <ConfigHdr> string using routing\r
   information that includes a GUID, an optional Unicode string name, and a device\r
-  path.  The string returned is allocated with AllocatePool().  The caller is \r
+  path.  The string returned is allocated with AllocatePool().  The caller is\r
   responsible for freeing the allocated string with FreePool().\r
-  \r
+\r
   The format of a <ConfigHdr> is as follows:\r
 \r
     GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize<Null>\r
 \r
   @param[in]  Guid          Pointer to an EFI_GUID that is the routing information\r
-                            GUID.  Each of the 16 bytes in Guid is converted to \r
+                            GUID.  Each of the 16 bytes in Guid is converted to\r
                             a 2 Unicode character hexadecimal string.  This is\r
                             an optional parameter that may be NULL.\r
-  @param[in]  Name          Pointer to a Null-terminated Unicode string that is \r
-                            the routing information NAME.  This is an optional \r
-                            parameter that may be NULL.  Each 16-bit Unicode \r
-                            character in Name is converted to a 4 character Unicode \r
+  @param[in]  Name          Pointer to a Null-terminated Unicode string that is\r
+                            the routing information NAME.  This is an optional\r
+                            parameter that may be NULL.  Each 16-bit Unicode\r
+                            character in Name is converted to a 4 character Unicode\r
                             hexadecimal string.\r
   @param[in]  DriverHandle  The driver handle which supports a Device Path Protocol\r
                             that is the routing information PATH.  Each byte of\r
@@ -730,7 +728,7 @@ HiiConstructConfigHdr (
   UINTN                     MaxLen;\r
 \r
   //\r
-  // Compute the length of Name in Unicode characters.  \r
+  // Compute the length of Name in Unicode characters.\r
   // If Name is NULL, then the length is 0.\r
   //\r
   NameLength = 0;\r
@@ -786,7 +784,7 @@ HiiConstructConfigHdr (
       String += StrnLenS (String, MaxLen - ((UINTN)String - (UINTN)ReturnString) / sizeof (CHAR16));\r
     }\r
   }\r
-  \r
+\r
   //\r
   // Append L"&NAME="\r
   //\r
@@ -841,7 +839,7 @@ HiiConstructConfigHdr (
 }\r
 \r
 /**\r
-  Convert the hex UNICODE encoding string of UEFI GUID, NAME or device path \r
+  Convert the hex UNICODE encoding string of UEFI GUID, NAME or device path\r
   to binary buffer from <ConfigHdr>.\r
 \r
   This is a internal function.\r
@@ -874,7 +872,7 @@ InternalHiiGetBufferFromString (
   if (String == NULL || Buffer == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   DataBuffer = NULL;\r
   StringPtr  = NULL;\r
   ConfigHdr  = String;\r
@@ -909,14 +907,14 @@ InternalHiiGetBufferFromString (
         DataBuffer [Index/2] = (UINT8) ((DataBuffer [Index/2] << 4) + DigitUint8);\r
       }\r
     }\r
-    \r
+\r
     *Buffer = DataBuffer;\r
     break;\r
 \r
   case NAME_CONFIG_STRING_TYPE:\r
     //\r
     // Convert Config String to Unicode String, e.g. "0041004200430044" => "ABCD"\r
-    // \r
+    //\r
 \r
     //\r
     // Add the tailling char L'\0'\r
@@ -952,10 +950,10 @@ InternalHiiGetBufferFromString (
 /**\r
   This function checks VarOffset and VarWidth is in the block range.\r
 \r
-  @param  BlockArray         The block array is to be checked. \r
+  @param  BlockArray         The block array is to be checked.\r
   @param  VarOffset          Offset of var to the structure\r
   @param  VarWidth           Width of var.\r
-  \r
+\r
   @retval TRUE   This Var is in the block range.\r
   @retval FALSE  This Var is not in the block range.\r
 **/\r
@@ -968,14 +966,14 @@ BlockArrayCheck (
 {\r
   LIST_ENTRY          *Link;\r
   IFR_BLOCK_DATA      *BlockData;\r
-  \r
+\r
   //\r
   // No Request Block array, all vars are got.\r
   //\r
   if (BlockArray == NULL) {\r
     return TRUE;\r
   }\r
-  \r
+\r
   //\r
   // Check the input var is in the request block range.\r
   //\r
@@ -1032,7 +1030,7 @@ InternalHiiGetValueOfNumber (
     StringPtr++;\r
   }\r
   Length = StringPtr - ValueString;\r
-  \r
+\r
   //\r
   // Allocate buffer to store the value\r
   //\r
@@ -1040,7 +1038,7 @@ InternalHiiGetValueOfNumber (
   if (Buf == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  \r
+\r
   //\r
   // Convert character one by one to the value buffer\r
   //\r
@@ -1054,7 +1052,7 @@ InternalHiiGetValueOfNumber (
       Buf [Index/2] = (UINT8) ((DigitUint8 << 4) + Buf [Index/2]);\r
     }\r
   }\r
-  \r
+\r
   //\r
   // Set the converted value and string length.\r
   //\r
@@ -1069,7 +1067,7 @@ InternalHiiGetValueOfNumber (
   @param ConfigElement           ConfigResp string contains the current setting.\r
   @param VarName                 The variable name which need to get value.\r
   @param VarValue                The return value.\r
-  \r
+\r
   @retval EFI_SUCCESS            Get the value for the VarName\r
   @retval EFI_OUT_OF_RESOURCES   The memory is not enough.\r
 **/\r
@@ -1127,7 +1125,7 @@ GetValueFromRequest (
   @param RequestElement     The config string for this storage.\r
   @param HiiHandle          The HiiHandle for this formset.\r
   @param NameValueType      Whether current storage is name/value varstore or not.\r
-  \r
+\r
   @retval EFI_SUCCESS            The current setting is valid.\r
   @retval EFI_OUT_OF_RESOURCES   The memory is not enough.\r
   @retval EFI_INVALID_PARAMETER  The config string or the Hii package is invalid.\r
@@ -1169,6 +1167,13 @@ ValidateQuestionFromVfr (
   UINTN                        Index;\r
   CHAR16                       *QuestionName;\r
   CHAR16                       *StringPtr;\r
+  UINT16                       BitOffset;\r
+  UINT16                       BitWidth;\r
+  UINT16                       TotalBits;\r
+  UINTN                        StartBit;\r
+  UINTN                        EndBit;\r
+  BOOLEAN                      QuestionReferBitField;\r
+  UINT32                       BufferValue;\r
 \r
   //\r
   // Initialize the local variables.\r
@@ -1182,6 +1187,9 @@ ValidateQuestionFromVfr (
   IfrEfiVarStore    = NULL;\r
   ZeroMem (&VarStoreData, sizeof (IFR_VARSTORAGE_DATA));\r
   ZeroMem (&VarBlockData, sizeof (VarBlockData));\r
+  BitOffset = 0;\r
+  BitWidth = 0;\r
+  QuestionReferBitField = FALSE;\r
 \r
   //\r
   // Check IFR value is in block data, then Validate Value\r
@@ -1265,8 +1273,8 @@ ValidateQuestionFromVfr (
           IfrEfiVarStore = (EFI_IFR_VARSTORE_EFI *) IfrOpHdr;\r
 \r
           //\r
-          // If the length is small than the structure, this is from old efi \r
-          // varstore definition. Old efi varstore get config directly from \r
+          // If the length is small than the structure, this is from old efi\r
+          // varstore definition. Old efi varstore get config directly from\r
           // GetVariable function.\r
           //\r
           if (IfrOpHdr->Length < sizeof (EFI_IFR_VARSTORE_EFI)) {\r
@@ -1313,12 +1321,12 @@ ValidateQuestionFromVfr (
           //\r
 \r
           //\r
-          // OneOf question is not in IFR Form. This IFR form is not valid. \r
+          // OneOf question is not in IFR Form. This IFR form is not valid.\r
           //\r
           if (VarStoreData.VarStoreId == 0) {\r
             return EFI_INVALID_PARAMETER;\r
           }\r
-          // \r
+          //\r
           // Check whether this question is for the requested varstore.\r
           //\r
           IfrOneOf = (EFI_IFR_ONE_OF *) IfrOpHdr;\r
@@ -1345,8 +1353,19 @@ ValidateQuestionFromVfr (
             //\r
             // Get Offset by Question header and Width by DataType Flags\r
             //\r
-            Offset = IfrOneOf->Question.VarStoreInfo.VarOffset;\r
-            Width  = (UINT16) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE));\r
+            if (QuestionReferBitField) {\r
+              //\r
+              // Get the byte offset/width for bit field.\r
+              //\r
+              BitOffset = IfrOneOf->Question.VarStoreInfo.VarOffset;\r
+              BitWidth = IfrOneOf->Flags & EDKII_IFR_NUMERIC_SIZE_BIT;\r
+              Offset = BitOffset / 8;\r
+              TotalBits = BitOffset % 8 + BitWidth;\r
+              Width = (TotalBits % 8 == 0 ? TotalBits / 8: TotalBits / 8 + 1);\r
+            } else {\r
+              Offset = IfrOneOf->Question.VarStoreInfo.VarOffset;\r
+              Width  = (UINT16) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE));\r
+            }\r
             //\r
             // Check whether this question is in current block array.\r
             //\r
@@ -1357,11 +1376,11 @@ ValidateQuestionFromVfr (
               break;\r
             }\r
             //\r
-            // Check this var question is in the var storage \r
+            // Check this var question is in the var storage\r
             //\r
             if ((Offset + Width) > VarStoreData.Size) {\r
               //\r
-              // This question exceeds the var store size. \r
+              // This question exceeds the var store size.\r
               //\r
               return EFI_INVALID_PARAMETER;\r
             }\r
@@ -1370,7 +1389,17 @@ ValidateQuestionFromVfr (
             // Get the current value for oneof opcode\r
             //\r
             VarValue = 0;\r
-            CopyMem (&VarValue, VarBuffer +  Offset, Width);\r
+            if (QuestionReferBitField) {\r
+              //\r
+              // Get the value in bit fields.\r
+              //\r
+              StartBit = BitOffset % 8;\r
+              EndBit = StartBit + BitWidth - 1;\r
+              CopyMem ((UINT8 *) &BufferValue, VarBuffer + Offset, Width);\r
+              VarValue = BitFieldRead32 (BufferValue, StartBit, EndBit);\r
+            } else {\r
+              CopyMem (&VarValue, VarBuffer +  Offset, Width);\r
+            }\r
           }\r
           //\r
           // Set Block Data, to be checked in the following Oneof option opcode.\r
@@ -1384,7 +1413,7 @@ ValidateQuestionFromVfr (
           //\r
 \r
           //\r
-          // Numeric question is not in IFR Form. This IFR form is not valid. \r
+          // Numeric question is not in IFR Form. This IFR form is not valid.\r
           //\r
           if (VarStoreData.VarStoreId == 0) {\r
             return EFI_INVALID_PARAMETER;\r
@@ -1407,7 +1436,7 @@ ValidateQuestionFromVfr (
               //\r
               break;\r
             }\r
-            \r
+\r
             Status = GetValueFromRequest (RequestElement, QuestionName, &VarValue);\r
             if (EFI_ERROR (Status)) {\r
               return Status;\r
@@ -1416,8 +1445,19 @@ ValidateQuestionFromVfr (
             //\r
             // Get Offset by Question header and Width by DataType Flags\r
             //\r
-            Offset = IfrNumeric->Question.VarStoreInfo.VarOffset;\r
-            Width  = (UINT16) (1 << (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE));\r
+            if (QuestionReferBitField) {\r
+              //\r
+              // Get the byte offset/width for bit field.\r
+              //\r
+              BitOffset = IfrNumeric->Question.VarStoreInfo.VarOffset;\r
+              BitWidth = IfrNumeric->Flags & EDKII_IFR_NUMERIC_SIZE_BIT;\r
+              Offset = BitOffset / 8;\r
+              TotalBits = BitOffset % 8 + BitWidth;\r
+              Width  = (TotalBits % 8 == 0 ? TotalBits / 8: TotalBits / 8 + 1);\r
+            } else {\r
+              Offset = IfrNumeric->Question.VarStoreInfo.VarOffset;\r
+              Width  = (UINT16) (1 << (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE));\r
+            }\r
             //\r
             // Check whether this question is in current block array.\r
             //\r
@@ -1428,11 +1468,11 @@ ValidateQuestionFromVfr (
               break;\r
             }\r
             //\r
-            // Check this var question is in the var storage \r
+            // Check this var question is in the var storage\r
             //\r
             if ((Offset + Width) > VarStoreData.Size) {\r
               //\r
-              // This question exceeds the var store size. \r
+              // This question exceeds the var store size.\r
               //\r
               return EFI_INVALID_PARAMETER;\r
             }\r
@@ -1441,77 +1481,108 @@ ValidateQuestionFromVfr (
             // Check the current value is in the numeric range.\r
             //\r
             VarValue = 0;\r
-            CopyMem (&VarValue, VarBuffer +  Offset, Width);\r
-          }\r
-          if ((IfrNumeric->Flags & EFI_IFR_DISPLAY) == 0) {\r
-            switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) {\r
-            case EFI_IFR_NUMERIC_SIZE_1:\r
-              if ((INT8) VarValue < (INT8) IfrNumeric->data.u8.MinValue || (INT8) VarValue > (INT8) IfrNumeric->data.u8.MaxValue) {\r
-                //\r
-                // Not in the valid range.\r
-                //\r
-                return EFI_INVALID_PARAMETER;\r
-              }\r
-              break;\r
-            case EFI_IFR_NUMERIC_SIZE_2:\r
-              if ((INT16) VarValue < (INT16) IfrNumeric->data.u16.MinValue || (INT16) VarValue > (INT16) IfrNumeric->data.u16.MaxValue) {\r
-                //\r
-                // Not in the valid range.\r
-                //\r
-                return EFI_INVALID_PARAMETER;\r
-              }\r
-              break;\r
-            case EFI_IFR_NUMERIC_SIZE_4:\r
-              if ((INT32) VarValue < (INT32) IfrNumeric->data.u32.MinValue || (INT32) VarValue > (INT32) IfrNumeric->data.u32.MaxValue) {\r
-                //\r
-                // Not in the valid range.\r
-                //\r
-                return EFI_INVALID_PARAMETER;\r
-              }\r
-              break;\r
-            case EFI_IFR_NUMERIC_SIZE_8:\r
-              if ((INT64) VarValue < (INT64) IfrNumeric->data.u64.MinValue || (INT64) VarValue > (INT64) IfrNumeric->data.u64.MaxValue) {\r
-                //\r
-                // Not in the valid range.\r
-                //\r
-                return EFI_INVALID_PARAMETER;\r
-              }\r
-              break;\r
+            if (QuestionReferBitField) {\r
+              //\r
+              // Get the value in the bit fields.\r
+              //\r
+              StartBit = BitOffset % 8;\r
+              EndBit = StartBit + BitWidth - 1;\r
+              CopyMem ((UINT8 *) &BufferValue, VarBuffer + Offset, Width);\r
+              VarValue = BitFieldRead32 (BufferValue, StartBit, EndBit);\r
+            } else {\r
+              CopyMem (&VarValue, VarBuffer +  Offset, Width);\r
             }\r
+          }\r
+          if ( QuestionReferBitField) {\r
+             //\r
+             // Value in bit fields was stored as UINt32 type.\r
+             //\r
+             if ((IfrNumeric->Flags & EDKII_IFR_DISPLAY_BIT) == 0) {\r
+               if ((INT32) VarValue < (INT32) IfrNumeric->data.u32.MinValue || (INT32) VarValue > (INT32) IfrNumeric->data.u32.MaxValue) {\r
+                  //\r
+                  // Not in the valid range.\r
+                  //\r
+                  return EFI_INVALID_PARAMETER;\r
+                }\r
+             } else {\r
+               if (VarValue < IfrNumeric->data.u32.MinValue || VarValue > IfrNumeric->data.u32.MaxValue) {\r
+                  //\r
+                  // Not in the valid range.\r
+                  //\r
+                  return EFI_INVALID_PARAMETER;\r
+                }\r
+             }\r
           } else {\r
-            switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) {\r
-            case EFI_IFR_NUMERIC_SIZE_1:\r
-              if ((UINT8) VarValue < IfrNumeric->data.u8.MinValue || (UINT8) VarValue > IfrNumeric->data.u8.MaxValue) {\r
-                //\r
-                // Not in the valid range.\r
-                //\r
-                return EFI_INVALID_PARAMETER;\r
-              }\r
-              break;\r
-            case EFI_IFR_NUMERIC_SIZE_2:\r
-              if ((UINT16) VarValue < IfrNumeric->data.u16.MinValue || (UINT16) VarValue > IfrNumeric->data.u16.MaxValue) {\r
-                //\r
-                // Not in the valid range.\r
-                //\r
-                return EFI_INVALID_PARAMETER;\r
-              }\r
-              break;\r
-            case EFI_IFR_NUMERIC_SIZE_4:\r
-              if ((UINT32) VarValue < IfrNumeric->data.u32.MinValue || (UINT32) VarValue > IfrNumeric->data.u32.MaxValue) {\r
-                //\r
-                // Not in the valid range.\r
-                //\r
-                return EFI_INVALID_PARAMETER;\r
+            if ((IfrNumeric->Flags & EFI_IFR_DISPLAY) == 0) {\r
+              switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) {\r
+              case EFI_IFR_NUMERIC_SIZE_1:\r
+                if ((INT8) VarValue < (INT8) IfrNumeric->data.u8.MinValue || (INT8) VarValue > (INT8) IfrNumeric->data.u8.MaxValue) {\r
+                  //\r
+                  // Not in the valid range.\r
+                  //\r
+                  return EFI_INVALID_PARAMETER;\r
+                }\r
+                break;\r
+              case EFI_IFR_NUMERIC_SIZE_2:\r
+                if ((INT16) VarValue < (INT16) IfrNumeric->data.u16.MinValue || (INT16) VarValue > (INT16) IfrNumeric->data.u16.MaxValue) {\r
+                  //\r
+                  // Not in the valid range.\r
+                  //\r
+                  return EFI_INVALID_PARAMETER;\r
+                }\r
+                break;\r
+              case EFI_IFR_NUMERIC_SIZE_4:\r
+                if ((INT32) VarValue < (INT32) IfrNumeric->data.u32.MinValue || (INT32) VarValue > (INT32) IfrNumeric->data.u32.MaxValue) {\r
+                  //\r
+                  // Not in the valid range.\r
+                  //\r
+                  return EFI_INVALID_PARAMETER;\r
+                }\r
+                break;\r
+              case EFI_IFR_NUMERIC_SIZE_8:\r
+                if ((INT64) VarValue < (INT64) IfrNumeric->data.u64.MinValue || (INT64) VarValue > (INT64) IfrNumeric->data.u64.MaxValue) {\r
+                  //\r
+                  // Not in the valid range.\r
+                  //\r
+                  return EFI_INVALID_PARAMETER;\r
+                }\r
+                break;\r
               }\r
-              break;\r
-            case EFI_IFR_NUMERIC_SIZE_8:\r
-              if ((UINT64) VarValue < IfrNumeric->data.u64.MinValue || (UINT64) VarValue > IfrNumeric->data.u64.MaxValue) {\r
-                //\r
-                // Not in the valid range.\r
-                //\r
-                return EFI_INVALID_PARAMETER;\r
+            } else {\r
+              switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) {\r
+              case EFI_IFR_NUMERIC_SIZE_1:\r
+                if ((UINT8) VarValue < IfrNumeric->data.u8.MinValue || (UINT8) VarValue > IfrNumeric->data.u8.MaxValue) {\r
+                  //\r
+                  // Not in the valid range.\r
+                  //\r
+                  return EFI_INVALID_PARAMETER;\r
+                }\r
+                break;\r
+              case EFI_IFR_NUMERIC_SIZE_2:\r
+                if ((UINT16) VarValue < IfrNumeric->data.u16.MinValue || (UINT16) VarValue > IfrNumeric->data.u16.MaxValue) {\r
+                  //\r
+                  // Not in the valid range.\r
+                  //\r
+                  return EFI_INVALID_PARAMETER;\r
+                }\r
+                break;\r
+              case EFI_IFR_NUMERIC_SIZE_4:\r
+                if ((UINT32) VarValue < IfrNumeric->data.u32.MinValue || (UINT32) VarValue > IfrNumeric->data.u32.MaxValue) {\r
+                  //\r
+                  // Not in the valid range.\r
+                  //\r
+                  return EFI_INVALID_PARAMETER;\r
+                }\r
+                break;\r
+              case EFI_IFR_NUMERIC_SIZE_8:\r
+                if ((UINT64) VarValue < IfrNumeric->data.u64.MinValue || (UINT64) VarValue > IfrNumeric->data.u64.MaxValue) {\r
+                  //\r
+                  // Not in the valid range.\r
+                  //\r
+                  return EFI_INVALID_PARAMETER;\r
+                }\r
+                break;\r
               }\r
-              break;\r
             }\r
           }\r
           break;\r
@@ -1521,7 +1592,7 @@ ValidateQuestionFromVfr (
           //\r
 \r
           //\r
-          // CheckBox question is not in IFR Form. This IFR form is not valid. \r
+          // CheckBox question is not in IFR Form. This IFR form is not valid.\r
           //\r
           if (VarStoreData.VarStoreId == 0) {\r
             return EFI_INVALID_PARAMETER;\r
@@ -1545,7 +1616,7 @@ ValidateQuestionFromVfr (
               //\r
               break;\r
             }\r
-            \r
+\r
             Status = GetValueFromRequest (RequestElement, QuestionName, &VarValue);\r
             if (EFI_ERROR (Status)) {\r
               return Status;\r
@@ -1554,8 +1625,19 @@ ValidateQuestionFromVfr (
             //\r
             // Get Offset by Question header\r
             //\r
-            Offset = IfrCheckBox->Question.VarStoreInfo.VarOffset;\r
-            Width  = (UINT16) sizeof (BOOLEAN);\r
+           if (QuestionReferBitField) {\r
+              //\r
+              // Get the byte offset/width for bit field.\r
+              //\r
+              BitOffset = IfrCheckBox->Question.VarStoreInfo.VarOffset;\r
+              BitWidth = 1;\r
+              Offset = BitOffset / 8;\r
+              TotalBits = BitOffset % 8 + BitWidth;\r
+              Width = (TotalBits % 8 == 0 ? TotalBits / 8: TotalBits / 8 + 1);\r
+            } else {\r
+              Offset = IfrCheckBox->Question.VarStoreInfo.VarOffset;\r
+              Width  = (UINT16) sizeof (BOOLEAN);\r
+            }\r
             //\r
             // Check whether this question is in current block array.\r
             //\r
@@ -1566,11 +1648,11 @@ ValidateQuestionFromVfr (
               break;\r
             }\r
             //\r
-            // Check this var question is in the var storage \r
+            // Check this var question is in the var storage\r
             //\r
             if ((Offset + Width) > VarStoreData.Size) {\r
               //\r
-              // This question exceeds the var store size. \r
+              // This question exceeds the var store size.\r
               //\r
               return EFI_INVALID_PARAMETER;\r
             }\r
@@ -1578,7 +1660,17 @@ ValidateQuestionFromVfr (
             // Check the current value is in the numeric range.\r
             //\r
             VarValue = 0;\r
-            CopyMem (&VarValue, VarBuffer +  Offset, Width);\r
+            if (QuestionReferBitField) {\r
+              //\r
+              // Get the value in bit fields.\r
+              //\r
+              StartBit = BitOffset % 8;\r
+              EndBit = StartBit + BitWidth - 1;\r
+              CopyMem ((UINT8 *) &BufferValue, VarBuffer + Offset, Width);\r
+              VarValue = BitFieldRead32 (BufferValue, StartBit, EndBit);\r
+            } else {\r
+              CopyMem (&VarValue, VarBuffer +  Offset, Width);\r
+            }\r
           }\r
           //\r
           // Boolean type, only 1 and 0 is valid.\r
@@ -1593,7 +1685,7 @@ ValidateQuestionFromVfr (
           //\r
 \r
           //\r
-          // CheckBox question is not in IFR Form. This IFR form is not valid. \r
+          // CheckBox question is not in IFR Form. This IFR form is not valid.\r
           //\r
           if (VarStoreData.VarStoreId == 0) {\r
             return EFI_INVALID_PARAMETER;\r
@@ -1607,7 +1699,7 @@ ValidateQuestionFromVfr (
             break;\r
           }\r
           //\r
-          // Get Width by OneOf Flags\r
+          // Get the Max size of the string.\r
           //\r
           Width  = (UINT16) (IfrString->MaxSize * sizeof (UINT16));\r
           if (NameValueType) {\r
@@ -1621,16 +1713,25 @@ ValidateQuestionFromVfr (
               //\r
               break;\r
             }\r
+            //\r
+            // Skip the VarName.\r
+            //\r
+            StringPtr += StrLen (QuestionName);\r
 \r
             //\r
             // Skip the "=".\r
-            // \r
+            //\r
             StringPtr += 1;\r
-            \r
+\r
             //\r
             // Check current string length is less than maxsize\r
+            // e.g Config String: "0041004200430044", Unicode String: "ABCD". Unicode String length = Config String length / 4.\r
+            // Config string format in UEFI spec.\r
+            // <NvConfig> ::= <Label>'='<String>\r
+            // <String> ::= [<Char>]+\r
+            // <Char> ::= <HexCh>4\r
             //\r
-            if (StrSize (StringPtr) > Width) {\r
+            if (StrLen (StringPtr) / 4 > IfrString->MaxSize) {\r
               return EFI_INVALID_PARAMETER;\r
             }\r
           } else {\r
@@ -1648,11 +1749,11 @@ ValidateQuestionFromVfr (
               break;\r
             }\r
             //\r
-            // Check this var question is in the var storage \r
+            // Check this var question is in the var storage\r
             //\r
             if ((Offset + Width) > VarStoreData.Size) {\r
               //\r
-              // This question exceeds the var store size. \r
+              // This question exceeds the var store size.\r
               //\r
               return EFI_INVALID_PARAMETER;\r
             }\r
@@ -1660,14 +1761,14 @@ ValidateQuestionFromVfr (
             //\r
             // Check current string length is less than maxsize\r
             //\r
-            if (StrSize ((CHAR16 *) (VarBuffer + Offset)) > Width) {\r
+            if (StrLen ((CHAR16 *) (VarBuffer + Offset)) > IfrString->MaxSize) {\r
               return EFI_INVALID_PARAMETER;\r
             }\r
           }\r
           break;\r
         case EFI_IFR_ONE_OF_OPTION_OP:\r
           //\r
-          // Opcode Scope is zero. This one of option is not to be checked. \r
+          // Opcode Scope is zero. This one of option is not to be checked.\r
           //\r
           if (VarBlockData.Scope == 0) {\r
             break;\r
@@ -1694,6 +1795,7 @@ ValidateQuestionFromVfr (
           }\r
           break;\r
         case EFI_IFR_END_OP:\r
+          QuestionReferBitField = FALSE;\r
           //\r
           // Decrease opcode scope for the validated opcode\r
           //\r
@@ -1702,12 +1804,17 @@ ValidateQuestionFromVfr (
           }\r
 \r
           //\r
-          // OneOf value doesn't belong to one of option value. \r
+          // OneOf value doesn't belong to one of option value.\r
           //\r
           if ((VarBlockData.Scope == 0) && (VarBlockData.OpCode == EFI_IFR_ONE_OF_OP)) {\r
             return EFI_INVALID_PARAMETER;\r
           }\r
           break;\r
+        case EFI_IFR_GUID_OP:\r
+          if (CompareGuid ((EFI_GUID *)((UINT8*)IfrOpHdr + sizeof (EFI_IFR_OP_HEADER)), &gEdkiiIfrBitVarstoreGuid)) {\r
+            QuestionReferBitField = TRUE;\r
+          }\r
+          break;\r
         default:\r
           //\r
           // Increase Scope for the validated opcode\r
@@ -1743,7 +1850,7 @@ ValidateQuestionFromVfr (
   @param ConfigElement         ConfigResp element string contains the current setting.\r
   @param CurrentBlockArray     Current block array.\r
   @param VarBuffer             Data buffer for this varstore.\r
-  \r
+\r
   @retval EFI_SUCCESS            The current setting is valid.\r
   @retval EFI_OUT_OF_RESOURCES   The memory is not enough.\r
   @retval EFI_INVALID_PARAMETER  The config string or the Hii package is invalid.\r
@@ -1767,7 +1874,7 @@ GetBlockDataInfo (
   EFI_STATUS                   Status;\r
   IFR_BLOCK_DATA               *BlockArray;\r
   UINT8                        *DataBuffer;\r
-  \r
+\r
   //\r
   // Initialize the local variables.\r
   //\r
@@ -1803,7 +1910,7 @@ GetBlockDataInfo (
   while (*StringPtr != 0 && StrnCmp (StringPtr, L"&OFFSET=", StrLen (L"&OFFSET=")) == 0) {\r
     //\r
     // Skip the &OFFSET= string\r
-    // \r
+    //\r
     StringPtr += StrLen (L"&OFFSET=");\r
 \r
     //\r
@@ -1874,7 +1981,7 @@ GetBlockDataInfo (
     //\r
     // Check whether VarBuffer is enough\r
     //\r
-    if ((UINTN) (Offset + Width) > MaxBufferSize) {\r
+    if ((UINT32)Offset + Width > MaxBufferSize) {\r
       DataBuffer = ReallocatePool (\r
                     MaxBufferSize,\r
                     Offset + Width + HII_LIB_DEFAULT_VARSTORE_SIZE,\r
@@ -1933,13 +2040,13 @@ GetBlockDataInfo (
     }\r
 \r
     //\r
-    // If '\0', parsing is finished. \r
+    // If '\0', parsing is finished.\r
     //\r
     if (*StringPtr == 0) {\r
       break;\r
     }\r
     //\r
-    // Go to next ConfigBlock \r
+    // Go to next ConfigBlock\r
     //\r
   }\r
 \r
@@ -1969,7 +2076,7 @@ Done:
   if (DataBuffer != NULL) {\r
     FreePool (DataBuffer);\r
   }\r
-  \r
+\r
   if (BlockArray != NULL) {\r
     //\r
     // Free Link Array CurrentBlockArray\r
@@ -1994,7 +2101,7 @@ Done:
   @param VarGuid            Guid of the buffer storage.\r
   @param VarName            Name of the buffer storage.\r
   @param HiiHandle          The HiiHandle for this package.\r
-  \r
+\r
   @retval EFI_SUCCESS            The current setting is valid.\r
   @retval EFI_OUT_OF_RESOURCES   The memory is not enough.\r
   @retval EFI_INVALID_PARAMETER  The config string or the Hii package is invalid.\r
@@ -2063,7 +2170,7 @@ InternalHiiValidateCurrentSetting (
   if (VarBuffer != NULL) {\r
     FreePool (VarBuffer);\r
   }\r
-  \r
+\r
   if (CurrentBlockArray != NULL) {\r
     //\r
     // Free Link Array CurrentBlockArray\r
@@ -2088,7 +2195,7 @@ InternalHiiValidateCurrentSetting (
 \r
   @retval  TRUE              The input include config request elements.\r
   @retval  FALSE             The input string not includes.\r
-                                 \r
+\r
 **/\r
 BOOLEAN\r
 GetElementsFromRequest (\r
@@ -2111,15 +2218,15 @@ GetElementsFromRequest (
   This function parses the input ConfigRequest string and its matched IFR code\r
   string for setting default value and validating current setting.\r
 \r
-  1. For setting default action, Reset the default value specified by DefaultId \r
+  1. For setting default action, Reset the default value specified by DefaultId\r
   to the driver configuration got by Request string.\r
-  2. For validating current setting, Validate the current configuration \r
+  2. For validating current setting, Validate the current configuration\r
   by parsing HII form IFR opcode.\r
 \r
   NULL request string support depends on the ExportConfig interface of\r
   HiiConfigRouting protocol in UEFI specification.\r
-  \r
-  @param Request    A null-terminated Unicode string in \r
+\r
+  @param Request    A null-terminated Unicode string in\r
                     <MultiConfigRequest> format. It can be NULL.\r
                     If it is NULL, all current configuration for the\r
                     entirety of the current HII database will be validated.\r
@@ -2127,7 +2234,7 @@ GetElementsFromRequest (
                     entirety of the current HII database will be reset.\r
   @param DefaultId  Specifies the type of defaults to retrieve only for setting default action.\r
   @param ActionType Action supports setting defaults and validate current setting.\r
-  \r
+\r
   @retval TRUE    Action runs successfully.\r
   @retval FALSE   Action is not valid or Action can't be executed successfully..\r
 **/\r
@@ -2171,7 +2278,7 @@ InternalHiiIfrValueAction (
   TempDriverHandle = NULL;\r
   HiiHandle        = NULL;\r
   HiiPackageList   = NULL;\r
-  \r
+\r
   //\r
   // Only support set default and validate setting action.\r
   //\r
@@ -2195,14 +2302,15 @@ InternalHiiIfrValueAction (
                                   &ConfigAltResp\r
                                 );\r
   }\r
-  \r
+\r
   if (EFI_ERROR (Status)) {\r
     return FALSE;\r
   }\r
-  \r
+\r
   StringPtr = ConfigAltResp;\r
-  \r
-  while (StringPtr != L'\0') {\r
+  ASSERT (StringPtr != NULL);\r
+\r
+  while (*StringPtr != L'\0') {\r
     //\r
     // 1. Find <ConfigHdr> GUID=...&NAME=...&PATH=...\r
     //\r
@@ -2236,7 +2344,7 @@ InternalHiiIfrValueAction (
     if (EFI_ERROR (Status)) {\r
       goto Done;\r
     }\r
-    \r
+\r
     //\r
     // Get Path value DevicePath\r
     //\r
@@ -2261,7 +2369,7 @@ InternalHiiIfrValueAction (
     if (EFI_ERROR (Status)) {\r
       goto Done;\r
     }\r
-    \r
+\r
     //\r
     // Find the matched Hii Handle for the found Driver handle\r
     //\r
@@ -2285,7 +2393,7 @@ InternalHiiIfrValueAction (
       //\r
       // This request string has no its Hii package.\r
       // Its default value and validating can't execute by parsing IFR data.\r
-      // Directly jump into the next ConfigAltResp string for another pair Guid, Name, and Path.   \r
+      // Directly jump into the next ConfigAltResp string for another pair Guid, Name, and Path.\r
       //\r
       Status = EFI_SUCCESS;\r
       goto NextConfigAltResp;\r
@@ -2297,7 +2405,7 @@ InternalHiiIfrValueAction (
     PackageListLength  = 0;\r
     HiiPackageList     = NULL;\r
     Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, HiiHandle, &PackageListLength, HiiPackageList);\r
-  \r
+\r
     //\r
     // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.\r
     //\r
@@ -2305,13 +2413,13 @@ InternalHiiIfrValueAction (
       Status = EFI_INVALID_PARAMETER;\r
       goto Done;\r
     }\r
-  \r
+\r
     HiiPackageList = AllocatePool (PackageListLength);\r
     if (HiiPackageList == NULL) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
       goto Done;\r
     }\r
-  \r
+\r
     //\r
     // Get PackageList on HiiHandle\r
     //\r
@@ -2319,7 +2427,7 @@ InternalHiiIfrValueAction (
     if (EFI_ERROR (Status)) {\r
       goto Done;\r
     }\r
-    \r
+\r
     //\r
     // 3. Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, Name, DevicePath, AltCfgId, AltCfgResp)\r
     //    Get the default configuration string according to the default ID.\r
@@ -2333,7 +2441,7 @@ InternalHiiIfrValueAction (
                                   (ActionType == ACTION_SET_DEFAUTL_VALUE) ? &DefaultId:NULL,  // it can be NULL to get the current setting.\r
                                   &ConfigResp\r
                                 );\r
-    \r
+\r
     //\r
     // The required setting can't be found. So, it is not required to be validated and set.\r
     //\r
@@ -2347,7 +2455,7 @@ InternalHiiIfrValueAction (
     if (!GetElementsFromRequest (ConfigResp)) {\r
       goto NextConfigAltResp;\r
     }\r
-    \r
+\r
     //\r
     // 4. Set the default configuration information or Validate current setting by parse IFR code.\r
     //    Current Setting is in ConfigResp, will be set into buffer, then check it again.\r
@@ -2376,7 +2484,7 @@ NextConfigAltResp:
       FreePool (HiiPackageList);\r
       HiiPackageList = NULL;\r
     }\r
-    \r
+\r
     if (ConfigResp != NULL) {\r
       FreePool (ConfigResp);\r
       ConfigResp = NULL;\r
@@ -2387,10 +2495,10 @@ NextConfigAltResp:
     //\r
     FreePool (VarGuid);\r
     VarGuid = NULL;\r
-  \r
+\r
     FreePool (VarName);\r
     VarName = NULL;\r
-  \r
+\r
     FreePool (DevicePath);\r
     DevicePath = NULL;\r
 \r
@@ -2407,9 +2515,9 @@ NextConfigAltResp:
     if (*StringPtr == L'\0') {\r
       break;\r
     }\r
-        \r
+\r
     //\r
-    // Construct ConfigAltHdr string  "&<ConfigHdr>&ALTCFG=\0" \r
+    // Construct ConfigAltHdr string  "&<ConfigHdr>&ALTCFG=\0"\r
     //                               | 1 | StrLen (ConfigHdr) | 8 | 1 |\r
     //\r
     MaxLen = 1 + StringPtr - StringHdr + 8 + 1;\r
@@ -2421,7 +2529,7 @@ NextConfigAltResp:
     StrCpyS (ConfigAltHdr, MaxLen, L"&");\r
     StrnCatS (ConfigAltHdr, MaxLen, StringHdr, StringPtr - StringHdr);\r
     StrCatS (ConfigAltHdr, MaxLen, L"&ALTCFG=");\r
-    \r
+\r
     //\r
     // Skip all AltResp (AltConfigHdr ConfigBody) for the same ConfigHdr\r
     //\r
@@ -2431,7 +2539,7 @@ NextConfigAltResp:
         break;\r
       }\r
     }\r
-    \r
+\r
     //\r
     // Free the allocated ConfigAltHdr string\r
     //\r
@@ -2439,7 +2547,7 @@ NextConfigAltResp:
     if (*StringPtr == L'\0') {\r
       break;\r
     }\r
-    \r
+\r
     //\r
     // Find &GUID as the next ConfigHdr\r
     //\r
@@ -2453,7 +2561,7 @@ NextConfigAltResp:
     //\r
     StringPtr ++;\r
   }\r
-  \r
+\r
 Done:\r
   if (VarGuid != NULL) {\r
     FreePool (VarGuid);\r
@@ -2474,11 +2582,11 @@ Done:
   if (ConfigAltResp != NULL) {\r
     FreePool (ConfigAltResp);\r
   }\r
\r
+\r
   if (HiiPackageList != NULL) {\r
     FreePool (HiiPackageList);\r
   }\r
-  \r
+\r
   if (EFI_ERROR (Status)) {\r
     return FALSE;\r
   }\r
@@ -2491,17 +2599,17 @@ Done:
 \r
   NULL request string support depends on the ExportConfig interface of\r
   HiiConfigRouting protocol in UEFI specification.\r
-  \r
-  @param  Request   A null-terminated Unicode string in \r
+\r
+  @param  Request   A null-terminated Unicode string in\r
                     <MultiConfigRequest> format. It can be NULL.\r
                     If it is NULL, all current configuration for the\r
                     entirety of the current HII database will be validated.\r
-  \r
+\r
   @retval TRUE    Current configuration is valid.\r
   @retval FALSE   Current configuration is invalid.\r
 **/\r
 BOOLEAN\r
-EFIAPI                               \r
+EFIAPI\r
 HiiValidateSettings (\r
   IN CONST EFI_STRING Request  OPTIONAL\r
   )\r
@@ -2511,17 +2619,17 @@ HiiValidateSettings (
 \r
 /**\r
   Reset the default value specified by DefaultId to the driver\r
-  configuration got by Request string. \r
+  configuration got by Request string.\r
 \r
   NULL request string support depends on the ExportConfig interface of\r
   HiiConfigRouting protocol in UEFI specification.\r
-  \r
-  @param Request    A null-terminated Unicode string in \r
+\r
+  @param Request    A null-terminated Unicode string in\r
                     <MultiConfigRequest> format. It can be NULL.\r
                     If it is NULL, all configuration for the\r
                     entirety of the current HII database will be reset.\r
   @param DefaultId  Specifies the type of defaults to retrieve.\r
-  \r
+\r
   @retval TRUE    The default value is set successfully.\r
   @retval FALSE   The default value can't be found and set.\r
 **/\r
@@ -2538,8 +2646,8 @@ HiiSetToDefaults (
 /**\r
   Determines if two values in config strings match.\r
 \r
-  Compares the substring between StartSearchString and StopSearchString in \r
-  FirstString to the substring between StartSearchString and StopSearchString \r
+  Compares the substring between StartSearchString and StopSearchString in\r
+  FirstString to the substring between StartSearchString and StopSearchString\r
   in SecondString.  If the two substrings match, then TRUE is returned.  If the\r
   two substrings do not match, then FALSE is returned.\r
 \r
@@ -2550,20 +2658,20 @@ HiiSetToDefaults (
 \r
   @param FirstString        Pointer to the first Null-terminated Unicode string.\r
   @param SecondString       Pointer to the second Null-terminated Unicode string.\r
-  @param StartSearchString  Pointer to the Null-terminated Unicode string that \r
+  @param StartSearchString  Pointer to the Null-terminated Unicode string that\r
                             marks the start of the value string to compare.\r
-  @param StopSearchString   Pointer to the Null-terminated Unicode string that \r
+  @param StopSearchString   Pointer to the Null-terminated Unicode string that\r
                             marks the end of the value string to compare.\r
 \r
-  @retval FALSE             StartSearchString is not present in FirstString. \r
+  @retval FALSE             StartSearchString is not present in FirstString.\r
   @retval FALSE             StartSearchString is not present in SecondString.\r
-  @retval FALSE             StopSearchString is not present in FirstString. \r
+  @retval FALSE             StopSearchString is not present in FirstString.\r
   @retval FALSE             StopSearchString is not present in SecondString.\r
-  @retval FALSE             The length of the substring in FirstString is not the \r
+  @retval FALSE             The length of the substring in FirstString is not the\r
                             same length as the substring in SecondString.\r
-  @retval FALSE             The value string in FirstString does not matche the \r
+  @retval FALSE             The value string in FirstString does not matche the\r
                             value string in SecondString.\r
-  @retval TRUE              The value string in FirstString matches the value \r
+  @retval TRUE              The value string in FirstString matches the value\r
                             string in SecondString.\r
 \r
 **/\r
@@ -2672,11 +2780,11 @@ HiiIsConfigHdrMatch (
   Retrieves uncommitted data from the Form Browser and converts it to a binary\r
   buffer.\r
 \r
-  @param[in]  VariableGuid  Pointer to an EFI_GUID structure.  This is an optional \r
+  @param[in]  VariableGuid  Pointer to an EFI_GUID structure.  This is an optional\r
                             parameter that may be NULL.\r
-  @param[in]  VariableName  Pointer to a Null-terminated Unicode string.  This \r
+  @param[in]  VariableName  Pointer to a Null-terminated Unicode string.  This\r
                             is an optional parameter that may be NULL.\r
-  @param[in]  BufferSize    Length in bytes of buffer to hold retrieved data. \r
+  @param[in]  BufferSize    Length in bytes of buffer to hold retrieved data.\r
   @param[out] Buffer        Buffer of data to be updated.\r
 \r
   @retval FALSE  The uncommitted data could not be retrieved.\r
@@ -2713,7 +2821,7 @@ HiiGetBrowserData (
   Size = Size + (StrLen (ResultsData) + 1) * sizeof (CHAR16);\r
   ConfigResp = AllocateZeroPool (Size);\r
   UnicodeSPrint (ConfigResp, Size, L"%s&%s", mConfigHdrTemplate, ResultsData);\r
-  \r
+\r
   //\r
   // Free the allocated buffer\r
   //\r
@@ -2758,7 +2866,7 @@ HiiGetBrowserData (
   @param[in]  RequestElement  An optional field to specify which part of the\r
                               buffer data will be send back to Browser. If NULL,\r
                               the whole buffer of data will be committed to\r
-                              Browser. \r
+                              Browser.\r
                               <RequestElement> ::= &OFFSET=<Number>&WIDTH=<Number>*\r
 \r
   @retval FALSE  The uncommitted data could not be updated.\r
@@ -2787,7 +2895,7 @@ HiiSetBrowserData (
   //\r
   if (RequestElement == NULL) {\r
     //\r
-    // Allocate and fill a buffer large enough to hold the <ConfigHdr> template \r
+    // Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r
     // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r
     //\r
     Size = (StrLen (mConfigHdrTemplate) + 32 + 1) * sizeof (CHAR16);\r
@@ -2795,7 +2903,7 @@ HiiSetBrowserData (
     UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", mConfigHdrTemplate, (UINT64)BufferSize);\r
   } else {\r
     //\r
-    // Allocate and fill a buffer large enough to hold the <ConfigHdr> template \r
+    // Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r
     // followed by <RequestElement> followed by a Null-terminator\r
     //\r
     Size = StrLen (mConfigHdrTemplate) * sizeof (CHAR16);\r
@@ -2854,7 +2962,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 mHiiDefaultTypeToWidth[] = {
 };\r
 \r
 /**\r
-  Allocates and returns a new OpCode Handle.  OpCode Handles must be freed with \r
+  Allocates and returns a new OpCode Handle.  OpCode Handles must be freed with\r
   HiiFreeOpCodeHandle().\r
 \r
   @retval NULL   There are not enough resources to allocate a new OpCode Handle.\r
@@ -2912,7 +3020,7 @@ HiiFreeOpCodeHandle (
 \r
 /**\r
   Internal function gets the current position of opcode buffer.\r
-  \r
+\r
   @param[in]  OpCodeHandle   Handle to the buffer of opcodes.\r
 \r
   @return Current position of opcode buffer.\r
@@ -2928,7 +3036,7 @@ InternalHiiOpCodeHandlePosition (
 \r
 /**\r
   Internal function gets the start pointer of opcode buffer.\r
-  \r
+\r
   @param[in]  OpCodeHandle   Handle to the buffer of opcodes.\r
 \r
   @return Pointer to the opcode buffer base.\r
@@ -2945,7 +3053,7 @@ InternalHiiOpCodeHandleBuffer (
 /**\r
   Internal function reserves the enough buffer for current opcode.\r
   When the buffer is not enough, Opcode buffer will be extended.\r
-  \r
+\r
   @param[in]  OpCodeHandle   Handle to the buffer of opcodes.\r
   @param[in]  Size           Size of current opcode.\r
 \r
@@ -2966,7 +3074,7 @@ InternalHiiGrowOpCodeHandle (
   OpCodeBuffer = (HII_LIB_OPCODE_BUFFER *)OpCodeHandle;\r
   if (OpCodeBuffer->Position + Size > OpCodeBuffer->BufferSize) {\r
     Buffer = ReallocatePool (\r
-              OpCodeBuffer->BufferSize, \r
+              OpCodeBuffer->BufferSize,\r
               OpCodeBuffer->BufferSize + (Size + HII_LIB_OPCODE_ALLOCATION_SIZE),\r
               OpCodeBuffer->Buffer\r
               );\r
@@ -2981,7 +3089,7 @@ InternalHiiGrowOpCodeHandle (
 \r
 /**\r
   Internal function creates opcode based on the template opcode.\r
-  \r
+\r
   @param[in]  OpCodeHandle    Handle to the buffer of opcodes.\r
   @param[in]  OpCodeTemplate  Pointer to the template buffer of opcode.\r
   @param[in]  OpCode          OpCode IFR value.\r
@@ -3018,7 +3126,7 @@ InternalHiiCreateOpCodeExtended (
 \r
 /**\r
   Internal function creates opcode based on the template opcode for the normal opcode.\r
-  \r
+\r
   @param[in]  OpCodeHandle    Handle to the buffer of opcodes.\r
   @param[in]  OpCodeTemplate  Pointer to the template buffer of opcode.\r
   @param[in]  OpCode          OpCode IFR value.\r
@@ -3203,14 +3311,14 @@ HiiCreateDefaultOpCode (
 \r
   @param[in]  OpCodeHandle  Handle to the buffer of opcodes.\r
   @param[in]  Guid          Pointer to EFI_GUID of this guided opcode.\r
-  @param[in]  GuidOpCode    Pointer to an EFI_IFR_GUID opcode.  This is an \r
+  @param[in]  GuidOpCode    Pointer to an EFI_IFR_GUID opcode.  This is an\r
                             optional parameter that may be NULL.  If this\r
-                            parameter is NULL, then the GUID extension \r
+                            parameter is NULL, then the GUID extension\r
                             region of the created opcode is filled with zeros.\r
-                            If this parameter is not NULL, then the GUID \r
-                            extension region of GuidData will be copied to \r
+                            If this parameter is not NULL, then the GUID\r
+                            extension region of GuidData will be copied to\r
                             the GUID extension region of the created opcode.\r
-  @param[in]  OpCodeSize    The size, in bytes, of created opcode.  This value \r
+  @param[in]  OpCodeSize    The size, in bytes, of created opcode.  This value\r
                             must be >= sizeof(EFI_IFR_GUID).\r
 \r
   @retval NULL   There is not enough space left in Buffer to add the opcode.\r
@@ -3236,7 +3344,7 @@ HiiCreateGuidOpCode (
   CopyGuid ((EFI_GUID *)(VOID *)&OpCode.Guid, Guid);\r
 \r
   OpCodePointer = (EFI_IFR_GUID *)InternalHiiCreateOpCodeExtended (\r
-                                    OpCodeHandle, \r
+                                    OpCodeHandle,\r
                                     &OpCode,\r
                                     EFI_IFR_GUID_OP,\r
                                     sizeof (OpCode),\r
@@ -3330,11 +3438,11 @@ HiiCreateSubTitleOpCode (
   OpCode.Flags            = Flags;\r
 \r
   return InternalHiiCreateOpCodeExtended (\r
-           OpCodeHandle, \r
+           OpCodeHandle,\r
            &OpCode,\r
-           EFI_IFR_SUBTITLE_OP, \r
-           sizeof (OpCode), \r
-           0, \r
+           EFI_IFR_SUBTITLE_OP,\r
+           sizeof (OpCode),\r
+           0,\r
            Scope\r
            );\r
 }\r
@@ -3384,7 +3492,7 @@ HiiCreateGotoOpCode (
 /**\r
   Create EFI_IFR_REF_OP, EFI_IFR_REF2_OP, EFI_IFR_REF3_OP and EFI_IFR_REF4_OP opcode.\r
 \r
-  When RefDevicePath is not zero, EFI_IFR_REF4 opcode will be created. \r
+  When RefDevicePath is not zero, EFI_IFR_REF4 opcode will be created.\r
   When RefDevicePath is zero and RefFormSetId is not NULL, EFI_IFR_REF3 opcode will be created.\r
   When RefDevicePath is zero, RefFormSetId is NULL and RefQuestionId is not zero, EFI_IFR_REF2 opcode will be created.\r
   When RefDevicePath is zero, RefFormSetId is NULL and RefQuestionId is zero, EFI_IFR_REF opcode will be created.\r
@@ -3398,11 +3506,11 @@ HiiCreateGotoOpCode (
   @param[in]  Help           The string ID for Help.\r
   @param[in]  QuestionFlags  The flags in Question Header\r
   @param[in]  QuestionId     Question ID.\r
-  @param[in]  RefQuestionId  The question on the form to which this link is referring. \r
+  @param[in]  RefQuestionId  The question on the form to which this link is referring.\r
                              If its value is zero, then the link refers to the top of the form.\r
-  @param[in]  RefFormSetId   The form set to which this link is referring. If its value is NULL, and RefDevicePath is \r
+  @param[in]  RefFormSetId   The form set to which this link is referring. If its value is NULL, and RefDevicePath is\r
                              zero, then the link is to the current form set.\r
-  @param[in]  RefDevicePath  The string identifier that specifies the string containing the text representation of \r
+  @param[in]  RefDevicePath  The string identifier that specifies the string containing the text representation of\r
                              the device path to which the form set containing the form specified by FormId.\r
                              If its value is zero, then the link refers to the current page.\r
 \r
@@ -3996,7 +4104,7 @@ HiiCreateTimeOpCode (
   @param[in] FormSetGuid       The optional Formset GUID.\r
   @param[in] FormId            The Form ID.\r
   @param[in] Package           The package header.\r
-  @param[in] OpCodeBufferStart An OpCode buffer that contains the set of IFR \r
+  @param[in] OpCodeBufferStart An OpCode buffer that contains the set of IFR\r
                                opcodes to be inserted or replaced in the form.\r
   @param[in] OpCodeBufferEnd   An OpCcode buffer that contains the IFR opcode\r
                                that marks the end of a replace operation in the form.\r
@@ -4043,7 +4151,7 @@ InternalHiiUpdateFormPackageData (
     CopyMem (BufferPos, IfrOpHdr, IfrOpHdr->Length);\r
     BufferPos           += IfrOpHdr->Length;\r
     UpdatePackageLength += IfrOpHdr->Length;\r
-    \r
+\r
     //\r
     // Find the matched FormSet and Form\r
     //\r
@@ -4060,7 +4168,7 @@ InternalHiiUpdateFormPackageData (
         GetForm = FALSE;\r
       }\r
     }\r
-    \r
+\r
     //\r
     // The matched Form is found, and Update data in this form\r
     //\r
@@ -4089,7 +4197,7 @@ InternalHiiUpdateFormPackageData (
             Offset        += IfrOpHdr->Length;\r
             IfrOpHdr       = (EFI_IFR_OP_HEADER *) ((UINT8 *) (IfrOpHdr) + IfrOpHdr->Length);\r
           }\r
-          \r
+\r
           if (Offset >= PackageHeader.Length) {\r
             //\r
             // The end opcode is not found.\r
@@ -4136,7 +4244,7 @@ InternalHiiUpdateFormPackageData (
     Offset   += IfrOpHdr->Length;\r
     IfrOpHdr = (EFI_IFR_OP_HEADER *) ((CHAR8 *) (IfrOpHdr) + IfrOpHdr->Length);\r
   }\r
-  \r
+\r
   if (!Updated) {\r
     //\r
     // The updated opcode buffer is not found.\r
@@ -4153,26 +4261,26 @@ InternalHiiUpdateFormPackageData (
 }\r
 \r
 /**\r
-  This function updates a form that has previously been registered with the HII \r
+  This function updates a form that has previously been registered with the HII\r
   Database.  This function will perform at most one update operation.\r
-    \r
-  The form to update is specified by Handle, FormSetGuid, and FormId.  Binary \r
-  comparisons of IFR opcodes are performed from the beginning of the form being \r
-  updated until an IFR opcode is found that exactly matches the first IFR opcode \r
+\r
+  The form to update is specified by Handle, FormSetGuid, and FormId.  Binary\r
+  comparisons of IFR opcodes are performed from the beginning of the form being\r
+  updated until an IFR opcode is found that exactly matches the first IFR opcode\r
   specified by StartOpCodeHandle.  The following rules are used to determine if\r
   an insert, replace, or delete operation is performed.\r
-  \r
-  1) If no matches are found, then NULL is returned.  \r
+\r
+  1) If no matches are found, then NULL is returned.\r
   2) If a match is found, and EndOpCodeHandle is NULL, then all of the IFR opcodes\r
-     from StartOpCodeHandle except the first opcode are inserted immediately after \r
+     from StartOpCodeHandle except the first opcode are inserted immediately after\r
      the matching IFR opcode in the form to be updated.\r
-  3) If a match is found, and EndOpCodeHandle is not NULL, then a search is made \r
-     from the matching IFR opcode until an IFR opcode exactly matches the first \r
+  3) If a match is found, and EndOpCodeHandle is not NULL, then a search is made\r
+     from the matching IFR opcode until an IFR opcode exactly matches the first\r
      IFR opcode specified by EndOpCodeHandle.  If no match is found for the first\r
      IFR opcode specified by EndOpCodeHandle, then NULL is returned.  If a match\r
-     is found, then all of the IFR opcodes between the start match and the end \r
+     is found, then all of the IFR opcodes between the start match and the end\r
      match are deleted from the form being updated and all of the IFR opcodes\r
-     from StartOpCodeHandle except the first opcode are inserted immediately after \r
+     from StartOpCodeHandle except the first opcode are inserted immediately after\r
      the matching start IFR opcode.  If StartOpCcodeHandle only contains one\r
      IFR instruction, then the result of this operation will delete all of the IFR\r
      opcodes between the start end matches.\r
@@ -4185,26 +4293,26 @@ InternalHiiUpdateFormPackageData (
                                  is an optional parameter that may be NULL.\r
                                  If it is NULL, all FormSet will be updated.\r
   @param[in]  FormId             The ID of the form to update.\r
-  @param[in]  StartOpCodeHandle  An OpCode Handle that contains the set of IFR \r
+  @param[in]  StartOpCodeHandle  An OpCode Handle that contains the set of IFR\r
                                  opcodes to be inserted or replaced in the form.\r
-                                 The first IFR instruction in StartOpCodeHandle \r
-                                 is used to find matching IFR opcode in the \r
-                                 form. \r
+                                 The first IFR instruction in StartOpCodeHandle\r
+                                 is used to find matching IFR opcode in the\r
+                                 form.\r
   @param[in]  EndOpCodeHandle    An OpCcode Handle that contains the IFR opcode\r
                                  that marks the end of a replace operation in\r
                                  the form.  This is an optional parameter that\r
                                  may be NULL.  If it is NULL, then an the IFR\r
-                                 opcodes specified by StartOpCodeHandle are \r
+                                 opcodes specified by StartOpCodeHandle are\r
                                  inserted into the form.\r
-  \r
+\r
   @retval EFI_OUT_OF_RESOURCES   No enough memory resource is allocated.\r
   @retval EFI_NOT_FOUND          The following cases will return EFI_NOT_FOUND.\r
-                                 1) The form specified by HiiHandle, FormSetGuid, \r
+                                 1) The form specified by HiiHandle, FormSetGuid,\r
                                  and FormId could not be found in the HII Database.\r
                                  2) No IFR opcodes in the target form match the first\r
                                  IFR opcode in StartOpCodeHandle.\r
-                                 3) EndOpCOde is not NULL, and no IFR opcodes in the \r
-                                 target form following a matching start opcode match \r
+                                 3) EndOpCOde is not NULL, and no IFR opcodes in the\r
+                                 target form following a matching start opcode match\r
                                  the first IFR opcode in EndOpCodeHandle.\r
   @retval EFI_SUCCESS            The matched form is updated by StartOpcode.\r
 \r
@@ -4212,7 +4320,7 @@ InternalHiiUpdateFormPackageData (
 EFI_STATUS\r
 EFIAPI\r
 HiiUpdateForm (\r
-  IN EFI_HII_HANDLE  HiiHandle,           \r
+  IN EFI_HII_HANDLE  HiiHandle,\r
   IN EFI_GUID        *FormSetGuid,        OPTIONAL\r
   IN EFI_FORM_ID     FormId,\r
   IN VOID            *StartOpCodeHandle,\r
@@ -4221,7 +4329,7 @@ HiiUpdateForm (
 {\r
   EFI_STATUS                   Status;\r
   EFI_HII_PACKAGE_LIST_HEADER  *HiiPackageList;\r
-  UINT32                       PackageListLength;  \r
+  UINT32                       PackageListLength;\r
   UINT32                       Offset;\r
   EFI_HII_PACKAGE_LIST_HEADER  *UpdatePackageList;\r
   UINTN                        BufferSize;\r
@@ -4232,7 +4340,7 @@ HiiUpdateForm (
   BOOLEAN                      Updated;\r
   HII_LIB_OPCODE_BUFFER        *OpCodeBufferStart;\r
   HII_LIB_OPCODE_BUFFER        *OpCodeBufferEnd;\r
-  \r
+\r
   //\r
   // Input update data can't be NULL.\r
   //\r
@@ -4241,13 +4349,13 @@ HiiUpdateForm (
   UpdatePackageList = NULL;\r
   TempPackage       = NULL;\r
   HiiPackageList    = NULL;\r
-  \r
+\r
   //\r
   // Retrieve buffer data from Opcode Handle\r
   //\r
   OpCodeBufferStart = (HII_LIB_OPCODE_BUFFER *) StartOpCodeHandle;\r
   OpCodeBufferEnd   = (HII_LIB_OPCODE_BUFFER *) EndOpCodeHandle;\r
-  \r
+\r
   //\r
   // Get the original package list\r
   //\r
@@ -4281,7 +4389,7 @@ HiiUpdateForm (
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Finish;\r
   }\r
-  \r
+\r
   //\r
   // Allocate temp buffer to store the temp updated package buffer\r
   //\r
@@ -4298,7 +4406,7 @@ HiiUpdateForm (
   //\r
   CopyMem (UpdateBufferPos, HiiPackageList, sizeof (EFI_HII_PACKAGE_LIST_HEADER));\r
   UpdateBufferPos += sizeof (EFI_HII_PACKAGE_LIST_HEADER);\r
-  \r
+\r
   //\r
   // Go through each package to find the matched package and update one by one\r
   //\r
@@ -4321,7 +4429,7 @@ HiiUpdateForm (
       if (!EFI_ERROR(Status)) {\r
         //\r
         // Set Update Flag\r
-        //        \r
+        //\r
         Updated = TRUE;\r
         //\r
         // Add updated package buffer\r
@@ -4337,14 +4445,14 @@ HiiUpdateForm (
     CopyMem (UpdateBufferPos, Package, PackageHeader.Length);\r
     UpdateBufferPos += PackageHeader.Length;\r
   }\r
-  \r
+\r
   if (Updated) {\r
     //\r
     // Update package list length\r
     //\r
     BufferSize = UpdateBufferPos - (UINT8 *) UpdatePackageList;\r
     WriteUnaligned32 (&UpdatePackageList->PackageLength, (UINT32) BufferSize);\r
-    \r
+\r
     //\r
     // Update Package to show form\r
     //\r
@@ -4360,14 +4468,14 @@ Finish:
   if (HiiPackageList != NULL) {\r
     FreePool (HiiPackageList);\r
   }\r
-  \r
+\r
   if (UpdatePackageList != NULL) {\r
     FreePool (UpdatePackageList);\r
   }\r
-  \r
+\r
   if (TempPackage != NULL) {\r
     FreePool (TempPackage);\r
   }\r
 \r
-  return Status; \r
+  return Status;\r
 }\r