]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Code Clean up for IfrSupportLib, HiiLib, PeiExtractGuidedSectionLib and DxeExtractGui...
authorlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 18 Aug 2008 12:11:37 +0000 (12:11 +0000)
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 18 Aug 2008 12:11:37 +0000 (12:11 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5687 6f19259b-4bc3-4df7-8a09-765794883524

12 files changed:
MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.c
MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf
MdePkg/Library/HiiLib/HiiLanguage.c
MdePkg/Library/HiiLib/HiiLib.c
MdePkg/Library/HiiLib/HiiLib.inf
MdePkg/Library/HiiLib/InternalHiiLib.h
MdePkg/Library/IfrSupportLib/IfrSupportLib.inf
MdePkg/Library/IfrSupportLib/UefiIfrCommon.c [deleted file]
MdePkg/Library/IfrSupportLib/UefiIfrForm.c
MdePkg/Library/IfrSupportLib/UefiIfrLibraryInternal.h
MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.c
MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf

index b98e8f3ae96c9e726a1b3f2d954cecbac1033955..7250828744744466f7af6dffaa366916f017ef57 100644 (file)
@@ -21,7 +21,7 @@
 #include <Library/ExtractGuidedSectionLib.h>\r
 \r
 STATIC GUID                 *mExtractHandlerGuidTable;\r
-STATIC UINT32               mNumberOfExtractHandler;\r
+STATIC UINT32               mNumberOfExtractHandler = 0;\r
 \r
 STATIC EXTRACT_GUIDED_SECTION_DECODE_HANDLER   *mExtractDecodeHandlerTable;\r
 STATIC EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *mExtractGetInfoHandlerTable;\r
@@ -52,19 +52,17 @@ DxeExtractGuidedSectionLibConstructor (
   \r
   mExtractDecodeHandlerTable  = (EXTRACT_GUIDED_SECTION_DECODE_HANDLER *) AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER));\r
   if (mExtractDecodeHandlerTable == NULL) {\r
+    FreePool (mExtractHandlerGuidTable);\r
     return RETURN_OUT_OF_RESOURCES;\r
   }\r
 \r
   mExtractGetInfoHandlerTable = (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *) AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER));\r
   if (mExtractGetInfoHandlerTable == NULL) {\r
+    FreePool (mExtractHandlerGuidTable);\r
+    FreePool (mExtractDecodeHandlerTable);\r
     return RETURN_OUT_OF_RESOURCES;\r
   }\r
   \r
-  //\r
-  // the initialized number is Zero.\r
-  //\r
-  mNumberOfExtractHandler = 0;\r
-  \r
   return RETURN_SUCCESS;\r
 }\r
 \r
@@ -122,18 +120,14 @@ ExtractGuidedSectionRegisterHandlers (
   //\r
   for (Index = 0; Index < mNumberOfExtractHandler; Index ++) {\r
     if (CompareGuid (&mExtractHandlerGuidTable[Index], SectionGuid)) {\r
-      break;\r
+      //\r
+      // If the guided handler has been registered before, only update its handler.\r
+      //\r
+      mExtractDecodeHandlerTable [Index] = DecodeHandler;\r
+      mExtractGetInfoHandlerTable [Index] = GetInfoHandler;\r
+      return RETURN_SUCCESS;\r
     }\r
   }\r
-\r
-  //\r
-  // If the guided handler has been registered before, only update its handler.\r
-  //\r
-  if (Index < mNumberOfExtractHandler) {\r
-    mExtractDecodeHandlerTable [Index] = DecodeHandler;\r
-    mExtractGetInfoHandlerTable [Index] = GetInfoHandler;\r
-    return RETURN_SUCCESS;\r
-  }\r
   \r
   //\r
   // Check the global table is enough to contain new Handler.\r
@@ -197,26 +191,22 @@ ExtractGuidedSectionGetInfo (
   //\r
   for (Index = 0; Index < mNumberOfExtractHandler; Index ++) {\r
     if (CompareGuid (&mExtractHandlerGuidTable[Index], &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
-      break;\r
+      //\r
+      // Call the match handler to getinfo for the input section data.\r
+      //\r
+      return mExtractGetInfoHandlerTable [Index] (\r
+                InputSection,\r
+                OutputBufferSize,\r
+                ScratchBufferSize,\r
+                SectionAttribute\r
+              );\r
     }\r
   }\r
 \r
   //\r
   // Not found, the input guided section is not supported. \r
   //\r
-  if (Index == mNumberOfExtractHandler) {\r
-    return RETURN_UNSUPPORTED;\r
-  }\r
-\r
-  //\r
-  // Call the match handler to getinfo for the input section data.\r
-  //\r
-  return mExtractGetInfoHandlerTable [Index] (\r
-            InputSection,\r
-            OutputBufferSize,\r
-            ScratchBufferSize,\r
-            SectionAttribute\r
-          );\r
+  return RETURN_UNSUPPORTED;\r
 }\r
 \r
 /**
@@ -270,24 +260,20 @@ ExtractGuidedSectionDecode (
   //\r
   for (Index = 0; Index < mNumberOfExtractHandler; Index ++) {\r
     if (CompareGuid (&mExtractHandlerGuidTable[Index], &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
-      break;\r
+      //\r
+      // Call the match handler to extract raw data for the input section data.\r
+      //\r
+      return mExtractDecodeHandlerTable [Index] (\r
+                InputSection,\r
+                OutputBuffer,\r
+                ScratchBuffer,\r
+                AuthenticationStatus\r
+              );\r
     }\r
   }\r
 \r
   //\r
   // Not found, the input guided section is not supported. \r
   //\r
-  if (Index == mNumberOfExtractHandler) {\r
-    return RETURN_UNSUPPORTED;\r
-  }\r
-\r
-  //\r
-  // Call the match handler to extract raw data for the input section data.\r
-  //\r
-  return mExtractDecodeHandlerTable [Index] (\r
-            InputSection,\r
-            OutputBuffer,\r
-            ScratchBuffer,\r
-            AuthenticationStatus\r
-          );\r
+  return RETURN_UNSUPPORTED;\r
 }\r
index 7bed5477e0a786775384d6c24a7e9da89a1a0a44..5e288dde8ac9fb72f8f0ae7e6b478b0e7b3fe6a1 100644 (file)
@@ -44,7 +44,7 @@
   BaseMemoryLib\r
   DebugLib\r
 \r
-[FixedPcd.common]\r
+[Pcd.common]\r
   gEfiMdePkgTokenSpaceGuid.PcdMaximumGuidedExtractHandler \r
 \r
 \r
index 6948b2c331eba844e68062bc6e3e8e2ca45499d2..8c03bb993af4244352de0c0bf7d2da8139a93d32 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Language related HII Library implementation.\r
 \r
-  Copyright (c) 2006, Intel Corporation<BR>\r
+  Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
   All rights reserved. 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
@@ -128,6 +128,7 @@ HiiLibGetSupportedLanguages (
   ASSERT (IsHiiHandleRegistered (HiiHandle));\r
   //\r
   // Collect current supported Languages for given HII handle\r
+  // First try allocate 4K buffer to store the current supported languages.\r
   //\r
   BufferSize = 0x1000;\r
   LanguageString = AllocateZeroPool (BufferSize);\r
@@ -223,6 +224,7 @@ HiiLibGetSupportedSecondaryLanguages (
   ASSERT (IsHiiHandleRegistered (HiiHandle));\r
   //\r
   // Collect current supported 2nd Languages for given HII handle\r
+  // First try allocate 4K buffer to store the current supported 2nd languages.\r
   //\r
   BufferSize = 0x1000;\r
   LanguageString = AllocateZeroPool (BufferSize);\r
index efae6780bc2356d1945abeacd12c97a0e7bc7f1b..81a7241cc9dd5d20b0d810e1b442d85487fa8337 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   HII Library implementation that uses DXE protocols and services.\r
 \r
-  Copyright (c) 2006, Intel Corporation<BR>\r
+  Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
   All rights reserved. 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
 \r
 #include "InternalHiiLib.h"\r
 \r
-CONST EFI_HII_DATABASE_PROTOCOL   *mHiiDatabaseProt;\r
-CONST EFI_HII_STRING_PROTOCOL     *mHiiStringProt;\r
-BOOLEAN mHiiProtocolsInitialized = FALSE;\r
-\r
+CONST EFI_HII_DATABASE_PROTOCOL   *mHiiDatabaseProt = NULL;\r
+CONST EFI_HII_STRING_PROTOCOL     *mHiiStringProt = NULL;\r
 \r
 /**\r
 \r
@@ -31,7 +29,7 @@ LocateHiiProtocols (
 {\r
   EFI_STATUS  Status;\r
 \r
-  if (mHiiProtocolsInitialized) {\r
+  if (mHiiStringProt != NULL && mHiiDatabaseProt != NULL) {\r
     //\r
     // Only need to initialize the protocol instance once.\r
     //\r
@@ -43,8 +41,6 @@ LocateHiiProtocols (
 \r
   Status = gBS->LocateProtocol (&gEfiHiiStringProtocolGuid, NULL, (VOID **) &mHiiStringProt);\r
   ASSERT_EFI_ERROR (Status);\r
-\r
-  mHiiProtocolsInitialized = TRUE;\r
 }\r
 \r
 \r
@@ -112,7 +108,7 @@ InternalHiiLibPreparePackages (
   PackageListHeader = AllocateZeroPool (PackageListLength);\r
   ASSERT (PackageListHeader != NULL);\r
   \r
-  CopyMem (&PackageListHeader->PackageListGuid, GuidId, sizeof (EFI_GUID));\r
+  CopyGuid (&PackageListHeader->PackageListGuid, GuidId);\r
   PackageListHeader->PackageLength = PackageListLength;\r
 \r
   PackageListData = ((UINT8 *) PackageListHeader) + sizeof (EFI_HII_PACKAGE_LIST_HEADER);\r
@@ -304,6 +300,7 @@ HiiLibGetHiiHandles (
 \r
   if (Status == EFI_BUFFER_TOO_SMALL) {\r
       *HiiHandleBuffer = AllocateZeroPool (BufferLength);\r
+      ASSERT (*HiiHandleBuffer != NULL);\r
       Status = mHiiDatabaseProt->ListPackageLists (\r
                                      mHiiDatabaseProt,\r
                                      EFI_HII_PACKAGE_TYPE_ALL,\r
@@ -366,13 +363,14 @@ HiiLibExtractGuidFromHiiHandle (
     Status = mHiiDatabaseProt->ExportPackageLists (mHiiDatabaseProt, Handle, &BufferSize, HiiPackageList);\r
   }\r
   if (EFI_ERROR (Status)) {\r
+    FreePool (HiiPackageList);\r
     return Status;\r
   }\r
 \r
   //\r
   // Extract GUID\r
   //\r
-  CopyMem (Guid, &HiiPackageList->PackageListGuid, sizeof (EFI_GUID));\r
+  CopyGuid (Guid, &HiiPackageList->PackageListGuid);\r
 \r
   FreePool (HiiPackageList);\r
 \r
index f9ff028942cfe246f61cc7794e8e64632e8ef83b..f9f62645a59b77294c81c8b89acdb9df8fa35254 100644 (file)
@@ -22,7 +22,7 @@
   VERSION_STRING                 = 1.0\r
   LIBRARY_CLASS                  = HiiLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER\r
   EDK_RELEASE_VERSION            = 0x00020000\r
-  EFI_SPECIFICATION_VERSION      = 0x0002000A\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
 \r
 #\r
 #  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
   HiiLib.c\r
   HiiString.c\r
   HiiLanguage.c\r
-\r
+  InternalHiiLib.h\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
 \r
 [LibraryClasses]\r
   MemoryAllocationLib\r
+  BaseMemoryLib\r
+  BaseLib\r
   DebugLib\r
   PcdLib\r
   UefiRuntimeServicesTableLib\r
+  UefiBootServicesTableLib\r
   DevicePathLib\r
 \r
 [Protocols]\r
@@ -53,4 +56,4 @@
   gEfiGlobalVariableGuid \r
 \r
 [Pcd]\r
-  gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultPlatformLang
\ No newline at end of file
+  gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultPlatformLang\r
index c01e5b020a789137b3ab16b5d4d5beae177099a5..d80db675a2e08c3345042446414056e5a5c030b1 100644 (file)
@@ -38,8 +38,6 @@
 \r
 extern CONST EFI_HII_DATABASE_PROTOCOL         *mHiiDatabaseProt;\r
 extern CONST EFI_HII_STRING_PROTOCOL           *mHiiStringProt;\r
-extern BOOLEAN                           mHiiProtocolsInitialized;\r
-\r
 \r
 /**\r
   This function check if the Hii Handle is a valid handle registered\r
index 32e1027ae30a1d30b68616ca3c5cb420e6534ef2..6c1b86f12ba4fafeac57252e63eff3f8465d879b 100644 (file)
@@ -2,7 +2,7 @@
 #Utility functions which helps in opcode creation, HII configuration string manipulations, \r
 #pop up window creations, setup browser persistence data set and get.\r
 #\r
-# Copyright (c) 2007, Intel Corporation. All rights reserved.\r
+# Copyright (c) 2007 - 2008, Intel Corporation. All rights reserved.\r
 #\r
 #  All rights reserved. This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -21,7 +21,7 @@
   FILE_GUID                      = bf38668e-e231-4baa-99e4-8c0e4c35dca6\r
   MODULE_TYPE                    = DXE_DRIVER\r
   VERSION_STRING                 = 1.0\r
-  LIBRARY_CLASS                  = IfrSupportLib\r
+  LIBRARY_CLASS                  = IfrSupportLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER\r
   EDK_RELEASE_VERSION            = 0x00020000\r
   EFI_SPECIFICATION_VERSION      = 0x00020000\r
 \r
   DevicePathLib\r
   BaseLib\r
   UefiBootServicesTableLib\r
-  UefiRuntimeServicesTableLib\r
   BaseMemoryLib\r
   DebugLib\r
-  PcdLib\r
-\r
-[Guids]\r
-  gEfiGlobalVariableGuid                        # ALWAYS_CONSUMED\r
 \r
 [Protocols]\r
   gEfiDevicePathProtocolGuid                    # PROTOCOL ALWAYS_CONSUMED\r
-  gEfiHiiDatabaseProtocolGuid\r
-  gEfiHiiStringProtocolGuid\r
   gEfiHiiConfigRoutingProtocolGuid\r
   gEfiFormBrowser2ProtocolGuid   \r
-\r
-[Pcd]\r
-  gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultPlatformLang\r
diff --git a/MdePkg/Library/IfrSupportLib/UefiIfrCommon.c b/MdePkg/Library/IfrSupportLib/UefiIfrCommon.c
deleted file mode 100644 (file)
index 18c594f..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/** @file
-Utility functions which helps in opcode creation, HII configuration string manipulations, 
-pop up window creations, setup browser persistence data set and get.
-
-Copyright (c) 2007 - 2008, Intel Corporation
-All rights reserved. This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution.  The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include "UefiIfrLibraryInternal.h"
-
-EFI_HII_DATABASE_PROTOCOL *gIfrLibHiiDatabase;
-EFI_HII_STRING_PROTOCOL   *gIfrLibHiiString;
-
-
-/**
-  IfrSupportLib's constructor. It locates the required protocol:
-  gEfiHiiDatabaseProtocolGuid and gEfiHiiStringProtocolGuid.
-
-  @param ImageHandle     The firmware allocated handle for the EFI image.
-  
-  @param SystemTable     A pointer to the EFI System Table.
-
-  @retval EFI_SUCCESS    This function always completes successfully.
-
-**/
-EFI_STATUS
-EFIAPI
-IfrSupportLibConstructor (
-  IN EFI_HANDLE           ImageHandle,
-  IN EFI_SYSTEM_TABLE     *SystemTable
-  )
-{
-  EFI_STATUS  Status;
-
-  Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **) &gIfrLibHiiDatabase);
-  ASSERT_EFI_ERROR (Status);
-
-  Status = gBS->LocateProtocol (&gEfiHiiStringProtocolGuid, NULL, (VOID **) &gIfrLibHiiString);
-  ASSERT_EFI_ERROR (Status);
-  
-  return EFI_SUCCESS;
-}
-
-
index 504b88d46804655813f7f9e3e27d6a8e3c0b31ae..3ae15f41613bb857fd42eae063eef29f0323b854 100644 (file)
@@ -15,6 +15,40 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 
 #include "UefiIfrLibraryInternal.h"
 
+STATIC CONST EFI_FORM_BROWSER2_PROTOCOL      *mFormBrowser2     = NULL;
+STATIC CONST EFI_HII_CONFIG_ROUTING_PROTOCOL *mHiiConfigRouting = NULL;
+
+/**\r
+  This function locate FormBrowser2 protocols for later usage.\r
+
+  @return Status the status to locate protocol.\r
+**/\r
+EFI_STATUS\r
+LocateFormBrowser2Protocols (\r
+  VOID\r
+  )\r
+{
+  EFI_STATUS Status;
+  //
+  // Locate protocols for later usage
+  //
+  if (mFormBrowser2 == NULL) {
+    Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &mFormBrowser2);
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
+  }
+  
+  if (mHiiConfigRouting == NULL) {
+    Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **) &mHiiConfigRouting);
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
+  }
+
+  return EFI_SUCCESS;
+}
+
 //
 // Fake <ConfigHdr>
 //
@@ -32,6 +66,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT16 mFakeConfigHdr[] = L"GUID=00000000000
 
   @retval EFI_SUCCESS            Displayed dialog and received user interaction
   @retval EFI_INVALID_PARAMETER  One of the parameters was invalid.
+  @retval EFI_OUT_OF_RESOURCES   There is no enough available memory space.
 
 **/
 EFI_STATUS
@@ -86,13 +121,19 @@ IfrLibCreatePopUp2 (
   CurrentAttribute = ConOut->Mode->Attribute;
 
   LineBuffer = AllocateZeroPool (DimensionsWidth * sizeof (CHAR16));
-  ASSERT (LineBuffer != NULL);
+  if (LineBuffer == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
 
   //
   // Determine the largest string in the dialog box
   // Notice we are starting with 1 since String is the first string
   //
   StringArray = AllocateZeroPool (NumberOfLines * sizeof (CHAR16 *));
+  if (StringArray == NULL) {
+    FreePool (LineBuffer);
+    return EFI_OUT_OF_RESOURCES;
+  }
   LargestString = StrLen (String);
   StringArray[0] = String;
 
@@ -100,6 +141,8 @@ IfrLibCreatePopUp2 (
     StackString = VA_ARG (Marker, CHAR16 *);
 
     if (StackString == NULL) {
+      FreePool (LineBuffer);
+      FreePool (StringArray);
       return EFI_INVALID_PARAMETER;
     }
 
@@ -211,7 +254,11 @@ IfrLibCreatePopUp2 (
   ConOut->SetAttribute (ConOut, CurrentAttribute);
   ConOut->EnableCursor (ConOut, TRUE);
 
-  return Status;}
+  FreePool (LineBuffer);
+  FreePool (StringArray);
+
+  return Status;
+}
 
 
 /**
@@ -307,6 +354,7 @@ ToLower (
   @param  BufferSize             Size of the buffer in bytes.
 
   @retval EFI_SUCCESS            The function completed successfully.
+  @retval EFI_OUT_OF_RESOURCES   There is no enough available memory space.
 
 **/
 EFI_STATUS
@@ -322,6 +370,9 @@ BufferToHexString (
   UINTN       StrBufferLen;
 
   NewBuffer = AllocateCopyPool (BufferSize, Buffer);
+  if (NewBuffer == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
   SwapBuffer (NewBuffer, BufferSize);
 
   StrBufferLen = BufferSize * sizeof (CHAR16) + 1;
@@ -670,6 +721,7 @@ FindBlockName (
 
   @retval EFI_SUCCESS            Routine success.
   @retval EFI_BUFFER_TOO_SMALL   The intput buffer is too small.
+  @retval EFI_OUT_OF_RESOURCES   There is no enough available memory space.
 
 **/
 EFI_STATUS
@@ -688,18 +740,11 @@ GetBrowserData (
   UINTN                           HeaderLen;
   UINTN                           BufferLen;
   CHAR16                          *Progress;
-  EFI_FORM_BROWSER2_PROTOCOL      *FormBrowser2;
-  EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
 
   //
   // Locate protocols for use
   //
-  Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &FormBrowser2);
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **) &HiiConfigRouting);
+  Status = LocateFormBrowser2Protocols ();
   if (EFI_ERROR (Status)) {
     return Status;
   }
@@ -709,16 +754,22 @@ GetBrowserData (
   //
   ConfigHdr = mFakeConfigHdr;
   HeaderLen = StrLen (ConfigHdr);
-
+  
+  //
+  // First try allocate 0x4000 buffer for the formet storage data.
+  //
   BufferLen = 0x4000;
   ConfigResp = AllocateZeroPool (BufferLen + HeaderLen);
+  if (ConfigResp == NULL) {
+    BufferLen = 0;
+  }
 
   StringPtr = ConfigResp + HeaderLen;
   *StringPtr = L'&';
   StringPtr++;
 
-  Status = FormBrowser2->BrowserCallback (
-                           FormBrowser2,
+  Status = mFormBrowser2->BrowserCallback (
+                           mFormBrowser2,
                            &BufferLen,
                            StringPtr,
                            TRUE,
@@ -726,15 +777,21 @@ GetBrowserData (
                            VariableName
                            );
   if (Status == EFI_BUFFER_TOO_SMALL) {
-    FreePool (ConfigResp);
+    if (ConfigResp != NULL) {
+      FreePool (ConfigResp);
+    }
+
     ConfigResp = AllocateZeroPool (BufferLen + HeaderLen);
+    if (ConfigResp == NULL) {
+      return EFI_OUT_OF_RESOURCES;
+    }
 
     StringPtr = ConfigResp + HeaderLen;
     *StringPtr = L'&';
     StringPtr++;
 
-    Status = FormBrowser2->BrowserCallback (
-                             FormBrowser2,
+    Status = mFormBrowser2->BrowserCallback (
+                             mFormBrowser2,
                              &BufferLen,
                              StringPtr,
                              TRUE,
@@ -751,8 +808,8 @@ GetBrowserData (
   //
   // Convert <ConfigResp> to buffer data
   //
-  Status = HiiConfigRouting->ConfigToBlock (
-                               HiiConfigRouting,
+  Status = mHiiConfigRouting->ConfigToBlock (
+                               mHiiConfigRouting,
                                ConfigResp,
                                Buffer,
                                BufferSize,
@@ -780,6 +837,7 @@ GetBrowserData (
                                  &OFFSET=<Number>&WIDTH=<Number>*
 
   @retval EFI_SUCCESS            Routine success.
+  @retval EFI_OUT_OF_RESOURCES   There is no enough available memory space.
   @retval Other                  Updating Browser uncommitted data failed.
 
 **/
@@ -800,8 +858,6 @@ SetBrowserData (
   UINTN                           HeaderLen;
   UINTN                           BufferLen;
   CHAR16                          *Progress;
-  EFI_FORM_BROWSER2_PROTOCOL      *FormBrowser2;
-  EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
   CHAR16                          BlockName[33];
   CHAR16                          *ConfigRequest;
   CHAR16                          *Request;
@@ -809,12 +865,7 @@ SetBrowserData (
   //
   // Locate protocols for use
   //
-  Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &FormBrowser2);
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **) &HiiConfigRouting);
+  Status = LocateFormBrowser2Protocols ();
   if (EFI_ERROR (Status)) {
     return Status;
   }
@@ -846,6 +897,9 @@ SetBrowserData (
 
   BufferLen = HeaderLen * sizeof (CHAR16) + StrSize (Request);
   ConfigRequest = AllocateZeroPool (BufferLen);
+  if (ConfigRequest == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
 
   CopyMem (ConfigRequest, ConfigHdr, HeaderLen * sizeof (CHAR16));
   StringPtr = ConfigRequest + HeaderLen;
@@ -854,8 +908,8 @@ SetBrowserData (
   //
   // Convert buffer to <ConfigResp>
   //
-  Status = HiiConfigRouting->BlockToConfig (
-                                HiiConfigRouting,
+  Status = mHiiConfigRouting->BlockToConfig (
+                                mHiiConfigRouting,
                                 ConfigRequest,
                                 Buffer,
                                 BufferSize,
@@ -863,7 +917,7 @@ SetBrowserData (
                                 &Progress
                                 );
   if (EFI_ERROR (Status)) {
-    FreePool (ConfigResp);
+    FreePool (ConfigRequest);
     return Status;
   }
 
@@ -875,14 +929,14 @@ SetBrowserData (
   //
   // Change uncommitted data in Browser
   //
-  Status = FormBrowser2->BrowserCallback (
-                           FormBrowser2,
+  Status = mFormBrowser2->BrowserCallback (
+                           mFormBrowser2,
                            &BufferSize,
                            StringPtr,
                            FALSE,
                            NULL,
                            NULL
                            );
-  FreePool (ConfigResp);
+  FreePool (ConfigRequest);
   return Status;
 }
index 34a0cf1260b111532e766848b0b4dbed52363788..1cdb36c78d8bf699a878ea544d4f2a6da4a04770 100644 (file)
@@ -2,7 +2,7 @@
 Utility functions which helps in opcode creation, HII configuration string manipulations, 
 pop up window creations, setup browser persistence data set and get.
 
-Copyright (c) 2007, Intel Corporation
+Copyright (c) 2007 - 2008, Intel Corporation
 All rights reserved. This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -20,19 +20,16 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 
 #include <PiDxe.h>
 
-#include <Guid/GlobalVariable.h>
 #include <Protocol/DevicePath.h>
 
 #include <Library/DebugLib.h>
 #include <Library/BaseMemoryLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
 #include <Library/UefiBootServicesTableLib.h>
 #include <Library/BaseLib.h>
 #include <Library/DevicePathLib.h>
 #include <Library/MemoryAllocationLib.h>
 #include <Library/IfrSupportLib.h>
-#include <Library/HiiLib.h>
-#include <Library/PcdLib.h>
+
 
 #endif
 
index 2b09c46cc9d9151986d194f461f82fd8cf8ceea3..72add417b66ba4cc086ffaf60281640512e99fe9 100644 (file)
@@ -196,19 +196,15 @@ ExtractGuidedSectionRegisterHandlers (
   //\r
   for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index ++) {\r
     if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, SectionGuid)) {\r
-      break;\r
+      //\r
+      // If the guided handler has been registered before, only update its handler.\r
+      //\r
+      HandlerInfo->ExtractDecodeHandlerTable [Index] = DecodeHandler;\r
+      HandlerInfo->ExtractGetInfoHandlerTable [Index] = GetInfoHandler;\r
+      return RETURN_SUCCESS;\r
     }\r
   }\r
 \r
-  //\r
-  // If the guided handler has been registered before, only update its handler.\r
-  //\r
-  if (Index < HandlerInfo->NumberOfExtractHandler) {\r
-    HandlerInfo->ExtractDecodeHandlerTable [Index] = DecodeHandler;\r
-    HandlerInfo->ExtractGetInfoHandlerTable [Index] = GetInfoHandler;\r
-    return RETURN_SUCCESS;\r
-  }\r
-\r
   //\r
   // Check the global table is enough to contain new Handler.\r
   //\r
@@ -284,26 +280,22 @@ ExtractGuidedSectionGetInfo (
   //\r
   for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index ++) {\r
     if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
-      break;\r
+      //\r
+      // Call the match handler to getinfo for the input section data.\r
+      //\r
+      return HandlerInfo->ExtractGetInfoHandlerTable [Index] (\r
+                InputSection,\r
+                OutputBufferSize,\r
+                ScratchBufferSize,\r
+                SectionAttribute\r
+              );\r
     }\r
   }\r
 \r
   //\r
   // Not found, the input guided section is not supported. \r
   //\r
-  if (Index == HandlerInfo->NumberOfExtractHandler) {\r
-    return RETURN_UNSUPPORTED;\r
-  }\r
-\r
-  //\r
-  // Call the match handler to getinfo for the input section data.\r
-  //\r
-  return HandlerInfo->ExtractGetInfoHandlerTable [Index] (\r
-            InputSection,\r
-            OutputBufferSize,\r
-            ScratchBufferSize,\r
-            SectionAttribute\r
-          );\r
+  return RETURN_UNSUPPORTED;\r
 }\r
 \r
 /**
@@ -366,24 +358,20 @@ ExtractGuidedSectionDecode (
   //\r
   for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index ++) {\r
     if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
-      break;\r
+      //\r
+      // Call the match handler to extract raw data for the input guided section.\r
+      //\r
+      return HandlerInfo->ExtractDecodeHandlerTable [Index] (\r
+                InputSection,\r
+                OutputBuffer,\r
+                ScratchBuffer,\r
+                AuthenticationStatus\r
+              );\r
     }\r
   }\r
 \r
   //\r
   // Not found, the input guided section is not supported. \r
   //\r
-  if (Index == HandlerInfo->NumberOfExtractHandler) {\r
-    return RETURN_UNSUPPORTED;\r
-  }\r
-\r
-  //\r
-  // Call the match handler to extract raw data for the input guided section.\r
-  //\r
-  return HandlerInfo->ExtractDecodeHandlerTable [Index] (\r
-            InputSection,\r
-            OutputBuffer,\r
-            ScratchBuffer,\r
-            AuthenticationStatus\r
-          );\r
+  return RETURN_UNSUPPORTED;\r
 }\r
index d0853d261e947d55efb14e2b051f663f87ab6a60..b84ee05581b5d810fc0b9c6bf9638321484bd987 100644 (file)
@@ -42,7 +42,7 @@
   DebugLib\r
   HobLib\r
 \r
-[FixedPcd.common]\r
+[Pcd.common]\r
   gEfiMdePkgTokenSpaceGuid.PcdMaximumGuidedExtractHandler \r
 \r
 \r