summaryrefslogtreecommitdiffstats
path: root/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c
diff options
context:
space:
mode:
Diffstat (limited to 'MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c')
-rw-r--r--MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c89
1 files changed, 48 insertions, 41 deletions
diff --git a/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c b/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c
index 8fdd9490b5..4ff9308a68 100644
--- a/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c
+++ b/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c
@@ -7,7 +7,6 @@
**/
-
#include <Uefi.h>
#include <Protocol/DevicePathUtilities.h>
@@ -22,9 +21,9 @@
#include <Library/UefiBootServicesTableLib.h>
#include <Library/PcdLib.h>
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_UTILITIES_PROTOCOL *mDevicePathLibDevicePathUtilities = NULL;
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *mDevicePathLibDevicePathToText = NULL;
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *mDevicePathLibDevicePathFromText = NULL;
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_UTILITIES_PROTOCOL *mDevicePathLibDevicePathUtilities = NULL;
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *mDevicePathLibDevicePathToText = NULL;
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *mDevicePathLibDevicePathFromText = NULL;
//
// Template for an end-of-device path node.
@@ -53,16 +52,16 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_DEVICE_PATH_PROTOCOL mUefiDevicePathLib
EFI_STATUS
EFIAPI
DevicePathLibConstructor (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
Status = gBS->LocateProtocol (
&gEfiDevicePathUtilitiesProtocolGuid,
NULL,
- (VOID**) &mDevicePathLibDevicePathUtilities
+ (VOID **)&mDevicePathLibDevicePathUtilities
);
ASSERT_EFI_ERROR (Status);
ASSERT (mDevicePathLibDevicePathUtilities != NULL);
@@ -87,13 +86,13 @@ DevicePathLibConstructor (
BOOLEAN
EFIAPI
IsDevicePathValid (
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
- IN UINTN MaxSize
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
+ IN UINTN MaxSize
)
{
- UINTN Count;
- UINTN Size;
- UINTN NodeLength;
+ UINTN Count;
+ UINTN Size;
+ UINTN NodeLength;
ASSERT (DevicePath != NULL);
@@ -117,6 +116,7 @@ IsDevicePathValid (
if (NodeLength > MAX_UINTN - Size) {
return FALSE;
}
+
Size += NodeLength;
//
@@ -136,9 +136,10 @@ IsDevicePathValid (
//
// FilePath must be a NULL-terminated string.
//
- if (DevicePathType (DevicePath) == MEDIA_DEVICE_PATH &&
- DevicePathSubType (DevicePath) == MEDIA_FILEPATH_DP &&
- *(CHAR16 *)((UINT8 *)DevicePath + NodeLength - 2) != 0) {
+ if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&
+ (DevicePathSubType (DevicePath) == MEDIA_FILEPATH_DP) &&
+ (*(CHAR16 *)((UINT8 *)DevicePath + NodeLength - 2) != 0))
+ {
return FALSE;
}
}
@@ -146,7 +147,7 @@ IsDevicePathValid (
//
// Only return TRUE when the End Device Path node is valid.
//
- return (BOOLEAN) (DevicePathNodeLength (DevicePath) == END_DEVICE_PATH_LENGTH);
+ return (BOOLEAN)(DevicePathNodeLength (DevicePath) == END_DEVICE_PATH_LENGTH);
}
/**
@@ -239,7 +240,7 @@ NextDevicePathNode (
)
{
ASSERT (Node != NULL);
- return (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)(Node) + DevicePathNodeLength(Node));
+ return (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)(Node) + DevicePathNodeLength (Node));
}
/**
@@ -268,7 +269,7 @@ IsDevicePathEndType (
)
{
ASSERT (Node != NULL);
- return (BOOLEAN) (DevicePathType (Node) == END_DEVICE_PATH_TYPE);
+ return (BOOLEAN)(DevicePathType (Node) == END_DEVICE_PATH_TYPE);
}
/**
@@ -294,7 +295,7 @@ IsDevicePathEnd (
)
{
ASSERT (Node != NULL);
- return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_ENTIRE_DEVICE_PATH_SUBTYPE);
+ return (BOOLEAN)(IsDevicePathEndType (Node) && DevicePathSubType (Node) == END_ENTIRE_DEVICE_PATH_SUBTYPE);
}
/**
@@ -322,7 +323,7 @@ IsDevicePathEndInstance (
)
{
ASSERT (Node != NULL);
- return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_INSTANCE_DEVICE_PATH_SUBTYPE);
+ return (BOOLEAN)(IsDevicePathEndType (Node) && DevicePathSubType (Node) == END_INSTANCE_DEVICE_PATH_SUBTYPE);
}
/**
@@ -564,8 +565,8 @@ AppendDevicePathInstance (
EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
GetNextDevicePathInstance (
- IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
- OUT UINTN *Size
+ IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
+ OUT UINTN *Size
)
{
ASSERT (Size != NULL);
@@ -594,9 +595,9 @@ GetNextDevicePathInstance (
EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
CreateDeviceNode (
- IN UINT8 NodeType,
- IN UINT8 NodeSubType,
- IN UINT16 NodeLength
+ IN UINT8 NodeType,
+ IN UINT8 NodeSubType,
+ IN UINT16 NodeLength
)
{
return mDevicePathLibDevicePathUtilities->CreateDeviceNode (NodeType, NodeSubType, NodeLength);
@@ -642,7 +643,7 @@ IsDevicePathMultiInstance (
EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
DevicePathFromHandle (
- IN EFI_HANDLE Handle
+ IN EFI_HANDLE Handle
)
{
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
@@ -651,11 +652,12 @@ DevicePathFromHandle (
Status = gBS->HandleProtocol (
Handle,
&gEfiDevicePathProtocolGuid,
- (VOID *) &DevicePath
+ (VOID *)&DevicePath
);
if (EFI_ERROR (Status)) {
DevicePath = NULL;
}
+
return DevicePath;
}
@@ -684,8 +686,8 @@ DevicePathFromHandle (
EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
FileDevicePath (
- IN EFI_HANDLE Device OPTIONAL,
- IN CONST CHAR16 *FileName
+ IN EFI_HANDLE Device OPTIONAL,
+ IN CONST CHAR16 *FileName
)
{
UINTN Size;
@@ -695,10 +697,10 @@ FileDevicePath (
DevicePath = NULL;
- Size = StrSize (FileName);
+ Size = StrSize (FileName);
FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + END_DEVICE_PATH_LENGTH);
if (FileDevicePath != NULL) {
- FilePath = (FILEPATH_DEVICE_PATH *) FileDevicePath;
+ FilePath = (FILEPATH_DEVICE_PATH *)FileDevicePath;
FilePath->Header.Type = MEDIA_DEVICE_PATH;
FilePath->Header.SubType = MEDIA_FILEPATH_DP;
CopyMem (&FilePath->PathName, FileName, Size);
@@ -725,15 +727,16 @@ FileDevicePath (
**/
VOID *
UefiDevicePathLibLocateProtocol (
- EFI_GUID *ProtocolGuid
+ EFI_GUID *ProtocolGuid
)
{
- EFI_STATUS Status;
- VOID *Protocol;
+ EFI_STATUS Status;
+ VOID *Protocol;
+
Status = gBS->LocateProtocol (
ProtocolGuid,
NULL,
- (VOID**) &Protocol
+ (VOID **)&Protocol
);
if (EFI_ERROR (Status)) {
return NULL;
@@ -768,6 +771,7 @@ ConvertDeviceNodeToText (
if (mDevicePathLibDevicePathToText == NULL) {
mDevicePathLibDevicePathToText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathToTextProtocolGuid);
}
+
if (mDevicePathLibDevicePathToText != NULL) {
return mDevicePathLibDevicePathToText->ConvertDeviceNodeToText (DeviceNode, DisplayOnly, AllowShortcuts);
} else {
@@ -793,14 +797,15 @@ ConvertDeviceNodeToText (
CHAR16 *
EFIAPI
ConvertDevicePathToText (
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
- IN BOOLEAN DisplayOnly,
- IN BOOLEAN AllowShortcuts
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
+ IN BOOLEAN DisplayOnly,
+ IN BOOLEAN AllowShortcuts
)
{
if (mDevicePathLibDevicePathToText == NULL) {
mDevicePathLibDevicePathToText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathToTextProtocolGuid);
}
+
if (mDevicePathLibDevicePathToText != NULL) {
return mDevicePathLibDevicePathToText->ConvertDevicePathToText (DevicePath, DisplayOnly, AllowShortcuts);
} else {
@@ -822,12 +827,13 @@ ConvertDevicePathToText (
EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
ConvertTextToDeviceNode (
- IN CONST CHAR16 *TextDeviceNode
+ IN CONST CHAR16 *TextDeviceNode
)
{
if (mDevicePathLibDevicePathFromText == NULL) {
mDevicePathLibDevicePathFromText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathFromTextProtocolGuid);
}
+
if (mDevicePathLibDevicePathFromText != NULL) {
return mDevicePathLibDevicePathFromText->ConvertTextToDeviceNode (TextDeviceNode);
} else {
@@ -850,12 +856,13 @@ ConvertTextToDeviceNode (
EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
ConvertTextToDevicePath (
- IN CONST CHAR16 *TextDevicePath
+ IN CONST CHAR16 *TextDevicePath
)
{
if (mDevicePathLibDevicePathFromText == NULL) {
mDevicePathLibDevicePathFromText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathFromTextProtocolGuid);
}
+
if (mDevicePathLibDevicePathFromText != NULL) {
return mDevicePathLibDevicePathFromText->ConvertTextToDevicePath (TextDevicePath);
} else {