]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.c
Fix one minor comment issue in last check-in
[mirror_edk2.git] / MdePkg / Library / UefiDevicePathLib / UefiDevicePathLib.c
index bdc512b495ae616d92a7cd600e37173917636dce..7869499a83f2f99d9ae1fde495d1d943bc41e47b 100644 (file)
   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:  UefiDevicePathLib.c\r
-\r
 **/\r
 \r
+\r
+#include <Uefi.h>\r
+\r
+#include <Protocol/DevicePath.h>\r
+\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/BaseLib.h>\r
+\r
 //\r
-// Include common header file for this module.\r
+// Template for an end-of-device path node.\r
 //\r
-#include "CommonHeader.h"\r
+STATIC EFI_DEVICE_PATH_PROTOCOL  mEndDevicePath[] = {\r
+  END_DEVICE_PATH_TYPE,\r
+  END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+  END_DEVICE_PATH_LENGTH,\r
+  0\r
+};\r
 \r
 /**\r
   Returns the size of a device path in bytes.\r
@@ -109,7 +124,8 @@ DuplicateDevicePath (
   SecondDevicePath is retained. The newly created device path is returned.  \r
   If FirstDevicePath is NULL, then it is ignored, and a duplicate of SecondDevicePath is returned.  \r
   If SecondDevicePath is NULL, then it is ignored, and a duplicate of FirstDevicePath is returned.  \r
-  If both FirstDevicePath and SecondDevicePath are NULL, then NULL is returned.  \r
+  If both FirstDevicePath and SecondDevicePath are NULL, then a copy of an end-of-device-path is\r
+  returned.  \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. It is the\r
   responsibility of the caller to free the memory allocated.\r
@@ -137,7 +153,7 @@ AppendDevicePath (
   // If there's only 1 path, just duplicate it.\r
   //\r
   if (FirstDevicePath == NULL) {\r
-    return DuplicateDevicePath (SecondDevicePath);\r
+    return DuplicateDevicePath ((SecondDevicePath != NULL) ? SecondDevicePath : mEndDevicePath);\r
   }\r
 \r
   if (SecondDevicePath == NULL) {\r
@@ -173,8 +189,11 @@ AppendDevicePath (
   This function creates a new device path by appending a copy of the device node specified by\r
   DevicePathNode to a copy of the device path specified by DevicePath in an allocated buffer.\r
   The end-of-device-path device node is moved after the end of the appended device node.\r
-  If DevicePath is NULL, then NULL is returned.\r
-  If DevicePathNode is NULL, then NULL is returned.\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 path device\r
+  node is returned.\r
+  If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path device node\r
+  is returned.\r
   If there is not enough memory to allocate space for the new device path, then NULL is returned.  \r
   The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
   free the memory allocated.\r
@@ -197,8 +216,8 @@ AppendDevicePathNode (
   EFI_DEVICE_PATH_PROTOCOL  *NewDevicePath;\r
   UINTN                     NodeLength;\r
 \r
-  if (DevicePath == NULL || DevicePathNode == NULL) {\r
-    return NULL;\r
+  if (DevicePathNode == NULL) {\r
+    return DuplicateDevicePath ((DevicePath != NULL) ? DevicePath : mEndDevicePath);\r
   }\r
   //\r
   // Build a Node that has a terminator on it\r