]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SetupBrowserDxe/Ui.c
Refine the logic to handle the device path info get from string token.
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Ui.c
index a2f336c2a4bdd13d446bca0a1f2c8a1361cef9be..e16b2e424a7338106afd9dff304942294dc26d28 100644 (file)
@@ -1948,6 +1948,55 @@ FormSetGuidToHiiHandle (
   return HiiHandle;\r
 }\r
 \r
+/**\r
+  Transfer the device path string to binary format.\r
+\r
+  @param   StringPtr     The device path string info.\r
+\r
+  @retval  Device path binary info.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+ConvertDevicePathFromText (\r
+  IN CHAR16  *StringPtr\r
+  )\r
+{\r
+  UINTN                           BufferSize;\r
+  EFI_DEVICE_PATH_PROTOCOL        *DevicePath;\r
+  CHAR16                          TemStr[2];\r
+  UINT8                           *DevicePathBuffer;\r
+  UINTN                           Index;\r
+  UINT8                           DigitUint8;\r
+\r
+  ASSERT (StringPtr != NULL);\r
+\r
+  BufferSize = StrLen (StringPtr) / 2;\r
+  DevicePath = AllocatePool (BufferSize);\r
+  ASSERT (DevicePath != NULL);\r
+  \r
+  //\r
+  // Convert from Device Path String to DevicePath Buffer in the reverse order.\r
+  //\r
+  DevicePathBuffer = (UINT8 *) DevicePath;\r
+  for (Index = 0; StringPtr[Index] != L'\0'; Index ++) {\r
+    TemStr[0] = StringPtr[Index];\r
+    DigitUint8 = (UINT8) StrHexToUint64 (TemStr);\r
+    if (DigitUint8 == 0 && TemStr[0] != L'0') {\r
+      //\r
+      // Invalid Hex Char as the tail.\r
+      //\r
+      break;\r
+    }\r
+    if ((Index & 1) == 0) {\r
+      DevicePathBuffer [Index/2] = DigitUint8;\r
+    } else {\r
+      DevicePathBuffer [Index/2] = (UINT8) ((DevicePathBuffer [Index/2] << 4) + DigitUint8);\r
+    }\r
+  }\r
+\r
+  return DevicePath;\r
+}\r
+\r
 /**\r
   Process the goto op code, update the info in the selection structure.\r
 \r
@@ -1968,13 +2017,7 @@ ProcessGotoOpCode (
   )\r
 {\r
   CHAR16                          *StringPtr;\r
-  UINTN                           StringLen;\r
-  UINTN                           BufferSize;\r
   EFI_DEVICE_PATH_PROTOCOL        *DevicePath;\r
-  CHAR16                          TemStr[2];\r
-  UINT8                           *DevicePathBuffer;\r
-  UINTN                           Index;\r
-  UINT8                           DigitUint8;\r
   FORM_BROWSER_FORM               *RefForm;\r
   EFI_INPUT_KEY                   Key;\r
   EFI_STATUS                      Status;\r
@@ -1984,22 +2027,18 @@ ProcessGotoOpCode (
   Status = EFI_SUCCESS;\r
   UpdateFormInfo = TRUE;\r
   StringPtr = NULL;\r
-  StringLen = 0;\r
 \r
   //\r
   // Prepare the device path check, get the device path info first.\r
   //\r
   if (Statement->HiiValue.Value.ref.DevicePath != 0) {\r
     StringPtr = GetToken (Statement->HiiValue.Value.ref.DevicePath, Selection->FormSet->HiiHandle);\r
-    if (StringPtr != NULL) {\r
-      StringLen = StrLen (StringPtr);\r
-    }\r
   }\r
 \r
   //\r
   // Check whether the device path string is a valid string.\r
   //\r
-  if (Statement->HiiValue.Value.ref.DevicePath != 0 && StringPtr != NULL && StringLen != 0) {\r
+  if (Statement->HiiValue.Value.ref.DevicePath != 0 && StringPtr != NULL) {\r
     if (Selection->Form->ModalForm) {\r
       return Status;\r
     }\r
@@ -2007,33 +2046,11 @@ ProcessGotoOpCode (
     // Goto another Hii Package list\r
     //\r
     Selection->Action = UI_ACTION_REFRESH_FORMSET;\r
-    BufferSize = StrLen (StringPtr) / 2;\r
-    DevicePath = AllocatePool (BufferSize);\r
-    ASSERT (DevicePath != NULL);\r
-\r
-    //\r
-    // Convert from Device Path String to DevicePath Buffer in the reverse order.\r
-    //\r
-    DevicePathBuffer = (UINT8 *) DevicePath;\r
-    for (Index = 0; StringPtr[Index] != L'\0'; Index ++) {\r
-      TemStr[0] = StringPtr[Index];\r
-      DigitUint8 = (UINT8) StrHexToUint64 (TemStr);\r
-      if (DigitUint8 == 0 && TemStr[0] != L'0') {\r
-        //\r
-        // Invalid Hex Char as the tail.\r
-        //\r
-        break;\r
-      }\r
-      if ((Index & 1) == 0) {\r
-        DevicePathBuffer [Index/2] = DigitUint8;\r
-      } else {\r
-        DevicePathBuffer [Index/2] = (UINT8) ((DevicePathBuffer [Index/2] << 4) + DigitUint8);\r
-      }\r
-    }\r
-    FreePool (StringPtr);\r
+    DevicePath = ConvertDevicePathFromText (StringPtr);\r
 \r
     Selection->Handle = DevicePathToHiiHandle (DevicePath);\r
     FreePool (DevicePath);\r
+    FreePool (StringPtr);\r
 \r
     if (Selection->Handle == NULL) {\r
       //\r