]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / UefiDevicePathLib / DevicePathUtilities.c
index 7f21a60380ac5fb800015c69f0f73b34c15c8b6b..5ee3e9a31f4881c7af3840c03ee56fef4460c927 100644 (file)
@@ -8,14 +8,8 @@
   environment varibles. Multi-instance device paths should never be placed\r
   on a Handle.\r
 \r
-  Copyright (c) 2006 - 2014, 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
@@ -35,12 +29,13 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_DEVICE_PATH_PROTOCOL  mUefiDevicePathLib
 \r
 /**\r
   Determine whether a given device path is valid.\r
-  If DevicePath is NULL, then ASSERT().\r
 \r
   @param  DevicePath  A pointer to a device path data structure.\r
   @param  MaxSize     The maximum size of the device path data structure.\r
 \r
   @retval TRUE        DevicePath is valid.\r
+  @retval FALSE       DevicePath is NULL.\r
+  @retval FALSE       Maxsize is less than sizeof(EFI_DEVICE_PATH_PROTOCOL).\r
   @retval FALSE       The length of any node node in the DevicePath is less\r
                       than sizeof (EFI_DEVICE_PATH_PROTOCOL).\r
   @retval FALSE       If MaxSize is not zero, the size of the DevicePath\r
@@ -51,15 +46,24 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_DEVICE_PATH_PROTOCOL  mUefiDevicePathLib
 BOOLEAN\r
 EFIAPI\r
 IsDevicePathValid (\r
-  IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
-  IN       UINTN                    MaxSize\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,\r
+  IN       UINTN                     MaxSize\r
   )\r
 {\r
-  UINTN Count;\r
-  UINTN Size;\r
-  UINTN NodeLength;\r
+  UINTN  Count;\r
+  UINTN  Size;\r
+  UINTN  NodeLength;\r
 \r
-  ASSERT (DevicePath != NULL);\r
+  //\r
+  // Validate the input whether exists and its size big enough to touch the first node\r
+  //\r
+  if ((DevicePath == NULL) || ((MaxSize > 0) && (MaxSize < END_DEVICE_PATH_LENGTH))) {\r
+    return FALSE;\r
+  }\r
+\r
+  if (MaxSize == 0) {\r
+    MaxSize = MAX_UINTN;\r
+  }\r
 \r
   for (Count = 0, Size = 0; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) {\r
     NodeLength = DevicePathNodeLength (DevicePath);\r
@@ -67,11 +71,17 @@ IsDevicePathValid (
       return FALSE;\r
     }\r
 \r
-    if (MaxSize > 0) {\r
-      Size += NodeLength;\r
-      if (Size + END_DEVICE_PATH_LENGTH > MaxSize) {\r
-        return FALSE;\r
-      }\r
+    if (NodeLength > MAX_UINTN - Size) {\r
+      return FALSE;\r
+    }\r
+\r
+    Size += NodeLength;\r
+\r
+    //\r
+    // Validate next node before touch it.\r
+    //\r
+    if (Size > MaxSize - END_DEVICE_PATH_LENGTH ) {\r
+      return FALSE;\r
     }\r
 \r
     if (PcdGet32 (PcdMaximumDevicePathNodeCount) > 0) {\r
@@ -80,12 +90,22 @@ IsDevicePathValid (
         return FALSE;\r
       }\r
     }\r
+\r
+    //\r
+    // FilePath must be a NULL-terminated string.\r
+    //\r
+    if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&\r
+        (DevicePathSubType (DevicePath) == MEDIA_FILEPATH_DP) &&\r
+        (*(CHAR16 *)((UINT8 *)DevicePath + NodeLength - 2) != 0))\r
+    {\r
+      return FALSE;\r
+    }\r
   }\r
 \r
   //\r
   // Only return TRUE when the End Device Path node is valid.\r
   //\r
-  return (BOOLEAN) (DevicePathNodeLength (DevicePath) == END_DEVICE_PATH_LENGTH);\r
+  return (BOOLEAN)(DevicePathNodeLength (DevicePath) == END_DEVICE_PATH_LENGTH);\r
 }\r
 \r
 /**\r
@@ -135,9 +155,9 @@ DevicePathSubType (
 /**\r
   Returns the 16-bit Length field of a device path node.\r
 \r
-  Returns the 16-bit Length field of the device path node specified by Node.  \r
+  Returns the 16-bit Length field of the device path node specified by Node.\r
   Node is not required to be aligned on a 16-bit boundary, so it is recommended\r
-  that a function such as ReadUnaligned16() be used to extract the contents of \r
+  that a function such as ReadUnaligned16() be used to extract the contents of\r
   the Length field.\r
 \r
   If Node is NULL, then ASSERT().\r
@@ -160,14 +180,14 @@ DevicePathNodeLength (
 /**\r
   Returns a pointer to the next node in a device path.\r
 \r
-  Returns a pointer to the device path node that follows the device path node \r
+  Returns a pointer to the device path node that follows the device path node\r
   specified by Node.\r
 \r
   If Node is NULL, then ASSERT().\r
 \r
   @param  Node      A pointer to a device path node data structure.\r
 \r
-  @return a pointer to the device path node that follows the device path node \r
+  @return a pointer to the device path node that follows the device path node\r
   specified by Node.\r
 \r
 **/\r
@@ -178,28 +198,28 @@ NextDevicePathNode (
   )\r
 {\r
   ASSERT (Node != NULL);\r
-  return (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)(Node) + DevicePathNodeLength(Node));\r
+  return (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)(Node) + DevicePathNodeLength (Node));\r
 }\r
 \r
 /**\r
   Determines if a device path node is an end node of a device path.\r
-  This includes nodes that are the end of a device path instance and nodes that \r
+  This includes nodes that are the end of a device path instance and nodes that\r
   are the end of an entire device path.\r
 \r
-  Determines if the device path node specified by Node is an end node of a device path.  \r
-  This includes nodes that are the end of a device path instance and nodes that are the \r
-  end of an entire device path.  If Node represents an end node of a device path, \r
+  Determines if the device path node specified by Node is an end node of a device path.\r
+  This includes nodes that are the end of a device path instance and nodes that are the\r
+  end of an entire device path.  If Node represents an end node of a device path,\r
   then TRUE is returned.  Otherwise, FALSE is returned.\r
 \r
   If Node is NULL, then ASSERT().\r
 \r
   @param  Node      A pointer to a device path node data structure.\r
 \r
-  @retval TRUE      The device path node specified by Node is an end node of a \r
+  @retval TRUE      The device path node specified by Node is an end node of a\r
                     device path.\r
-  @retval FALSE     The device path node specified by Node is not an end node of \r
+  @retval FALSE     The device path node specified by Node is not an end node of\r
                     a device path.\r
-  \r
+\r
 **/\r
 BOOLEAN\r
 EFIAPI\r
@@ -208,23 +228,23 @@ IsDevicePathEndType (
   )\r
 {\r
   ASSERT (Node != NULL);\r
-  return (BOOLEAN) (DevicePathType (Node) == END_DEVICE_PATH_TYPE);\r
+  return (BOOLEAN)(DevicePathType (Node) == END_DEVICE_PATH_TYPE);\r
 }\r
 \r
 /**\r
   Determines if a device path node is an end node of an entire device path.\r
 \r
-  Determines if a device path node specified by Node is an end node of an entire \r
-  device path. If Node represents the end of an entire device path, then TRUE is \r
+  Determines if a device path node specified by Node is an end node of an entire\r
+  device path. If Node represents the end of an entire device path, then TRUE is\r
   returned.  Otherwise, FALSE is returned.\r
 \r
   If Node is NULL, then ASSERT().\r
 \r
   @param  Node      A pointer to a device path node data structure.\r
 \r
-  @retval TRUE      The device path node specified by Node is the end of an entire \r
+  @retval TRUE      The device path node specified by Node is the end of an entire\r
                     device path.\r
-  @retval FALSE     The device path node specified by Node is not the end of an \r
+  @retval FALSE     The device path node specified by Node is not the end of an\r
                     entire device path.\r
 \r
 **/\r
@@ -235,23 +255,23 @@ IsDevicePathEnd (
   )\r
 {\r
   ASSERT (Node != NULL);\r
-  return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_ENTIRE_DEVICE_PATH_SUBTYPE);\r
+  return (BOOLEAN)(IsDevicePathEndType (Node) && DevicePathSubType (Node) == END_ENTIRE_DEVICE_PATH_SUBTYPE);\r
 }\r
 \r
 /**\r
   Determines if a device path node is an end node of a device path instance.\r
 \r
-  Determines if a device path node specified by Node is an end node of a device \r
-  path instance. If Node represents the end of a device path instance, then TRUE \r
+  Determines if a device path node specified by Node is an end node of a device\r
+  path instance. If Node represents the end of a device path instance, then TRUE\r
   is returned.  Otherwise, FALSE is returned.\r
 \r
   If Node is NULL, then ASSERT().\r
 \r
   @param  Node      A pointer to a device path node data structure.\r
 \r
-  @retval TRUE      The device path node specified by Node is the end of a device \r
+  @retval TRUE      The device path node specified by Node is the end of a device\r
                     path instance.\r
-  @retval FALSE     The device path node specified by Node is not the end of a \r
+  @retval FALSE     The device path node specified by Node is not the end of a\r
                     device path instance.\r
 \r
 **/\r
@@ -262,14 +282,14 @@ IsDevicePathEndInstance (
   )\r
 {\r
   ASSERT (Node != NULL);\r
-  return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_INSTANCE_DEVICE_PATH_SUBTYPE);\r
+  return (BOOLEAN)(IsDevicePathEndType (Node) && DevicePathSubType (Node) == END_INSTANCE_DEVICE_PATH_SUBTYPE);\r
 }\r
 \r
 /**\r
   Sets the length, in bytes, of a device path node.\r
 \r
-  Sets the length of the device path node specified by Node to the value specified \r
-  by NodeLength.  NodeLength is returned.  Node is not required to be aligned on \r
+  Sets the length of the device path node specified by Node to the value specified\r
+  by NodeLength.  NodeLength is returned.  Node is not required to be aligned on\r
   a 16-bit boundary, so it is recommended that a function such as WriteUnaligned16()\r
   be used to set the contents of the Length field.\r
 \r
@@ -298,15 +318,15 @@ SetDevicePathNodeLength (
 /**\r
   Fills in all the fields of a device path node that is the end of an entire device path.\r
 \r
-  Fills in all the fields of a device path node specified by Node so Node represents \r
-  the end of an entire device path.  The Type field of Node is set to \r
-  END_DEVICE_PATH_TYPE, the SubType field of Node is set to \r
-  END_ENTIRE_DEVICE_PATH_SUBTYPE, and the Length field of Node is set to \r
-  END_DEVICE_PATH_LENGTH.  Node is not required to be aligned on a 16-bit boundary, \r
-  so it is recommended that a function such as WriteUnaligned16() be used to set \r
-  the contents of the Length field. \r
+  Fills in all the fields of a device path node specified by Node so Node represents\r
+  the end of an entire device path.  The Type field of Node is set to\r
+  END_DEVICE_PATH_TYPE, the SubType field of Node is set to\r
+  END_ENTIRE_DEVICE_PATH_SUBTYPE, and the Length field of Node is set to\r
+  END_DEVICE_PATH_LENGTH.  Node is not required to be aligned on a 16-bit boundary,\r
+  so it is recommended that a function such as WriteUnaligned16() be used to set\r
+  the contents of the Length field.\r
 \r
-  If Node is NULL, then ASSERT(). \r
+  If Node is NULL, then ASSERT().\r
 \r
   @param  Node      A pointer to a device path node data structure.\r
 \r
@@ -324,7 +344,7 @@ SetDevicePathEndNode (
 /**\r
   Returns the size of a device path in bytes.\r
 \r
-  This function returns the size, in bytes, of the device path data structure \r
+  This function returns the size, in bytes, of the device path data structure\r
   specified by DevicePath including the end of device path node.\r
   If DevicePath is NULL or invalid, then 0 is returned.\r
 \r
@@ -361,24 +381,24 @@ UefiDevicePathLibGetDevicePathSize (
   //\r
   // Compute the size and add back in the size of the end device path structure\r
   //\r
-  return ((UINTN) DevicePath - (UINTN) Start) + DevicePathNodeLength (DevicePath);\r
+  return ((UINTN)DevicePath - (UINTN)Start) + DevicePathNodeLength (DevicePath);\r
 }\r
 \r
 /**\r
   Creates a new copy of an existing device path.\r
 \r
-  This function allocates space for a new copy of the device path specified by DevicePath.  \r
-  If DevicePath is NULL, then NULL is returned.  If the memory is successfully \r
-  allocated, then the contents of DevicePath are copied to the newly allocated \r
-  buffer, and a pointer to that buffer is returned.  Otherwise, NULL is returned.  \r
-  The memory for the new device path is allocated from EFI boot services memory. \r
-  It is the responsibility of the caller to free the memory allocated. \r
-  \r
+  This function allocates space for a new copy of the device path specified by DevicePath.\r
+  If DevicePath is NULL, then NULL is returned.  If the memory is successfully\r
+  allocated, then the contents of DevicePath are copied to the newly allocated\r
+  buffer, and a pointer to that buffer is returned.  Otherwise, NULL is returned.\r
+  The memory for the new device path is allocated from EFI boot services memory.\r
+  It is the responsibility of the caller to free the memory allocated.\r
+\r
   @param  DevicePath    A pointer to a device path data structure.\r
 \r
   @retval NULL          DevicePath is NULL or invalid.\r
   @retval Others        A pointer to the duplicated device path.\r
-  \r
+\r
 **/\r
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
@@ -386,7 +406,7 @@ UefiDevicePathLibDuplicateDevicePath (
   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
   )\r
 {\r
-  UINTN                     Size;\r
+  UINTN  Size;\r
 \r
   //\r
   // Compute the size\r
@@ -406,21 +426,21 @@ UefiDevicePathLibDuplicateDevicePath (
 /**\r
   Creates a new device path by appending a second device path to a first device path.\r
 \r
-  This function creates a new device path by appending a copy of SecondDevicePath \r
-  to a copy of FirstDevicePath in a newly allocated buffer.  Only the end-of-device-path \r
-  device node from SecondDevicePath is retained. The newly created device path is \r
-  returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of \r
-  SecondDevicePath is returned.  If SecondDevicePath is NULL, then it is ignored, \r
-  and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and \r
-  SecondDevicePath are NULL, then a copy of an end-of-device-path is returned.  \r
-  \r
+  This function creates a new device path by appending a copy of SecondDevicePath\r
+  to a copy of FirstDevicePath in a newly allocated buffer.  Only the end-of-device-path\r
+  device node from SecondDevicePath is retained. The newly created device path is\r
+  returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of\r
+  SecondDevicePath is returned.  If SecondDevicePath is NULL, then it is ignored,\r
+  and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and\r
+  SecondDevicePath are NULL, then a copy of an end-of-device-path is returned.\r
+\r
   If there is not enough memory for the newly allocated buffer, then NULL is returned.\r
-  The memory for the new device path is allocated from EFI boot services memory. \r
+  The memory for the new device path is allocated from EFI boot services memory.\r
   It is the responsibility of the caller to free the memory allocated.\r
 \r
   @param  FirstDevicePath            A pointer to a device path data structure.\r
   @param  SecondDevicePath           A pointer to a device path data structure.\r
-  \r
+\r
   @retval NULL      If there is not enough memory for the newly allocated buffer.\r
   @retval NULL      If FirstDevicePath or SecondDevicePath is invalid.\r
   @retval Others    A pointer to the new device path if success.\r
@@ -430,7 +450,7 @@ UefiDevicePathLibDuplicateDevicePath (
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
 UefiDevicePathLibAppendDevicePath (\r
-  IN CONST EFI_DEVICE_PATH_PROTOCOL  *FirstDevicePath,  OPTIONAL\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *FirstDevicePath   OPTIONAL,\r
   IN CONST EFI_DEVICE_PATH_PROTOCOL  *SecondDevicePath  OPTIONAL\r
   )\r
 {\r
@@ -459,9 +479,9 @@ UefiDevicePathLibAppendDevicePath (
   // Allocate space for the combined device path. It only has one end node of\r
   // length EFI_DEVICE_PATH_PROTOCOL.\r
   //\r
-  Size1         = GetDevicePathSize (FirstDevicePath);\r
-  Size2         = GetDevicePathSize (SecondDevicePath);\r
-  Size          = Size1 + Size2 - END_DEVICE_PATH_LENGTH;\r
+  Size1 = GetDevicePathSize (FirstDevicePath);\r
+  Size2 = GetDevicePathSize (SecondDevicePath);\r
+  Size  = Size1 + Size2 - END_DEVICE_PATH_LENGTH;\r
 \r
   NewDevicePath = AllocatePool (Size);\r
 \r
@@ -470,8 +490,8 @@ UefiDevicePathLibAppendDevicePath (
     //\r
     // Over write FirstDevicePath EndNode and do the copy\r
     //\r
-    DevicePath2 = (EFI_DEVICE_PATH_PROTOCOL *) ((CHAR8 *) NewDevicePath +\r
-                  (Size1 - END_DEVICE_PATH_LENGTH));\r
+    DevicePath2 = (EFI_DEVICE_PATH_PROTOCOL *)((CHAR8 *)NewDevicePath +\r
+                                               (Size1 - END_DEVICE_PATH_LENGTH));\r
     CopyMem (DevicePath2, SecondDevicePath, Size2);\r
   }\r
 \r
@@ -481,18 +501,18 @@ UefiDevicePathLibAppendDevicePath (
 /**\r
   Creates a new path by appending the device node to the device path.\r
 \r
-  This function creates a new device path by appending a copy of the device node \r
-  specified by DevicePathNode to a copy of the device path specified by DevicePath \r
-  in an allocated buffer. The end-of-device-path device node is moved after the \r
+  This function creates a new device path by appending a copy of the device node\r
+  specified by DevicePathNode to a copy of the device path specified by DevicePath\r
+  in an allocated buffer. The end-of-device-path device node is moved after the\r
   end of the appended device node.\r
   If DevicePathNode is NULL then a copy of DevicePath is returned.\r
-  If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device \r
+  If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device\r
   path device node is returned.\r
-  If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path \r
+  If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path\r
   device node is returned.\r
-  If there is not enough memory to allocate space for the new device path, then \r
-  NULL is returned.  \r
-  The memory is allocated from EFI boot services memory. It is the responsibility \r
+  If there is not enough memory to allocate space for the new device path, then\r
+  NULL is returned.\r
+  The memory is allocated from EFI boot services memory. It is the responsibility\r
   of the caller to free the memory allocated.\r
 \r
   @param  DevicePath                 A pointer to a device path data structure.\r
@@ -500,16 +520,16 @@ UefiDevicePathLibAppendDevicePath (
 \r
   @retval NULL      If there is not enough memory for the new device path.\r
   @retval Others    A pointer to the new device path if success.\r
-                    A copy of DevicePathNode followed by an end-of-device-path node \r
+                    A copy of DevicePathNode followed by an end-of-device-path node\r
                     if both FirstDevicePath and SecondDevicePath are NULL.\r
-                    A copy of an end-of-device-path node if both FirstDevicePath \r
+                    A copy of an end-of-device-path node if both FirstDevicePath\r
                     and SecondDevicePath are NULL.\r
 \r
 **/\r
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
 UefiDevicePathLibAppendDevicePathNode (\r
-  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,     OPTIONAL\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath      OPTIONAL,\r
   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathNode  OPTIONAL\r
   )\r
 {\r
@@ -521,6 +541,7 @@ UefiDevicePathLibAppendDevicePathNode (
   if (DevicePathNode == NULL) {\r
     return DuplicateDevicePath ((DevicePath != NULL) ? DevicePath : &mUefiDevicePathLibEndDevicePath);\r
   }\r
+\r
   //\r
   // Build a Node that has a terminator on it\r
   //\r
@@ -530,6 +551,7 @@ UefiDevicePathLibAppendDevicePathNode (
   if (TempDevicePath == NULL) {\r
     return NULL;\r
   }\r
+\r
   TempDevicePath = CopyMem (TempDevicePath, DevicePathNode, NodeLength);\r
   //\r
   // Add and end device path node to convert Node to device path\r
@@ -549,20 +571,20 @@ UefiDevicePathLibAppendDevicePathNode (
 /**\r
   Creates a new device path by appending the specified device path instance to the specified device\r
   path.\r
\r
-  This function creates a new device path by appending a copy of the device path \r
-  instance specified by DevicePathInstance to a copy of the device path specified \r
+\r
+  This function creates a new device path by appending a copy of the device path\r
+  instance specified by DevicePathInstance to a copy of the device path specified\r
   by DevicePath in a allocated buffer.\r
-  The end-of-device-path device node is moved after the end of the appended device \r
-  path instance and a new end-of-device-path-instance node is inserted between. \r
+  The end-of-device-path device node is moved after the end of the appended device\r
+  path instance and a new end-of-device-path-instance node is inserted between.\r
   If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r
   If DevicePathInstance is NULL, then NULL is returned.\r
   If DevicePath or DevicePathInstance is invalid, then NULL is returned.\r
-  If there is not enough memory to allocate space for the new device path, then \r
-  NULL is returned.  \r
-  The memory is allocated from EFI boot services memory. It is the responsibility \r
+  If there is not enough memory to allocate space for the new device path, then\r
+  NULL is returned.\r
+  The memory is allocated from EFI boot services memory. It is the responsibility\r
   of the caller to free the memory allocated.\r
-  \r
+\r
   @param  DevicePath                 A pointer to a device path data structure.\r
   @param  DevicePathInstance         A pointer to a device path instance.\r
 \r
@@ -572,7 +594,7 @@ UefiDevicePathLibAppendDevicePathNode (
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
 UefiDevicePathLibAppendDevicePathInstance (\r
-  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,        OPTIONAL\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath         OPTIONAL,\r
   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathInstance OPTIONAL\r
   )\r
 {\r
@@ -593,20 +615,19 @@ UefiDevicePathLibAppendDevicePathInstance (
     return NULL;\r
   }\r
 \r
-  SrcSize       = GetDevicePathSize (DevicePath);\r
-  InstanceSize  = GetDevicePathSize (DevicePathInstance);\r
+  SrcSize      = GetDevicePathSize (DevicePath);\r
+  InstanceSize = GetDevicePathSize (DevicePathInstance);\r
 \r
   NewDevicePath = AllocatePool (SrcSize + InstanceSize);\r
   if (NewDevicePath != NULL) {\r
-    \r
-    TempDevicePath = CopyMem (NewDevicePath, DevicePath, SrcSize);;\r
\r
+    TempDevicePath = CopyMem (NewDevicePath, DevicePath, SrcSize);\r
+\r
     while (!IsDevicePathEnd (TempDevicePath)) {\r
       TempDevicePath = NextDevicePathNode (TempDevicePath);\r
     }\r
-    \r
-    TempDevicePath->SubType  = END_INSTANCE_DEVICE_PATH_SUBTYPE;\r
-    TempDevicePath           = NextDevicePathNode (TempDevicePath);\r
+\r
+    TempDevicePath->SubType = END_INSTANCE_DEVICE_PATH_SUBTYPE;\r
+    TempDevicePath          = NextDevicePathNode (TempDevicePath);\r
     CopyMem (TempDevicePath, DevicePathInstance, InstanceSize);\r
   }\r
 \r
@@ -617,25 +638,25 @@ UefiDevicePathLibAppendDevicePathInstance (
   Creates a copy of the current device path instance and returns a pointer to the next device path\r
   instance.\r
 \r
-  This function creates a copy of the current device path instance. It also updates \r
-  DevicePath to point to the next device path instance in the device path (or NULL \r
+  This function creates a copy of the current device path instance. It also updates\r
+  DevicePath to point to the next device path instance in the device path (or NULL\r
   if no more) and updates Size to hold the size of the device path instance copy.\r
   If DevicePath is NULL, then NULL is returned.\r
   If DevicePath points to a invalid device path, then NULL is returned.\r
-  If there is not enough memory to allocate space for the new device path, then \r
-  NULL is returned.  \r
-  The memory is allocated from EFI boot services memory. It is the responsibility \r
+  If there is not enough memory to allocate space for the new device path, then\r
+  NULL is returned.\r
+  The memory is allocated from EFI boot services memory. It is the responsibility\r
   of the caller to free the memory allocated.\r
   If Size is NULL, then ASSERT().\r
\r
-  @param  DevicePath                 On input, this holds the pointer to the current \r
-                                     device path instance. On output, this holds \r
-                                     the pointer to the next device path instance \r
+\r
+  @param  DevicePath                 On input, this holds the pointer to the current\r
+                                     device path instance. On output, this holds\r
+                                     the pointer to the next device path instance\r
                                      or NULL if there are no more device path\r
-                                     instances in the device path pointer to a \r
+                                     instances in the device path pointer to a\r
                                      device path data structure.\r
-  @param  Size                       On output, this holds the size of the device \r
-                                     path instance, in bytes or zero, if DevicePath \r
+  @param  Size                       On output, this holds the size of the device\r
+                                     path instance, in bytes or zero, if DevicePath\r
                                      is NULL.\r
 \r
   @return A pointer to the current device path instance.\r
@@ -644,8 +665,8 @@ UefiDevicePathLibAppendDevicePathInstance (
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
 UefiDevicePathLibGetNextDevicePathInstance (\r
-  IN OUT EFI_DEVICE_PATH_PROTOCOL    **DevicePath,\r
-  OUT UINTN                          *Size\r
+  IN OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePath,\r
+  OUT UINTN                        *Size\r
   )\r
 {\r
   EFI_DEVICE_PATH_PROTOCOL  *DevPath;\r
@@ -654,7 +675,7 @@ UefiDevicePathLibGetNextDevicePathInstance (
 \r
   ASSERT (Size != NULL);\r
 \r
-  if (DevicePath == NULL || *DevicePath == NULL) {\r
+  if ((DevicePath == NULL) || (*DevicePath == NULL)) {\r
     *Size = 0;\r
     return NULL;\r
   }\r
@@ -674,15 +695,15 @@ UefiDevicePathLibGetNextDevicePathInstance (
   //\r
   // Compute the size of the device path instance\r
   //\r
-  *Size = ((UINTN) DevPath - (UINTN) (*DevicePath)) + sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
\r
+  *Size = ((UINTN)DevPath - (UINTN)(*DevicePath)) + sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
+\r
   //\r
   // Make a copy and return the device path instance\r
   //\r
-  Temp              = DevPath->SubType;\r
-  DevPath->SubType  = END_ENTIRE_DEVICE_PATH_SUBTYPE;\r
-  ReturnValue       = DuplicateDevicePath (*DevicePath);\r
-  DevPath->SubType  = Temp;\r
+  Temp             = DevPath->SubType;\r
+  DevPath->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;\r
+  ReturnValue      = DuplicateDevicePath (*DevicePath);\r
+  DevPath->SubType = Temp;\r
 \r
   //\r
   // If DevPath is the end of an entire device path, then another instance\r
@@ -700,13 +721,13 @@ UefiDevicePathLibGetNextDevicePathInstance (
 /**\r
   Creates a device node.\r
 \r
-  This function creates a new device node in a newly allocated buffer of size \r
-  NodeLength and initializes the device path node header with NodeType and NodeSubType.  \r
+  This function creates a new device node in a newly allocated buffer of size\r
+  NodeLength and initializes the device path node header with NodeType and NodeSubType.\r
   The new device path node is returned.\r
-  If NodeLength is smaller than a device path header, then NULL is returned.  \r
-  If there is not enough memory to allocate space for the new device path, then \r
-  NULL is returned.  \r
-  The memory is allocated from EFI boot services memory. It is the responsibility \r
+  If NodeLength is smaller than a device path header, then NULL is returned.\r
+  If there is not enough memory to allocate space for the new device path, then\r
+  NULL is returned.\r
+  The memory is allocated from EFI boot services memory. It is the responsibility\r
   of the caller to free the memory allocated.\r
 \r
   @param  NodeType                   The device node type for the new device node.\r
@@ -719,12 +740,12 @@ UefiDevicePathLibGetNextDevicePathInstance (
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
 UefiDevicePathLibCreateDeviceNode (\r
-  IN UINT8                           NodeType,\r
-  IN UINT8                           NodeSubType,\r
-  IN UINT16                          NodeLength\r
+  IN UINT8   NodeType,\r
+  IN UINT8   NodeSubType,\r
+  IN UINT16  NodeLength\r
   )\r
 {\r
-  EFI_DEVICE_PATH_PROTOCOL      *DevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
 \r
   if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {\r
     //\r
@@ -732,12 +753,12 @@ UefiDevicePathLibCreateDeviceNode (
     //\r
     return NULL;\r
   }\r
\r
+\r
   DevicePath = AllocateZeroPool (NodeLength);\r
   if (DevicePath != NULL) {\r
-     DevicePath->Type    = NodeType;\r
-     DevicePath->SubType = NodeSubType;\r
-     SetDevicePathNodeLength (DevicePath, NodeLength);\r
+    DevicePath->Type    = NodeType;\r
+    DevicePath->SubType = NodeSubType;\r
+    SetDevicePathNodeLength (DevicePath, NodeLength);\r
   }\r
 \r
   return DevicePath;\r
@@ -754,7 +775,7 @@ UefiDevicePathLibCreateDeviceNode (
   @param  DevicePath                 A pointer to a device path data structure.\r
 \r
   @retval  TRUE                      DevicePath is multi-instance.\r
-  @retval  FALSE                     DevicePath is not multi-instance, or DevicePath \r
+  @retval  FALSE                     DevicePath is not multi-instance, or DevicePath\r
                                      is NULL or invalid.\r
 \r
 **/\r
@@ -764,7 +785,7 @@ UefiDevicePathLibIsDevicePathMultiInstance (
   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
   )\r
 {\r
-  CONST EFI_DEVICE_PATH_PROTOCOL     *Node;\r
+  CONST EFI_DEVICE_PATH_PROTOCOL  *Node;\r
 \r
   if (DevicePath == NULL) {\r
     return FALSE;\r
@@ -786,40 +807,6 @@ UefiDevicePathLibIsDevicePathMultiInstance (
   return FALSE;\r
 }\r
 \r
-\r
-/**\r
-  Retrieves the device path protocol from a handle.\r
-\r
-  This function returns the device path protocol from the handle specified by Handle.  \r
-  If Handle is NULL or Handle does not contain a device path protocol, then NULL \r
-  is returned.\r
\r
-  @param  Handle                     The handle from which to retrieve the device \r
-                                     path protocol.\r
-\r
-  @return The device path protocol from the handle specified by Handle.\r
-\r
-**/\r
-EFI_DEVICE_PATH_PROTOCOL *\r
-EFIAPI\r
-DevicePathFromHandle (\r
-  IN EFI_HANDLE                      Handle\r
-  )\r
-{\r
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
-  EFI_STATUS                Status;\r
-\r
-  Status = gBS->HandleProtocol (\r
-                  Handle,\r
-                  &gEfiDevicePathProtocolGuid,\r
-                  (VOID *) &DevicePath\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    DevicePath = NULL;\r
-  }\r
-  return DevicePath;\r
-}\r
-\r
 /**\r
   Allocates a device path for a file and appends it to an existing device path.\r
 \r
@@ -830,11 +817,11 @@ DevicePathFromHandle (
   path node for the file specified by FileName is allocated and returned.\r
   The memory for the new device path is allocated from EFI boot services memory. It is the responsibility\r
   of the caller to free the memory allocated.\r
-  \r
+\r
   If FileName is NULL, then ASSERT().\r
   If FileName is not aligned on a 16-bit boundary, then ASSERT().\r
 \r
-  @param  Device                     A pointer to a device handle.  This parameter \r
+  @param  Device                     A pointer to a device handle.  This parameter\r
                                      is optional and may be NULL.\r
   @param  FileName                   A pointer to a Null-terminated Unicode string.\r
 \r
@@ -844,8 +831,8 @@ DevicePathFromHandle (
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
 FileDevicePath (\r
-  IN EFI_HANDLE                      Device,     OPTIONAL\r
-  IN CONST CHAR16                    *FileName\r
+  IN EFI_HANDLE    Device      OPTIONAL,\r
+  IN CONST CHAR16  *FileName\r
   )\r
 {\r
   UINTN                     Size;\r
@@ -855,10 +842,10 @@ FileDevicePath (
 \r
   DevicePath = NULL;\r
 \r
-  Size = StrSize (FileName);\r
+  Size           = StrSize (FileName);\r
   FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + END_DEVICE_PATH_LENGTH);\r
   if (FileDevicePath != NULL) {\r
-    FilePath = (FILEPATH_DEVICE_PATH *) FileDevicePath;\r
+    FilePath                 = (FILEPATH_DEVICE_PATH *)FileDevicePath;\r
     FilePath->Header.Type    = MEDIA_DEVICE_PATH;\r
     FilePath->Header.SubType = MEDIA_FILEPATH_DP;\r
     CopyMem (&FilePath->PathName, FileName, Size);\r
@@ -875,4 +862,3 @@ FileDevicePath (
 \r
   return DevicePath;\r
 }\r
-\r