summaryrefslogtreecommitdiff
path: root/ShellPkg/Library/UefiShellCommandLib
diff options
context:
space:
mode:
authorRuiyu Ni <ruiyu.ni@intel.com>2016-07-12 15:01:17 +0800
committerHao Wu <hao.a.wu@intel.com>2016-07-25 11:04:18 +0800
commit3adb20a23984cec7a7f4b9cb568d80d40b52b537 (patch)
treec318b7dde0e8e481abad3cea800e0380624b5f2c /ShellPkg/Library/UefiShellCommandLib
parente2098b9e6b2c26eb2c415faa0ce5ead2daae74c4 (diff)
downloadedk2-platforms-3adb20a23984cec7a7f4b9cb568d80d40b52b537.tar.xz
ShellPkg/ConsistMapping.c: Handle memory allocation failure
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com> (cherry picked from commit 2c7c3b87bf43ce0977106546220b96e4d4b1ca36)
Diffstat (limited to 'ShellPkg/Library/UefiShellCommandLib')
-rw-r--r--ShellPkg/Library/UefiShellCommandLib/ConsistMapping.c499
1 files changed, 320 insertions, 179 deletions
diff --git a/ShellPkg/Library/UefiShellCommandLib/ConsistMapping.c b/ShellPkg/Library/UefiShellCommandLib/ConsistMapping.c
index 41754dd905..d157ebbb2a 100644
--- a/ShellPkg/Library/UefiShellCommandLib/ConsistMapping.c
+++ b/ShellPkg/Library/UefiShellCommandLib/ConsistMapping.c
@@ -1,7 +1,7 @@
/** @file
Main file for support of shell consist mapping.
- Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -53,10 +53,12 @@ typedef struct {
@param MapInfo The map info.
@param OrigDevPath The original device path protocol.
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+ @retval EFI_SUCCESS The appending was successful.
**/
typedef
-VOID
-(EFIAPI *SERIAL_DECODE_FUNCTION) (
+EFI_STATUS
+(*SERIAL_DECODE_FUNCTION) (
EFI_DEVICE_PATH_PROTOCOL *DevPath,
DEVICE_CONSIST_MAPPING_INFO *MapInfo,
EFI_DEVICE_PATH_PROTOCOL *OrigDevPath
@@ -78,13 +80,11 @@ typedef struct {
@param Fmt The format string
@param ... The data will be printed.
- @return Allocated buffer with the formatted string printed in it.
- The caller must free the allocated buffer.
- The buffer allocation is not packed.
+ @retval EFI_SUCCESS The string is concatenated successfully.
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
**/
-CHAR16 *
-EFIAPI
+EFI_STATUS
CatPrint (
IN OUT POOL_PRINT *Str,
IN CHAR16 *Fmt,
@@ -94,37 +94,40 @@ CatPrint (
UINT16 *AppendStr;
VA_LIST Args;
UINTN StringSize;
+ CHAR16 *NewStr;
AppendStr = AllocateZeroPool (0x1000);
if (AppendStr == NULL) {
- ASSERT(FALSE);
- return Str->Str;
+ return EFI_OUT_OF_RESOURCES;
}
VA_START (Args, Fmt);
UnicodeVSPrint (AppendStr, 0x1000, Fmt, Args);
VA_END (Args);
if (NULL == Str->Str) {
- StringSize = StrSize (AppendStr);
- Str->Str = AllocateZeroPool (StringSize);
- ASSERT (Str->Str != NULL);
+ StringSize = StrSize (AppendStr);
+ NewStr = AllocateZeroPool (StringSize);
} else {
StringSize = StrSize (AppendStr);
StringSize += (StrSize (Str->Str) - sizeof (UINT16));
- Str->Str = ReallocatePool (
- StrSize (Str->Str),
- StringSize,
- Str->Str
+ NewStr = ReallocatePool (
+ StrSize (Str->Str),
+ StringSize,
+ Str->Str
);
- ASSERT (Str->Str != NULL);
+ }
+ if (NewStr == NULL) {
+ FreePool (AppendStr);
+ return EFI_OUT_OF_RESOURCES;
}
+ Str->Str = NewStr;
StrCatS (Str->Str, StringSize/sizeof(CHAR16), AppendStr);
Str->Len = StringSize;
FreePool (AppendStr);
- return Str->Str;
+ return EFI_SUCCESS;
}
MTD_NAME mMTDName[] = {
@@ -156,30 +159,30 @@ MTD_NAME mMTDName[] = {
@param[in, out] Str The string so append onto.
@param[in] Num The number to divide and append.
- @retval EFI_INVALID_PARAMETER A parameter was NULL.
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
-EFIAPI
AppendCSDNum2 (
IN OUT POOL_PRINT *Str,
IN UINT64 Num
)
{
- UINT64 Result;
- UINT32 Rem;
+ EFI_STATUS Status;
+ UINT64 Result;
+ UINT32 Rem;
- if (Str == NULL) {
- return (EFI_INVALID_PARAMETER);
- }
+ ASSERT (Str != NULL);
Result = DivU64x32Remainder (Num, 25, &Rem);
if (Result > 0) {
- AppendCSDNum2 (Str, Result);
+ Status = AppendCSDNum2 (Str, Result);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
}
- CatPrint (Str, L"%c", Rem + 'a');
- return (EFI_SUCCESS);
+ return CatPrint (Str, L"%c", Rem + 'a');
}
/**
@@ -188,29 +191,30 @@ AppendCSDNum2 (
@param[in, out] MappingItem The mapping info object to append onto.
@param[in] Num The info to append.
- @retval EFI_INVALID_PARAMETER A parameter was NULL.
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
+
**/
EFI_STATUS
-EFIAPI
AppendCSDNum (
IN OUT DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN UINT64 Num
)
{
- if (MappingItem == NULL) {
- return EFI_INVALID_PARAMETER;
- }
+ EFI_STATUS Status;
+ ASSERT (MappingItem != NULL);
if (MappingItem->Digital) {
- CatPrint (&MappingItem->Csd, L"%ld", Num);
+ Status = CatPrint (&MappingItem->Csd, L"%ld", Num);
} else {
- AppendCSDNum2 (&MappingItem->Csd, Num);
+ Status = AppendCSDNum2 (&MappingItem->Csd, Num);
}
- MappingItem->Digital = (BOOLEAN)!(MappingItem->Digital);
+ if (!EFI_ERROR (Status)) {
+ MappingItem->Digital = (BOOLEAN) !(MappingItem->Digital);
+ }
- return (EFI_SUCCESS);
+ return Status;
}
/**
@@ -219,21 +223,21 @@ AppendCSDNum (
@param[in, out] MappingItem The mapping info object to append onto.
@param[in] Str The info to append.
- @retval EFI_INVALID_PARAMETER A parameter was NULL.
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
-EFIAPI
AppendCSDStr (
IN OUT DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN CHAR16 *Str
)
{
- CHAR16 *Index;
+ CHAR16 *Index;
+ EFI_STATUS Status;
- if (Str == NULL || MappingItem == NULL) {
- return (EFI_INVALID_PARAMETER);
- }
+ ASSERT (Str != NULL && MappingItem != NULL);
+
+ Status = EFI_SUCCESS;
if (MappingItem->Digital) {
//
@@ -252,11 +256,11 @@ AppendCSDStr (
case '7':
case '8':
case '9':
- CatPrint (&MappingItem->Csd, L"%c", *Index);
+ Status = CatPrint (&MappingItem->Csd, L"%c", *Index);
break;
case '1':
- CatPrint (&MappingItem->Csd, L"16");
+ Status = CatPrint (&MappingItem->Csd, L"16");
break;
case 'a':
@@ -265,7 +269,7 @@ AppendCSDStr (
case 'd':
case 'e':
case 'f':
- CatPrint (&MappingItem->Csd, L"1%c", *Index - 'a' + '0');
+ Status = CatPrint (&MappingItem->Csd, L"1%c", *Index - 'a' + '0');
break;
case 'A':
@@ -274,9 +278,13 @@ AppendCSDStr (
case 'D':
case 'E':
case 'F':
- CatPrint (&MappingItem->Csd, L"1%c", *Index - 'A' + '0');
+ Status = CatPrint (&MappingItem->Csd, L"1%c", *Index - 'A' + '0');
break;
}
+
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
}
} else {
for (Index = Str; *Index != 0; Index++) {
@@ -286,11 +294,15 @@ AppendCSDStr (
// a b c d e f g h i j k l m n o p
//
if (*Index >= '0' && *Index <= '9') {
- CatPrint (&MappingItem->Csd, L"%c", *Index - '0' + 'a');
+ Status = CatPrint (&MappingItem->Csd, L"%c", *Index - '0' + 'a');
} else if (*Index >= 'a' && *Index <= 'f') {
- CatPrint (&MappingItem->Csd, L"%c", *Index - 'a' + 'k');
+ Status = CatPrint (&MappingItem->Csd, L"%c", *Index - 'a' + 'k');
} else if (*Index >= 'A' && *Index <= 'F') {
- CatPrint (&MappingItem->Csd, L"%c", *Index - 'A' + 'k');
+ Status = CatPrint (&MappingItem->Csd, L"%c", *Index - 'A' + 'k');
+ }
+
+ if (EFI_ERROR (Status)) {
+ return Status;
}
}
}
@@ -306,11 +318,10 @@ AppendCSDStr (
@param[in, out] MappingItem The item to append onto.
@param[in] Guid The guid to append.
- @retval EFI_SUCCESS The appending operation was successful.
- @retval EFI_INVALID_PARAMETER A parameter was NULL.
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+ @retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
-EFIAPI
AppendCSDGuid (
DEVICE_CONSIST_MAPPING_INFO *MappingItem,
EFI_GUID *Guid
@@ -318,9 +329,7 @@ AppendCSDGuid (
{
CHAR16 Buffer[64];
- if (Guid == NULL || MappingItem == NULL) {
- return (EFI_INVALID_PARAMETER);
- }
+ ASSERT (Guid != NULL && MappingItem != NULL);
UnicodeSPrint (
Buffer,
@@ -329,9 +338,7 @@ AppendCSDGuid (
Guid
);
- AppendCSDStr (MappingItem, Buffer);
-
- return (EFI_SUCCESS);
+ return AppendCSDStr (MappingItem, Buffer);
}
/**
@@ -445,9 +452,11 @@ DevPathCompareDefault (
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
+
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+ @retval EFI_SUCCESS The appending was successful.
**/
-VOID
-EFIAPI
+EFI_STATUS
DevPathSerialHardDrive (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
@@ -464,7 +473,7 @@ DevPathSerialHardDrive (
MappingItem->Mtd = MTDTypeHardDisk;
}
- AppendCSDNum (MappingItem, Hd->PartitionNumber);
+ return AppendCSDNum (MappingItem, Hd->PartitionNumber);
}
/**
@@ -473,9 +482,11 @@ DevPathSerialHardDrive (
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
+
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+ @retval EFI_SUCCESS The appending was successful.
**/
-VOID
-EFIAPI
+EFI_STATUS
DevPathSerialAtapi (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
@@ -488,7 +499,7 @@ DevPathSerialAtapi (
ASSERT(MappingItem != NULL);
Atapi = (ATAPI_DEVICE_PATH *) DevicePathNode;
- AppendCSDNum (MappingItem, (Atapi->PrimarySecondary * 2 + Atapi->SlaveMaster));
+ return AppendCSDNum (MappingItem, (Atapi->PrimarySecondary * 2 + Atapi->SlaveMaster));
}
/**
@@ -497,9 +508,11 @@ DevPathSerialAtapi (
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
+
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+ @retval EFI_SUCCESS The appending was successful.
**/
-VOID
-EFIAPI
+EFI_STATUS
DevPathSerialCdRom (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
@@ -513,7 +526,7 @@ DevPathSerialCdRom (
Cd = (CDROM_DEVICE_PATH *) DevicePathNode;
MappingItem->Mtd = MTDTypeCDRom;
- AppendCSDNum (MappingItem, Cd->BootEntry);
+ return AppendCSDNum (MappingItem, Cd->BootEntry);
}
/**
@@ -522,23 +535,29 @@ DevPathSerialCdRom (
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
+
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+ @retval EFI_SUCCESS The appending was successful.
**/
-VOID
-EFIAPI
+EFI_STATUS
DevPathSerialFibre (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
+ EFI_STATUS Status;
FIBRECHANNEL_DEVICE_PATH *Fibre;
ASSERT(DevicePathNode != NULL);
ASSERT(MappingItem != NULL);
Fibre = (FIBRECHANNEL_DEVICE_PATH *) DevicePathNode;
- AppendCSDNum (MappingItem, Fibre->WWN);
- AppendCSDNum (MappingItem, Fibre->Lun);
+ Status = AppendCSDNum (MappingItem, Fibre->WWN);
+ if (!EFI_ERROR (Status)) {
+ Status = AppendCSDNum (MappingItem, Fibre->Lun);
+ }
+ return Status;
}
/**
@@ -547,25 +566,35 @@ DevPathSerialFibre (
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
+
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+ @retval EFI_SUCCESS The appending was successful.
**/
-VOID
-EFIAPI
+EFI_STATUS
DevPathSerialUart (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
- UART_DEVICE_PATH *Uart;
+ EFI_STATUS Status;
+ UART_DEVICE_PATH *Uart;
ASSERT(DevicePathNode != NULL);
ASSERT(MappingItem != NULL);
Uart = (UART_DEVICE_PATH *) DevicePathNode;
- AppendCSDNum (MappingItem, Uart->BaudRate);
- AppendCSDNum (MappingItem, Uart->DataBits);
- AppendCSDNum (MappingItem, Uart->Parity);
- AppendCSDNum (MappingItem, Uart->StopBits);
+ Status = AppendCSDNum (MappingItem, Uart->BaudRate);
+ if (!EFI_ERROR (Status)) {
+ Status = AppendCSDNum (MappingItem, Uart->DataBits);
+ }
+ if (!EFI_ERROR (Status)) {
+ Status = AppendCSDNum (MappingItem, Uart->Parity);
+ }
+ if (!EFI_ERROR (Status)) {
+ Status = AppendCSDNum (MappingItem, Uart->StopBits);
+ }
+ return Status;
}
/**
@@ -574,9 +603,11 @@ DevPathSerialUart (
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
+
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+ @retval EFI_SUCCESS The appending was successful.
**/
-VOID
-EFIAPI
+EFI_STATUS
DevPathSerialUsb (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
@@ -594,8 +625,14 @@ DevPathSerialUsb (
ASSERT(MappingItem != NULL);
Usb = (USB_DEVICE_PATH *) DevicePathNode;
- AppendCSDNum (MappingItem, Usb->ParentPortNumber);
- AppendCSDNum (MappingItem, Usb->InterfaceNumber);
+ Status = AppendCSDNum (MappingItem, Usb->ParentPortNumber);
+ if (!EFI_ERROR (Status)) {
+ Status = AppendCSDNum (MappingItem, Usb->InterfaceNumber);
+ }
+
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
if (PcdGetBool(PcdUsbExtendedDecode)) {
Status = gBS->LocateDevicePath( &gEfiUsbIoProtocolGuid, &DevicePath, &TempHandle );
@@ -625,6 +662,7 @@ DevPathSerialUsb (
}
}
}
+ return Status;
}
/**
@@ -634,34 +672,45 @@ DevPathSerialUsb (
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+ @retval EFI_SUCCESS The appending was successful.
**/
-VOID
-EFIAPI
+EFI_STATUS
DevPathSerialVendor (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
+ EFI_STATUS Status;
VENDOR_DEVICE_PATH *Vendor;
SAS_DEVICE_PATH *Sas;
UINTN TargetNameLength;
UINTN Index;
CHAR16 *Buffer;
+ CHAR16 *NewBuffer;
- if (DevicePathNode == NULL || MappingItem == NULL) {
- return;
- }
+ ASSERT(DevicePathNode != NULL);
+ ASSERT(MappingItem != NULL);
Vendor = (VENDOR_DEVICE_PATH *) DevicePathNode;
- AppendCSDGuid (MappingItem, &Vendor->Guid);
+ Status = AppendCSDGuid (MappingItem, &Vendor->Guid);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
if (CompareGuid (&gEfiSasDevicePathGuid, &Vendor->Guid)) {
Sas = (SAS_DEVICE_PATH *) Vendor;
- AppendCSDNum (MappingItem, Sas->SasAddress);
- AppendCSDNum (MappingItem, Sas->Lun);
- AppendCSDNum (MappingItem, Sas->DeviceTopology);
- AppendCSDNum (MappingItem, Sas->RelativeTargetPort);
+ Status = AppendCSDNum (MappingItem, Sas->SasAddress);
+ if (!EFI_ERROR (Status)) {
+ Status = AppendCSDNum (MappingItem, Sas->Lun);
+ }
+ if (!EFI_ERROR (Status)) {
+ Status = AppendCSDNum (MappingItem, Sas->DeviceTopology);
+ }
+ if (!EFI_ERROR (Status)) {
+ Status = AppendCSDNum (MappingItem, Sas->RelativeTargetPort);
+ }
} else {
TargetNameLength = MIN(DevicePathNodeLength (DevicePathNode) - sizeof (VENDOR_DEVICE_PATH), PcdGet32(PcdShellVendorExtendedDecode));
if (TargetNameLength != 0) {
@@ -669,26 +718,33 @@ DevPathSerialVendor (
// String is 2 chars per data byte, plus NULL terminator
//
Buffer = AllocateZeroPool (((TargetNameLength * 2) + 1) * sizeof(CHAR16));
- ASSERT(Buffer != NULL);
if (Buffer == NULL) {
- return;
- }
+ return EFI_OUT_OF_RESOURCES;
+ }
//
// Build the string data
//
for (Index = 0; Index < TargetNameLength; Index++) {
- Buffer = CatSPrint (Buffer, L"%02x", *((UINT8*)Vendor + sizeof (VENDOR_DEVICE_PATH) + Index));
-}
+ NewBuffer = CatSPrint (Buffer, L"%02x", *((UINT8*)Vendor + sizeof (VENDOR_DEVICE_PATH) + Index));
+ if (NewBuffer == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ break;
+ }
+ Buffer = NewBuffer;
+ }
//
// Append the new data block
//
- AppendCSDStr (MappingItem, Buffer);
+ if (!EFI_ERROR (Status)) {
+ Status = AppendCSDStr (MappingItem, Buffer);
+ }
FreePool(Buffer);
}
}
+ return Status;
}
/**
@@ -697,9 +753,11 @@ DevPathSerialVendor (
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
+
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+ @retval EFI_SUCCESS The appending was successful.
**/
-VOID
-EFIAPI
+EFI_STATUS
DevPathSerialLun (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
@@ -712,7 +770,7 @@ DevPathSerialLun (
ASSERT(MappingItem != NULL);
Lun = (DEVICE_LOGICAL_UNIT_DEVICE_PATH *) DevicePathNode;
- AppendCSDNum (MappingItem, Lun->Lun);
+ return AppendCSDNum (MappingItem, Lun->Lun);
}
/**
@@ -721,24 +779,32 @@ DevPathSerialLun (
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
+
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+ @retval EFI_SUCCESS The appending was successful.
**/
-VOID
-EFIAPI
+EFI_STATUS
DevPathSerialSata (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
+ EFI_STATUS Status;
SATA_DEVICE_PATH *Sata;
ASSERT(DevicePathNode != NULL);
ASSERT(MappingItem != NULL);
Sata = (SATA_DEVICE_PATH *) DevicePathNode;
- AppendCSDNum (MappingItem, Sata->HBAPortNumber);
- AppendCSDNum (MappingItem, Sata->PortMultiplierPortNumber);
- AppendCSDNum (MappingItem, Sata->Lun);
+ Status = AppendCSDNum (MappingItem, Sata->HBAPortNumber);
+ if (!EFI_ERROR (Status)) {
+ Status = AppendCSDNum (MappingItem, Sata->PortMultiplierPortNumber);
+ }
+ if (!EFI_ERROR (Status)) {
+ Status = AppendCSDNum (MappingItem, Sata->Lun);
+ }
+ return Status;
}
/**
@@ -747,15 +813,18 @@ DevPathSerialSata (
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
+
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+ @retval EFI_SUCCESS The appending was successful.
**/
-VOID
-EFIAPI
+EFI_STATUS
DevPathSerialIScsi (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
+ EFI_STATUS Status;
ISCSI_DEVICE_PATH *IScsi;
UINT8 *IScsiTargetName;
CHAR16 *TargetName;
@@ -765,25 +834,39 @@ DevPathSerialIScsi (
ASSERT(DevicePathNode != NULL);
ASSERT(MappingItem != NULL);
+ Status = EFI_SUCCESS;
+
if (PcdGetBool(PcdShellDecodeIScsiMapNames)) {
IScsi = (ISCSI_DEVICE_PATH *) DevicePathNode;
- AppendCSDNum (MappingItem, IScsi->NetworkProtocol);
- AppendCSDNum (MappingItem, IScsi->LoginOption);
- AppendCSDNum (MappingItem, IScsi->Lun);
- AppendCSDNum (MappingItem, IScsi->TargetPortalGroupTag);
+ Status = AppendCSDNum (MappingItem, IScsi->NetworkProtocol);
+ if (!EFI_ERROR (Status)) {
+ Status = AppendCSDNum (MappingItem, IScsi->LoginOption);
+ }
+ if (!EFI_ERROR (Status)) {
+ Status = AppendCSDNum (MappingItem, IScsi->Lun);
+ }
+ if (!EFI_ERROR (Status)) {
+ Status = AppendCSDNum (MappingItem, IScsi->TargetPortalGroupTag);
+ }
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
TargetNameLength = DevicePathNodeLength (DevicePathNode) - sizeof (ISCSI_DEVICE_PATH);
if (TargetNameLength > 0) {
TargetName = AllocateZeroPool ((TargetNameLength + 1) * sizeof (CHAR16));
- if (TargetName != NULL) {
+ if (TargetName == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ } else {
IScsiTargetName = (UINT8 *) (IScsi + 1);
for (Index = 0; Index < TargetNameLength; Index++) {
TargetName[Index] = (CHAR16) IScsiTargetName[Index];
}
- AppendCSDStr (MappingItem, TargetName);
+ Status = AppendCSDStr (MappingItem, TargetName);
FreePool (TargetName);
}
}
}
+ return Status;
}
/**
@@ -792,9 +875,11 @@ DevPathSerialIScsi (
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
+
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+ @retval EFI_SUCCESS The appending was successful.
**/
-VOID
-EFIAPI
+EFI_STATUS
DevPathSerialI2O (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
@@ -807,7 +892,7 @@ DevPathSerialI2O (
ASSERT(MappingItem != NULL);
DevicePath_I20 = (I2O_DEVICE_PATH *) DevicePathNode;
- AppendCSDNum (MappingItem, DevicePath_I20->Tid);
+ return AppendCSDNum (MappingItem, DevicePath_I20->Tid);
}
/**
@@ -816,9 +901,11 @@ DevPathSerialI2O (
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
+
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+ @retval EFI_SUCCESS The appending was successful.
**/
-VOID
-EFIAPI
+EFI_STATUS
DevPathSerialMacAddr (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
@@ -845,7 +932,7 @@ DevPathSerialMacAddr (
UnicodeSPrint (PBuffer, 0, L"%02x", (UINTN) Mac->MacAddress.Addr[Index]);
}
- AppendCSDStr (MappingItem, Buffer);
+ return AppendCSDStr (MappingItem, Buffer);
}
/**
@@ -854,15 +941,18 @@ DevPathSerialMacAddr (
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
+
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+ @retval EFI_SUCCESS The appending was successful.
**/
-VOID
-EFIAPI
+EFI_STATUS
DevPathSerialInfiniBand (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
+ EFI_STATUS Status;
INFINIBAND_DEVICE_PATH *InfiniBand;
UINTN Index;
CHAR16 Buffer[64];
@@ -876,10 +966,17 @@ DevPathSerialInfiniBand (
UnicodeSPrint (PBuffer, 0, L"%02x", (UINTN) InfiniBand->PortGid[Index]);
}
- AppendCSDStr (MappingItem, Buffer);
- AppendCSDNum (MappingItem, InfiniBand->ServiceId);
- AppendCSDNum (MappingItem, InfiniBand->TargetPortId);
- AppendCSDNum (MappingItem, InfiniBand->DeviceId);
+ Status = AppendCSDStr (MappingItem, Buffer);
+ if (!EFI_ERROR (Status)) {
+ Status = AppendCSDNum (MappingItem, InfiniBand->ServiceId);
+ }
+ if (!EFI_ERROR (Status)) {
+ Status = AppendCSDNum (MappingItem, InfiniBand->TargetPortId);
+ }
+ if (!EFI_ERROR (Status)) {
+ Status = AppendCSDNum (MappingItem, InfiniBand->DeviceId);
+ }
+ return Status;
}
/**
@@ -888,15 +985,18 @@ DevPathSerialInfiniBand (
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
+
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+ @retval EFI_SUCCESS The appending was successful.
**/
-VOID
-EFIAPI
+EFI_STATUS
DevPathSerialIPv4 (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
+ EFI_STATUS Status;
IPv4_DEVICE_PATH *Ip;
CHAR16 Buffer[10];
@@ -913,19 +1013,26 @@ DevPathSerialIPv4 (
(UINTN) Ip->LocalIpAddress.Addr[2],
(UINTN) Ip->LocalIpAddress.Addr[3]
);
- AppendCSDStr (MappingItem, Buffer);
- AppendCSDNum (MappingItem, Ip->LocalPort);
- UnicodeSPrint (
- Buffer,
- 0,
- L"%02x%02x%02x%02x",
- (UINTN) Ip->RemoteIpAddress.Addr[0],
- (UINTN) Ip->RemoteIpAddress.Addr[1],
- (UINTN) Ip->RemoteIpAddress.Addr[2],
- (UINTN) Ip->RemoteIpAddress.Addr[3]
- );
- AppendCSDStr (MappingItem, Buffer);
- AppendCSDNum (MappingItem, Ip->RemotePort);
+ Status = AppendCSDStr (MappingItem, Buffer);
+ if (!EFI_ERROR (Status)) {
+ Status = AppendCSDNum (MappingItem, Ip->LocalPort);
+ }
+ if (!EFI_ERROR (Status)) {
+ UnicodeSPrint (
+ Buffer,
+ 0,
+ L"%02x%02x%02x%02x",
+ (UINTN) Ip->RemoteIpAddress.Addr[0],
+ (UINTN) Ip->RemoteIpAddress.Addr[1],
+ (UINTN) Ip->RemoteIpAddress.Addr[2],
+ (UINTN) Ip->RemoteIpAddress.Addr[3]
+ );
+ Status = AppendCSDStr (MappingItem, Buffer);
+ }
+ if (!EFI_ERROR (Status)) {
+ Status = AppendCSDNum (MappingItem, Ip->RemotePort);
+ }
+ return Status;
}
/**
@@ -935,15 +1042,17 @@ DevPathSerialIPv4 (
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+ @retval EFI_SUCCESS The appending was successful.
**/
-VOID
-EFIAPI
+EFI_STATUS
DevPathSerialIPv6 (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
+ EFI_STATUS Status;
IPv6_DEVICE_PATH *Ip;
UINTN Index;
CHAR16 Buffer[64];
@@ -957,14 +1066,21 @@ DevPathSerialIPv6 (
UnicodeSPrint (PBuffer, 0, L"%02x", (UINTN) Ip->LocalIpAddress.Addr[Index]);
}
- AppendCSDStr (MappingItem, Buffer);
- AppendCSDNum (MappingItem, Ip->LocalPort);
- for (Index = 0, PBuffer = Buffer; Index < 16; Index++, PBuffer += 2) {
- UnicodeSPrint (PBuffer, 0, L"%02x", (UINTN) Ip->RemoteIpAddress.Addr[Index]);
+ Status = AppendCSDStr (MappingItem, Buffer);
+ if (!EFI_ERROR (Status)) {
+ Status = AppendCSDNum (MappingItem, Ip->LocalPort);
}
+ if (!EFI_ERROR (Status)) {
+ for (Index = 0, PBuffer = Buffer; Index < 16; Index++, PBuffer += 2) {
+ UnicodeSPrint (PBuffer, 0, L"%02x", (UINTN) Ip->RemoteIpAddress.Addr[Index]);
+ }
- AppendCSDStr (MappingItem, Buffer);
- AppendCSDNum (MappingItem, Ip->RemotePort);
+ Status = AppendCSDStr (MappingItem, Buffer);
+ }
+ if (!EFI_ERROR (Status)) {
+ Status = AppendCSDNum (MappingItem, Ip->RemotePort);
+ }
+ return Status;
}
/**
@@ -974,23 +1090,28 @@ DevPathSerialIPv6 (
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+ @retval EFI_SUCCESS The appending was successful.
**/
-VOID
-EFIAPI
+EFI_STATUS
DevPathSerialScsi (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
+ EFI_STATUS Status;
SCSI_DEVICE_PATH *Scsi;
ASSERT(DevicePathNode != NULL);
ASSERT(MappingItem != NULL);
Scsi = (SCSI_DEVICE_PATH *) DevicePathNode;
- AppendCSDNum (MappingItem, Scsi->Pun);
- AppendCSDNum (MappingItem, Scsi->Lun);
+ Status = AppendCSDNum (MappingItem, Scsi->Pun);
+ if (!EFI_ERROR (Status)) {
+ Status = AppendCSDNum (MappingItem, Scsi->Lun);
+ }
+ return Status;
}
/**
@@ -999,9 +1120,11 @@ DevPathSerialScsi (
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
+
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+ @retval EFI_SUCCESS The appending was successful.
**/
-VOID
-EFIAPI
+EFI_STATUS
DevPathSerial1394 (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
@@ -1016,7 +1139,7 @@ DevPathSerial1394 (
DevicePath_F1394 = (F1394_DEVICE_PATH *) DevicePathNode;
UnicodeSPrint (Buffer, 0, L"%lx", DevicePath_F1394->Guid);
- AppendCSDStr (MappingItem, Buffer);
+ return AppendCSDStr (MappingItem, Buffer);
}
/**
@@ -1025,9 +1148,11 @@ DevPathSerial1394 (
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
+
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+ @retval EFI_SUCCESS The appending was successful.
**/
-VOID
-EFIAPI
+EFI_STATUS
DevPathSerialAcpi (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
@@ -1043,9 +1168,10 @@ DevPathSerialAcpi (
if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
if (EISA_ID_TO_NUM (Acpi->HID) == 0x0604) {
MappingItem->Mtd = MTDTypeFloppy;
- AppendCSDNum (MappingItem, Acpi->UID);
+ return AppendCSDNum (MappingItem, Acpi->UID);
}
}
+ return EFI_SUCCESS;
}
/**
@@ -1055,17 +1181,17 @@ DevPathSerialAcpi (
@param[in] MappingItem Ignored.
@param[in] DevicePath Ignored.
- Does nothing.
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+ @retval EFI_SUCCESS The appending was successful.
**/
-VOID
-EFIAPI
+EFI_STATUS
DevPathSerialDefault (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
- return;
+ return EFI_SUCCESS;
}
DEV_PATH_CONSIST_MAPPING_TABLE DevPathConsistMappingTable[] = {
@@ -1304,6 +1430,7 @@ GetDeviceConsistMappingInfo (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
+ EFI_STATUS Status;
SERIAL_DECODE_FUNCTION SerialFun;
UINTN Index;
EFI_DEVICE_PATH_PROTOCOL *OriginalDevicePath;
@@ -1329,7 +1456,11 @@ GetDeviceConsistMappingInfo (
}
}
- SerialFun (DevicePath, MappingItem, OriginalDevicePath);
+ Status = SerialFun (DevicePath, MappingItem, OriginalDevicePath);
+ if (EFI_ERROR (Status)) {
+ SHELL_FREE_NON_NULL (MappingItem->Csd.Str);
+ return Status;
+ }
//
// Next device path node
@@ -1476,11 +1607,12 @@ ShellCommandConsistMappingGenMappingName (
IN EFI_DEVICE_PATH_PROTOCOL **Table
)
{
+ EFI_STATUS Status;
POOL_PRINT Str;
DEVICE_CONSIST_MAPPING_INFO MappingInfo;
EFI_DEVICE_PATH_PROTOCOL *HIDevicePath;
UINTN Index;
- UINTN NewSize;
+ CHAR16 *NewStr;
ASSERT(DevicePath != NULL);
ASSERT(Table != NULL);
@@ -1505,7 +1637,10 @@ ShellCommandConsistMappingGenMappingName (
MappingInfo.Mtd = MTDTypeUnknown;
MappingInfo.Digital = FALSE;
- GetDeviceConsistMappingInfo (&MappingInfo, DevicePath);
+ Status = GetDeviceConsistMappingInfo (&MappingInfo, DevicePath);
+ if (EFI_ERROR (Status)) {
+ return NULL;
+ }
SetMem (&Str, sizeof (Str), 0);
for (Index = 0; mMTDName[Index].MTDType != MTDTypeEnd; Index++) {
@@ -1515,26 +1650,32 @@ ShellCommandConsistMappingGenMappingName (
}
if (mMTDName[Index].MTDType != MTDTypeEnd) {
- CatPrint (&Str, L"%s", mMTDName[Index].Name);
+ Status = CatPrint (&Str, L"%s", mMTDName[Index].Name);
}
- CatPrint (&Str, L"%d", (UINTN) MappingInfo.Hi);
- if (MappingInfo.Csd.Str != NULL) {
- CatPrint (&Str, L"%s", MappingInfo.Csd.Str);
+ if (!EFI_ERROR (Status)) {
+ Status = CatPrint (&Str, L"%d", (UINTN) MappingInfo.Hi);
+ }
+ if (!EFI_ERROR (Status) && MappingInfo.Csd.Str != NULL) {
+ Status = CatPrint (&Str, L"%s", MappingInfo.Csd.Str);
FreePool (MappingInfo.Csd.Str);
}
- if (Str.Str != NULL) {
- CatPrint (&Str, L":");
+ if (!EFI_ERROR (Status) && Str.Str != NULL) {
+ Status = CatPrint (&Str, L":");
+ }
+ if (EFI_ERROR (Status)) {
+ SHELL_FREE_NON_NULL (Str.Str);
+ return NULL;
}
- NewSize = (Str.Len + 1) * sizeof (CHAR16);
- Str.Str = ReallocatePool (Str.Len, NewSize, Str.Str);
- if (Str.Str == NULL) {
+ NewStr = ReallocatePool (Str.Len * sizeof (CHAR16), (Str.Len + 1) * sizeof (CHAR16), Str.Str);
+ if (NewStr == NULL) {
+ SHELL_FREE_NON_NULL (Str.Str);
return (NULL);
}
- Str.Str[Str.Len] = CHAR_NULL;
- return Str.Str;
+ NewStr[Str.Len] = CHAR_NULL;
+ return NewStr;
}
/**