X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiHandleParsingLib%2FUefiHandleParsingLib.c;h=1049dea0c009bdb628e0032f890f0d6ba03a9d20;hp=63710865251d85a137f60ac27ec098f748e76a77;hb=d4ec9a5725d67bb1770008513f4c6f1dce2c9b43;hpb=87f66b63d409fde7d2ea018b65a63986ba413f1f diff --git a/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c b/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c index 6371086525..1049dea0c0 100644 --- a/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c +++ b/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c @@ -1,7 +1,7 @@ /** @file Provides interface to advanced shell functionality for parsing both handle and protocol database. - Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.
(C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.
(C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
This program and the accompanying materials @@ -19,8 +19,8 @@ EFI_HANDLE mHandleParsingHiiHandle = NULL; HANDLE_INDEX_LIST mHandleList = {{{NULL,NULL},0,0},0}; -GUID_INFO_BLOCK *GuidList; -UINTN GuidListCount; +GUID_INFO_BLOCK *mGuidList; +UINTN mGuidListCount; /** Function to translate the EFI_MEMORY_TYPE into a string. @@ -29,7 +29,6 @@ UINTN GuidListCount; @retval A string representation of the type allocated from BS Pool. **/ CHAR16* -EFIAPI ConvertMemoryType ( IN CONST EFI_MEMORY_TYPE Memory ) @@ -66,7 +65,6 @@ ConvertMemoryType ( @retval A string representation of the type allocated from BS Pool. **/ CHAR16* -EFIAPI ConvertPixelFormat ( IN CONST EFI_GRAPHICS_PIXEL_FORMAT Fmt ) @@ -100,8 +98,8 @@ HandleParsingLibConstructor ( IN EFI_SYSTEM_TABLE *SystemTable ) { - GuidListCount = 0; - GuidList = NULL; + mGuidListCount = 0; + mGuidList = NULL; // // Do nothing with mHandleParsingHiiHandle. Initialize HII as needed. @@ -139,11 +137,11 @@ HandleParsingLibDestructor ( { UINTN LoopCount; - for (LoopCount = 0; GuidList != NULL && LoopCount < GuidListCount; LoopCount++) { - SHELL_FREE_NON_NULL(GuidList[LoopCount].GuidId); + for (LoopCount = 0; mGuidList != NULL && LoopCount < mGuidListCount; LoopCount++) { + SHELL_FREE_NON_NULL(mGuidList[LoopCount].GuidId); } - SHELL_FREE_NON_NULL(GuidList); + SHELL_FREE_NON_NULL(mGuidList); if (mHandleParsingHiiHandle != NULL) { HiiRemovePackages(mHandleParsingHiiHandle); } @@ -727,8 +725,9 @@ DriverEfiVersionProtocolDumpInformation( ASSERT_EFI_ERROR(Status); RetVal = AllocateZeroPool(VersionStringSize); - ASSERT(RetVal != NULL); - UnicodeSPrint(RetVal, VersionStringSize, L"0x%08x", DriverEfiVersion->FirmwareVersion); + if (RetVal != NULL) { + UnicodeSPrint (RetVal, VersionStringSize, L"0x%08x", DriverEfiVersion->FirmwareVersion); + } return (RetVal); } /** @@ -1323,7 +1322,7 @@ FirmwareManagementDumpInformation ( TempStr, Index, ImageInfoV1[Index].ImageIndex, - ImageInfoV1[Index].ImageTypeId, + &ImageInfoV1[Index].ImageTypeId, ImageInfoV1[Index].ImageId, ImageInfoV1[Index].ImageIdName, ImageInfoV1[Index].Version, @@ -1350,7 +1349,7 @@ FirmwareManagementDumpInformation ( TempStr, Index, ImageInfoV2[Index].ImageIndex, - ImageInfoV2[Index].ImageTypeId, + &ImageInfoV2[Index].ImageTypeId, ImageInfoV2[Index].ImageId, ImageInfoV2[Index].ImageIdName, ImageInfoV2[Index].Version, @@ -1378,7 +1377,7 @@ FirmwareManagementDumpInformation ( TempStr, Index, ImageInfo[Index].ImageIndex, - ImageInfo[Index].ImageTypeId, + &ImageInfo[Index].ImageTypeId, ImageInfo[Index].ImageId, ImageInfo[Index].ImageIdName, ImageInfo[Index].Version, @@ -1830,7 +1829,6 @@ STATIC CONST GUID_INFO_BLOCK mGuidStringList[] = { @return The node. **/ CONST GUID_INFO_BLOCK * -EFIAPI InternalShellGetNodeFromGuid( IN CONST EFI_GUID* Guid ) @@ -1840,7 +1838,7 @@ InternalShellGetNodeFromGuid( ASSERT(Guid != NULL); - for (LoopCount = 0, ListWalker = GuidList; GuidList != NULL && LoopCount < GuidListCount; LoopCount++, ListWalker++) { + for (LoopCount = 0, ListWalker = mGuidList; mGuidList != NULL && LoopCount < mGuidListCount; LoopCount++, ListWalker++) { if (CompareGuid(ListWalker->GuidId, Guid)) { return (ListWalker); } @@ -1874,7 +1872,6 @@ Function to add a new GUID/Name mapping. @retval EFI_INVALID_PARAMETER Guid NameId was invalid **/ EFI_STATUS -EFIAPI InsertNewGuidNameMapping( IN CONST EFI_GUID *Guid, IN CONST EFI_STRING_ID NameID, @@ -1884,18 +1881,18 @@ InsertNewGuidNameMapping( ASSERT(Guid != NULL); ASSERT(NameID != 0); - GuidList = ReallocatePool(GuidListCount * sizeof(GUID_INFO_BLOCK), GuidListCount+1 * sizeof(GUID_INFO_BLOCK), GuidList); - if (GuidList == NULL) { - GuidListCount = 0; + mGuidList = ReallocatePool(mGuidListCount * sizeof(GUID_INFO_BLOCK), mGuidListCount+1 * sizeof(GUID_INFO_BLOCK), mGuidList); + if (mGuidList == NULL) { + mGuidListCount = 0; return (EFI_OUT_OF_RESOURCES); } - GuidListCount++; + mGuidListCount++; - GuidList[GuidListCount - 1].GuidId = AllocateCopyPool(sizeof(EFI_GUID), Guid); - GuidList[GuidListCount - 1].StringId = NameID; - GuidList[GuidListCount - 1].DumpInfo = DumpFunc; + mGuidList[mGuidListCount - 1].GuidId = AllocateCopyPool(sizeof(EFI_GUID), Guid); + mGuidList[mGuidListCount - 1].StringId = NameID; + mGuidList[mGuidListCount - 1].DumpInfo = DumpFunc; - if (GuidList[GuidListCount - 1].GuidId == NULL) { + if (mGuidList[mGuidListCount - 1].GuidId == NULL) { return (EFI_OUT_OF_RESOURCES); } @@ -2064,7 +2061,7 @@ GetGuidFromStringName( } } - for (LoopCount = 0, ListWalker = GuidList; GuidList != NULL && LoopCount < GuidListCount; LoopCount++, ListWalker++) { + for (LoopCount = 0, ListWalker = mGuidList; mGuidList != NULL && LoopCount < mGuidListCount; LoopCount++, ListWalker++) { String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang); if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) { *Guid = ListWalker->GuidId; @@ -2189,7 +2186,6 @@ GetStringNameFromHandle( @retval EFI_SUCCESS The operation was successful. **/ EFI_STATUS -EFIAPI InternalShellInitHandleList( VOID ) @@ -2217,10 +2213,11 @@ InternalShellInitHandleList( } for (mHandleList.NextIndex = 1 ; mHandleList.NextIndex <= HandleCount ; mHandleList.NextIndex++){ ListWalker = AllocateZeroPool(sizeof(HANDLE_LIST)); - ASSERT(ListWalker != NULL); - ListWalker->TheHandle = HandleBuffer[mHandleList.NextIndex-1]; - ListWalker->TheIndex = mHandleList.NextIndex; - InsertTailList(&mHandleList.List.Link,&ListWalker->Link); + if (ListWalker != NULL) { + ListWalker->TheHandle = HandleBuffer[mHandleList.NextIndex - 1]; + ListWalker->TheIndex = mHandleList.NextIndex; + InsertTailList (&mHandleList.List.Link, &ListWalker->Link); + } } FreePool(HandleBuffer); return (EFI_SUCCESS); @@ -2288,7 +2285,9 @@ ConvertHandleToHandleIndex( FreePool (ProtocolBuffer); ListWalker = AllocateZeroPool(sizeof(HANDLE_LIST)); - ASSERT(ListWalker != NULL); + if (ListWalker == NULL) { + return 0; + } ListWalker->TheHandle = TheHandle; ListWalker->TheIndex = mHandleList.NextIndex++; InsertTailList(&mHandleList.List.Link,&ListWalker->Link); @@ -2415,7 +2414,11 @@ ParseHandleDatabaseByRelationshipWithType ( } *HandleType = AllocateZeroPool (*HandleCount * sizeof (UINTN)); - ASSERT(*HandleType != NULL); + if (*HandleType == NULL) { + SHELL_FREE_NON_NULL (*HandleBuffer); + *HandleCount = 0; + return EFI_OUT_OF_RESOURCES; + } DriverBindingHandleIndex = -1; for (HandleIndex = 0; HandleIndex < *HandleCount; HandleIndex++) { @@ -2671,26 +2674,28 @@ ParseHandleDatabaseByRelationship ( // Allocate a handle buffer for the number of handles that matched the attributes in Mask // *MatchingHandleBuffer = AllocateZeroPool ((*MatchingHandleCount +1)* sizeof (EFI_HANDLE)); - ASSERT(*MatchingHandleBuffer != NULL); + if (*MatchingHandleBuffer == NULL) { + Status = EFI_OUT_OF_RESOURCES; + } else { + for (HandleIndex = 0, *MatchingHandleCount = 0 + ; HandleIndex < HandleCount + ; HandleIndex++ + ) { + // + // Fill the allocated buffer with the handles that matched the attributes in Mask + // + if ((HandleType[HandleIndex] & Mask) == Mask) { + (*MatchingHandleBuffer)[(*MatchingHandleCount)++] = HandleBuffer[HandleIndex]; + } + } - for (HandleIndex = 0,*MatchingHandleCount = 0 - ; HandleIndex < HandleCount - ; HandleIndex++ - ){ // - // Fill the allocated buffer with the handles that matched the attributes in Mask + // Make the last one NULL // - if ((HandleType[HandleIndex] & Mask) == Mask) { - (*MatchingHandleBuffer)[(*MatchingHandleCount)++] = HandleBuffer[HandleIndex]; - } - } - - // - // Make the last one NULL - // - (*MatchingHandleBuffer)[*MatchingHandleCount] = NULL; + (*MatchingHandleBuffer)[*MatchingHandleCount] = NULL; - Status = EFI_SUCCESS; + Status = EFI_SUCCESS; + } // *MatchingHandleBuffer == NULL (ELSE) } // MacthingHandleBuffer == NULL (ELSE) } // *MatchingHandleCount == 0 (ELSE) } // no error on ParseHandleDatabaseByRelationshipWithType @@ -2703,6 +2708,9 @@ ParseHandleDatabaseByRelationship ( FreePool (HandleType); } + ASSERT ((MatchingHandleBuffer == NULL) || + (*MatchingHandleCount == 0 && *MatchingHandleBuffer == NULL) || + (*MatchingHandleCount != 0 && *MatchingHandleBuffer != NULL)); return Status; } @@ -2710,7 +2718,7 @@ ParseHandleDatabaseByRelationship ( Gets handles for any child controllers of the passed in controller. @param[in] ControllerHandle The handle of the "parent controller" - @param[in] MatchingHandleCount Pointer to the number of handles in + @param[out] MatchingHandleCount Pointer to the number of handles in MatchingHandleBuffer on return. @param[out] MatchingHandleBuffer Buffer containing handles on a successful return. @@ -2722,7 +2730,7 @@ EFI_STATUS EFIAPI ParseHandleDatabaseForChildControllers( IN CONST EFI_HANDLE ControllerHandle, - IN UINTN *MatchingHandleCount, + OUT UINTN *MatchingHandleCount, OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL ) { @@ -2789,12 +2797,22 @@ ParseHandleDatabaseForChildControllers( FreePool (DriverBindingHandleBuffer); + if (MatchingHandleBuffer == NULL || *MatchingHandleCount == 0) { + // + // The caller is not interested in the actual handles, or we've found none. + // + FreePool (HandleBufferForReturn); + HandleBufferForReturn = NULL; + } + if (MatchingHandleBuffer != NULL) { *MatchingHandleBuffer = HandleBufferForReturn; - } else { - FreePool(HandleBufferForReturn); } + ASSERT ((MatchingHandleBuffer == NULL) || + (*MatchingHandleCount == 0 && *MatchingHandleBuffer == NULL) || + (*MatchingHandleCount != 0 && *MatchingHandleBuffer != NULL)); + return (EFI_SUCCESS); } @@ -2814,7 +2832,6 @@ ParseHandleDatabaseForChildControllers( @return A pointer to (*DestinationBuffer). **/ VOID* -EFIAPI BuffernCatGrow ( IN OUT VOID **DestinationBuffer, IN OUT UINTN *DestinationSize,