]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/PlatformDriverOverride/PlatOverMngr/PlatOverMngr.c
Correct typo in comments, clean IfrSupportLib.h
[mirror_edk2.git] / MdeModulePkg / Universal / PlatformDriverOverride / PlatOverMngr / PlatOverMngr.c
index ebd9d18efbf29e534c57073a0fd349eecb04ddc4..24abaa654bd3ad3e4c71f91e0adf6cc5abb62f2a 100644 (file)
@@ -1,20 +1,5 @@
 /** @file\r
 \r
-Copyright (c) 2007 - 2008, Intel Corporation\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
-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
-\r
-Module Name:\r
-\r
-  PlatOverMngr.c\r
-\r
-Abstract:\r
-\r
   A UI application to offer a UI interface in device manager to let user configue\r
   platform override protocol to override the default algorithm for matching\r
   drivers to controllers.\r
@@ -27,6 +12,15 @@ Abstract:
   4. The UI application save all the mapping info in NV variables which will be consumed\r
      by platform override protocol driver to publish the platform override protocol.\r
 \r
+Copyright (c) 2007 - 2008, Intel Corporation\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
+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
+\r
 **/\r
 \r
 #include <PiDxe.h>\r
@@ -42,6 +36,7 @@ Abstract:
 #include <Protocol/ComponentName2.h>\r
 #include <Protocol/ComponentName.h>\r
 #include <Protocol/DriverBinding.h>\r
+#include <Guid/GlobalVariable.h>\r
 \r
 #include <Library/BaseLib.h>\r
 #include <Library/DebugLib.h>\r
@@ -119,30 +114,33 @@ ConvertComponentNameSupportLanguage (
   IN CHAR8                           *Language\r
   )\r
 {\r
-  CHAR8                              *LangCode;\r
-  LangCode           = NULL;\r
+  CHAR8    *LangCode;\r
+  LangCode = NULL;\r
 \r
   //\r
-  // check the input language is English\r
+  // Check the input language is English\r
   //\r
   if (AsciiStrnCmp (Language, "en-", 3) != 0) {\r
     return NULL;\r
   }\r
-\r
-  //\r
-  // Convert Language string from RFC 3066 to ISO 639-2\r
-  //\r
-  LangCode = AllocateZeroPool(4);\r
-  AsciiStrCpy (LangCode, "eng");\r
   \r
   //\r
-  // Check whether the converted language is supported in the SupportedLanguages list.\r
+  // Check SupportedLanguages format\r
   //\r
-  if (AsciiStrStr (SupportedLanguages, LangCode) == NULL) {\r
-    FreePool (LangCode);\r
-    return NULL;\r
+  if (AsciiStrStr (SupportedLanguages, "en-") != NULL) {\r
+    //\r
+    // Create RFC 3066 language\r
+    //\r
+    LangCode = AllocateZeroPool(AsciiStrSize (Language));\r
+    AsciiStrCpy (LangCode, Language);\r
+  } else if (AsciiStrStr (SupportedLanguages, "en") != NULL) {\r
+    //\r
+    // Create ISO 639-2 Language\r
+    //\r
+    LangCode = AllocateZeroPool(4);\r
+    AsciiStrCpy (LangCode, "eng");    \r
   }\r
-\r
+  \r
   return LangCode;\r
 }\r
 \r
@@ -193,12 +191,14 @@ GetComponentName (
   if (ComponentName != NULL) {\r
     if (ComponentName->GetDriverName != NULL) {\r
       SupportedLanguage = ConvertComponentNameSupportLanguage (ComponentName->SupportedLanguages, mLanguage);\r
-      Status = ComponentName->GetDriverName (\r
-                                ComponentName,\r
-                                SupportedLanguage,\r
-                                &DriverName\r
-                                );\r
-      FreePool (SupportedLanguage);\r
+      if (SupportedLanguage != NULL) {\r
+        Status = ComponentName->GetDriverName (\r
+                                  ComponentName,\r
+                                  SupportedLanguage,\r
+                                  &DriverName\r
+                                  );\r
+        FreePool (SupportedLanguage);\r
+      }\r
     }\r
   } else if (ComponentName2 != NULL) {\r
     if (ComponentName2->GetDriverName != NULL) {\r
@@ -468,6 +468,7 @@ UpdateDeviceSelectPage (
     //\r
     Len = StrSize (ControllerName);\r
     NewString = AllocateZeroPool (Len + StrSize (L"--"));\r
+    ASSERT (NewString != NULL);\r
     if (EFI_ERROR (CheckMapping (ControllerDevicePath,NULL, &mMappingDataBase, NULL, NULL))) {\r
       StrCat (NewString, L"--");\r
     } else {\r
@@ -554,7 +555,10 @@ GetDriverBindingHandleFromImageHandle (
   if (EFI_ERROR (Status) || (DriverBindingHandleCount == 0)) {\r
     return NULL;\r
   }\r
-\r
+  \r
+  //\r
+  // Get the first Driver Binding handle which has the specific image handle.\r
+  //\r
   for (Index = 0; Index < DriverBindingHandleCount; Index++) {\r
     DriverBindingInterface = NULL;\r
     Status = gBS->OpenProtocol (\r
@@ -575,9 +579,6 @@ GetDriverBindingHandleFromImageHandle (
     }\r
   }\r
 \r
-  //\r
-  // If no Driver Binding Protocol instance is found\r
-  //\r
   FreePool (DriverBindingHandleBuffer);\r
   return DriverBindingHandle;\r
 }\r
@@ -588,6 +589,7 @@ GetDriverBindingHandleFromImageHandle (
 \r
   @param  Private        Pointer to EFI_CALLBACK_INFO.\r
   @param  KeyValue       The callback key value of device controller item in first page.\r
+                         KeyValue is larger than or equal to KEY_VALUE_DEVICE_OFFSET.\r
   @param  FakeNvData     Pointer to PLAT_OVER_MNGR_DATA.\r
 \r
   @retval EFI_SUCCESS    Always returned.\r
@@ -762,6 +764,7 @@ UpdateBindingDriverSelectPage (
     // First create the driver image name\r
     //\r
     NewString = AllocateZeroPool (StrSize (DriverName));\r
+    ASSERT (NewString != NULL); \r
     if (EFI_ERROR (CheckMapping (mControllerDevicePathProtocol[mSelectedCtrIndex], LoadedImageDevicePath, &mMappingDataBase, NULL, NULL))) {\r
       FakeNvData->DriSelection[Index] = 0x00;\r
     } else {\r
@@ -788,6 +791,7 @@ UpdateBindingDriverSelectPage (
     DriverName = DevicePathToStr (LoadedImageDevicePath);\r
 \r
     NewString = AllocateZeroPool (StrSize (DriverName));\r
+    ASSERT (NewString != NULL); \r
     StrCat (NewString, DriverName);\r
     NewStringHelpToken = mDriverImageFilePathToken[Index];\r
     if (NewStringHelpToken == 0) {\r
@@ -894,7 +898,7 @@ UpdatePrioritySelectPage (
   }\r
   \r
   IfrOptionList = AllocateZeroPool (sizeof (IFR_OPTION) * mSelectedDriverImageNum);\r
-  ASSERT_EFI_ERROR (IfrOptionList != NULL);\r
+  ASSERT (IfrOptionList != NULL);\r
   //\r
   // Create order list for those selected drivers\r
   //\r
@@ -1226,7 +1230,7 @@ PlatOverMngrCallback (
     ASSERT_EFI_ERROR (Status);\r
   }\r
 \r
-  if (((KEY_VALUE_DEVICE_OFFSET <= KeyValue) && (KeyValue < KEY_VALUE_DEVICE_MAX)) || (KeyValue == KEY_VALUE_ORDER_GOTO_PREVIOUS)) {\r
+  if (((KeyValue >= KEY_VALUE_DEVICE_OFFSET) && (KeyValue < KEY_VALUE_DEVICE_MAX)) || (KeyValue == KEY_VALUE_ORDER_GOTO_PREVIOUS)) {\r
     if (KeyValue == KEY_VALUE_ORDER_GOTO_PREVIOUS) {\r
       KeyValue = (EFI_QUESTION_ID) (mSelectedCtrIndex + KEY_VALUE_DEVICE_OFFSET);\r
     }\r
@@ -1299,7 +1303,7 @@ PlatOverMngrInit (
   EFI_CALLBACK_INFO           *CallbackInfo;\r
   EFI_HANDLE                  DriverHandle;\r
   EFI_FORM_BROWSER2_PROTOCOL       *FormBrowser2;\r
-\r
+  \r
   //\r
   // There should only be one HII protocol\r
   //\r
@@ -1339,7 +1343,7 @@ PlatOverMngrInit (
   //\r
   Status = HiiLibCreateHiiDriverHandle (&DriverHandle);\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Finish;\r
   }\r
   CallbackInfo->DriverHandle = DriverHandle;\r
 \r
@@ -1353,7 +1357,7 @@ PlatOverMngrInit (
                   &CallbackInfo->ConfigAccess\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Finish;\r
   }\r
 \r
   //\r
@@ -1375,6 +1379,10 @@ PlatOverMngrInit (
                            );\r
   FreePool (PackageList);\r
 \r
+  if (EFI_ERROR (Status)) {\r
+    goto Finish;\r
+  }\r
+\r
   //\r
   // Locate ConfigRouting protocol\r
   //\r
@@ -1384,7 +1392,7 @@ PlatOverMngrInit (
                   (VOID **) &CallbackInfo->HiiConfigRouting\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Finish;\r
   }\r
 \r
   //\r
@@ -1409,11 +1417,24 @@ PlatOverMngrInit (
                            NULL,\r
                            NULL\r
                            );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Finish;\r
+  }\r
 \r
   Status = HiiDatabase->RemovePackageList (HiiDatabase, CallbackInfo->RegisteredHandle);\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Finish;\r
   }\r
-\r
+  \r
   return EFI_SUCCESS;\r
+\r
+Finish:\r
+  if (CallbackInfo->DriverHandle != NULL) {\r
+    HiiLibDestroyHiiDriverHandle (CallbackInfo->DriverHandle);\r
+  }\r
+  if (CallbackInfo != NULL) {\r
+    FreePool (CallbackInfo);\r
+  }\r
+\r
+  return Status;\r
 }\r