]> git.proxmox.com Git - mirror_edk2.git/commitdiff
PerformancePkg/Dp_App: Refine the code of locating all handles in DpTrace.c.
authorCinnamon Shia <cinnamon.shia@hpe.com>
Mon, 15 Feb 2016 09:07:14 +0000 (17:07 +0800)
committerStar Zeng <star.zeng@intel.com>
Thu, 18 Feb 2016 01:40:35 +0000 (09:40 +0800)
Replace gBS->LocateHandle with gBS->LocateHandleBuffer

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Cinnamon Shia <cinnamon.shia@hpe.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Samer El-Haj-Mahmoud <elhaj@hpe.com>
PerformancePkg/Dp_App/DpTrace.c

index d3df30ff28ab79c8e4a5b2c25e5d8a4c1af05856..632904f339408145aa2ac8a91610864ef4cb97aa 100644 (file)
@@ -2,7 +2,7 @@
   Trace reporting for the Dp utility.\r
 \r
   Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
-  (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
+  (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -153,8 +153,7 @@ DumpAllTrace(
   UINTN                     TIndex;\r
 \r
   EFI_HANDLE                *HandleBuffer;\r
-  UINTN                     Size;\r
-  EFI_HANDLE                TempHandle;\r
+  UINTN                     HandleCount;\r
   EFI_STATUS                Status;\r
   EFI_STRING                StringPtrUnknown;\r
 \r
@@ -166,17 +165,7 @@ DumpAllTrace(
 \r
   // Get Handle information\r
   //\r
-  Size = 0;\r
-  HandleBuffer = &TempHandle;\r
-  Status  = gBS->LocateHandle (AllHandles, NULL, NULL, &Size, &TempHandle);\r
-  if (Status == EFI_BUFFER_TOO_SMALL) {\r
-    HandleBuffer = AllocatePool (Size);\r
-    ASSERT (HandleBuffer != NULL);\r
-    if (HandleBuffer == NULL) {\r
-      return;\r
-    }\r
-    Status  = gBS->LocateHandle (AllHandles, NULL, NULL, &Size, HandleBuffer);\r
-  }\r
+  Status  = gBS->LocateHandleBuffer (AllHandles, NULL, NULL, &HandleCount, &HandleBuffer);\r
   if (EFI_ERROR (Status)) {\r
     PrintToken (STRING_TOKEN (STR_DP_HANDLES_ERROR), Status);\r
   }\r
@@ -232,7 +221,7 @@ DumpAllTrace(
       AsciiStrToUnicodeStr (Measurement.Token, mUnicodeToken);\r
       if (Measurement.Handle != NULL) {\r
         // See if the Handle is in the HandleBuffer\r
-        for (TIndex = 0; TIndex < (Size / sizeof(HandleBuffer[0])); TIndex++) {\r
+        for (TIndex = 0; TIndex < HandleCount; TIndex++) {\r
           if (Measurement.Handle == HandleBuffer[TIndex]) {\r
             GetNameFromHandle (HandleBuffer[TIndex]);\r
             break;\r
@@ -270,7 +259,7 @@ DumpAllTrace(
       }\r
     }\r
   }\r
-  if (HandleBuffer != &TempHandle) {\r
+  if (HandleBuffer != NULL) {\r
     FreePool (HandleBuffer);\r
   }\r
   SafeFreePool ((VOID *) IncFlag);\r
@@ -536,8 +525,7 @@ ProcessHandles(
   UINTN                     Index;\r
   UINTN                     LogEntryKey;\r
   UINTN                     Count;\r
-  UINTN                     Size;\r
-  EFI_HANDLE                TempHandle;\r
+  UINTN                     HandleCount;\r
   EFI_STATUS                Status;\r
   EFI_STRING                StringPtrUnknown;\r
 \r
@@ -548,17 +536,7 @@ ProcessHandles(
   FreePool (StringPtr);\r
   FreePool (StringPtrUnknown);\r
 \r
-  Size = 0;\r
-  HandleBuffer = &TempHandle;\r
-  Status  = gBS->LocateHandle (AllHandles, NULL, NULL, &Size, &TempHandle);\r
-  if (Status == EFI_BUFFER_TOO_SMALL) {\r
-    HandleBuffer = AllocatePool (Size);\r
-    ASSERT (HandleBuffer != NULL);\r
-    if (HandleBuffer == NULL) {\r
-      return Status;\r
-    }\r
-    Status  = gBS->LocateHandle (AllHandles, NULL, NULL, &Size, HandleBuffer);\r
-  }\r
+  Status = gBS->LocateHandleBuffer (AllHandles, NULL, NULL, &HandleCount, &HandleBuffer);\r
   if (EFI_ERROR (Status)) {\r
     PrintToken (STRING_TOKEN (STR_DP_HANDLES_ERROR), Status);\r
   }\r
@@ -598,7 +576,7 @@ ProcessHandles(
       mGaugeString[0] = 0;    // Empty driver name by default\r
       AsciiStrToUnicodeStr (Measurement.Token, mUnicodeToken);\r
       // See if the Handle is in the HandleBuffer\r
-      for (Index = 0; Index < (Size / sizeof(HandleBuffer[0])); Index++) {\r
+      for (Index = 0; Index < HandleCount; Index++) {\r
         if (Measurement.Handle == HandleBuffer[Index]) {\r
           GetNameFromHandle (HandleBuffer[Index]); // Name is put into mGaugeString\r
           break;\r
@@ -632,7 +610,7 @@ ProcessHandles(
       }\r
     }\r
   }\r
-  if (HandleBuffer != &TempHandle) {\r
+  if (HandleBuffer != NULL) {\r
     FreePool (HandleBuffer);\r
   }\r
   return Status;\r