]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c
ShellPkg/HandleParsingLib: Rename global variables
[mirror_edk2.git] / ShellPkg / Library / UefiHandleParsingLib / UefiHandleParsingLib.c
index 3fb55df8cc14fc26269f3e49aa8a2865a8614d2a..1049dea0c009bdb628e0032f890f0d6ba03a9d20 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Provides interface to advanced shell functionality for parsing both handle and protocol database.\r
 \r
-  Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>\r
   (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r
   (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r
   This program and the accompanying materials\r
@@ -19,8 +19,8 @@
 \r
 EFI_HANDLE        mHandleParsingHiiHandle = NULL;\r
 HANDLE_INDEX_LIST mHandleList = {{{NULL,NULL},0,0},0};\r
-GUID_INFO_BLOCK   *GuidList;\r
-UINTN             GuidListCount;\r
+GUID_INFO_BLOCK   *mGuidList;\r
+UINTN             mGuidListCount;\r
 /**\r
   Function to translate the EFI_MEMORY_TYPE into a string.\r
 \r
@@ -29,7 +29,6 @@ UINTN             GuidListCount;
   @retval               A string representation of the type allocated from BS Pool.\r
 **/\r
 CHAR16*\r
-EFIAPI\r
 ConvertMemoryType (\r
   IN CONST EFI_MEMORY_TYPE Memory\r
   )\r
@@ -66,7 +65,6 @@ ConvertMemoryType (
   @retval               A string representation of the type allocated from BS Pool.\r
 **/\r
 CHAR16*\r
-EFIAPI\r
 ConvertPixelFormat (\r
   IN CONST EFI_GRAPHICS_PIXEL_FORMAT Fmt\r
   )\r
@@ -100,8 +98,8 @@ HandleParsingLibConstructor (
   IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
 {\r
-  GuidListCount = 0;\r
-  GuidList      = NULL;\r
+  mGuidListCount = 0;\r
+  mGuidList      = NULL;\r
 \r
   //\r
   // Do nothing with mHandleParsingHiiHandle.  Initialize HII as needed.\r
@@ -139,11 +137,11 @@ HandleParsingLibDestructor (
 {\r
   UINTN                 LoopCount;\r
 \r
-  for (LoopCount = 0; GuidList != NULL && LoopCount < GuidListCount; LoopCount++) {\r
-    SHELL_FREE_NON_NULL(GuidList[LoopCount].GuidId);\r
+  for (LoopCount = 0; mGuidList != NULL && LoopCount < mGuidListCount; LoopCount++) {\r
+    SHELL_FREE_NON_NULL(mGuidList[LoopCount].GuidId);\r
   }\r
 \r
-  SHELL_FREE_NON_NULL(GuidList);\r
+  SHELL_FREE_NON_NULL(mGuidList);\r
   if (mHandleParsingHiiHandle != NULL) {\r
     HiiRemovePackages(mHandleParsingHiiHandle);\r
   }\r
@@ -1831,7 +1829,6 @@ STATIC CONST GUID_INFO_BLOCK mGuidStringList[] = {
   @return                       The node.\r
 **/\r
 CONST GUID_INFO_BLOCK *\r
-EFIAPI\r
 InternalShellGetNodeFromGuid(\r
   IN CONST EFI_GUID* Guid\r
   )\r
@@ -1841,7 +1838,7 @@ InternalShellGetNodeFromGuid(
 \r
   ASSERT(Guid != NULL);\r
 \r
-  for (LoopCount = 0, ListWalker = GuidList; GuidList != NULL && LoopCount < GuidListCount; LoopCount++, ListWalker++) {\r
+  for (LoopCount = 0, ListWalker = mGuidList; mGuidList != NULL && LoopCount < mGuidListCount; LoopCount++, ListWalker++) {\r
     if (CompareGuid(ListWalker->GuidId, Guid)) {\r
       return (ListWalker);\r
     }\r
@@ -1875,7 +1872,6 @@ Function to add a new GUID/Name mapping.
 @retval EFI_INVALID_PARAMETER Guid NameId was invalid\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 InsertNewGuidNameMapping(\r
   IN CONST EFI_GUID           *Guid,\r
   IN CONST EFI_STRING_ID      NameID,\r
@@ -1885,18 +1881,18 @@ InsertNewGuidNameMapping(
   ASSERT(Guid   != NULL);\r
   ASSERT(NameID != 0);\r
 \r
-  GuidList = ReallocatePool(GuidListCount * sizeof(GUID_INFO_BLOCK), GuidListCount+1 * sizeof(GUID_INFO_BLOCK), GuidList);\r
-  if (GuidList == NULL) {\r
-    GuidListCount = 0;\r
+  mGuidList = ReallocatePool(mGuidListCount * sizeof(GUID_INFO_BLOCK), mGuidListCount+1 * sizeof(GUID_INFO_BLOCK), mGuidList);\r
+  if (mGuidList == NULL) {\r
+    mGuidListCount = 0;\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
-  GuidListCount++;\r
+  mGuidListCount++;\r
 \r
-  GuidList[GuidListCount - 1].GuidId   = AllocateCopyPool(sizeof(EFI_GUID), Guid);\r
-  GuidList[GuidListCount - 1].StringId = NameID;\r
-  GuidList[GuidListCount - 1].DumpInfo = DumpFunc;\r
+  mGuidList[mGuidListCount - 1].GuidId   = AllocateCopyPool(sizeof(EFI_GUID), Guid);\r
+  mGuidList[mGuidListCount - 1].StringId = NameID;\r
+  mGuidList[mGuidListCount - 1].DumpInfo = DumpFunc;\r
 \r
-  if (GuidList[GuidListCount - 1].GuidId == NULL) {\r
+  if (mGuidList[mGuidListCount - 1].GuidId == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
 \r
@@ -2065,7 +2061,7 @@ GetGuidFromStringName(
     }\r
   }\r
 \r
-  for (LoopCount = 0, ListWalker = GuidList; GuidList != NULL && LoopCount < GuidListCount; LoopCount++, ListWalker++) {\r
+  for (LoopCount = 0, ListWalker = mGuidList; mGuidList != NULL && LoopCount < mGuidListCount; LoopCount++, ListWalker++) {\r
     String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);\r
     if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {\r
       *Guid = ListWalker->GuidId;\r
@@ -2190,7 +2186,6 @@ GetStringNameFromHandle(
   @retval EFI_SUCCESS     The operation was successful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 InternalShellInitHandleList(\r
   VOID\r
   )\r
@@ -2723,7 +2718,7 @@ ParseHandleDatabaseByRelationship (
   Gets handles for any child controllers of the passed in controller.\r
 \r
   @param[in] ControllerHandle       The handle of the "parent controller"\r
-  @param[in] MatchingHandleCount    Pointer to the number of handles in\r
+  @param[out] MatchingHandleCount   Pointer to the number of handles in\r
                                     MatchingHandleBuffer on return.\r
   @param[out] MatchingHandleBuffer  Buffer containing handles on a successful\r
                                     return.\r
@@ -2735,7 +2730,7 @@ EFI_STATUS
 EFIAPI\r
 ParseHandleDatabaseForChildControllers(\r
   IN CONST EFI_HANDLE       ControllerHandle,\r
-  IN UINTN                  *MatchingHandleCount,\r
+  OUT UINTN                 *MatchingHandleCount,\r
   OUT EFI_HANDLE            **MatchingHandleBuffer OPTIONAL\r
   )\r
 {\r
@@ -2802,11 +2797,18 @@ ParseHandleDatabaseForChildControllers(
 \r
   FreePool (DriverBindingHandleBuffer);\r
 \r
+  if (MatchingHandleBuffer == NULL || *MatchingHandleCount == 0) {\r
+    //\r
+    // The caller is not interested in the actual handles, or we've found none.\r
+    //\r
+    FreePool (HandleBufferForReturn);\r
+    HandleBufferForReturn = NULL;\r
+  }\r
+\r
   if (MatchingHandleBuffer != NULL) {\r
     *MatchingHandleBuffer = HandleBufferForReturn;\r
-  } else {\r
-    FreePool(HandleBufferForReturn);\r
   }\r
+\r
   ASSERT ((MatchingHandleBuffer == NULL) ||\r
           (*MatchingHandleCount == 0 && *MatchingHandleBuffer == NULL) ||\r
           (*MatchingHandleCount != 0 && *MatchingHandleBuffer != NULL));\r
@@ -2830,7 +2832,6 @@ ParseHandleDatabaseForChildControllers(
   @return                           A pointer to (*DestinationBuffer).\r
 **/\r
 VOID*\r
-EFIAPI\r
 BuffernCatGrow (\r
   IN OUT VOID   **DestinationBuffer,\r
   IN OUT UINTN  *DestinationSize,\r