]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg/UefiDpLib: Refine the code of locating all handles in DpTrace.c.
authorCinnamon Shia <cinnamon.shia@hpe.com>
Mon, 15 Feb 2016 09:07:13 +0000 (17:07 +0800)
committerStar Zeng <star.zeng@intel.com>
Thu, 18 Feb 2016 01:40:30 +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: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Samer El-Haj-Mahmoud <elhaj@hpe.com>
ShellPkg/Library/UefiDpLib/DpTrace.c

index d17d514bf12ec613bf8019345fa54b98b292080f..22b83d0917dfc2267a53dcff64f0a59ca2835b70 100644 (file)
@@ -2,7 +2,7 @@
   Trace reporting for the Dp utility.\r
 \r
   Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.\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
     ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_HANDLES_ERROR), gDpHiiHandle, 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
             DpGetNameFromHandle (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
   SHELL_FREE_NON_NULL (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
     ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_HANDLES_ERROR), gDpHiiHandle, 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
           DpGetNameFromHandle (HandleBuffer[Index]); // Name is put into mGaugeString\r
           break;\r
@@ -630,7 +608,7 @@ ProcessHandles(
       }\r
     }\r
   }\r
-  if (HandleBuffer != &TempHandle) {\r
+  if (HandleBuffer != NULL) {\r
     FreePool (HandleBuffer);\r
   }\r
   return Status;\r