]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeMoudlePkg/CapsulePei: Optimize GetScatterGatherHeadEntries
authorZhichao Gao <zhichao.gao@intel.com>
Mon, 10 Jun 2019 01:52:22 +0000 (09:52 +0800)
committerHao A Wu <hao.a.wu@intel.com>
Mon, 24 Jun 2019 01:18:32 +0000 (09:18 +0800)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1853

Rename the MACRO from MAX_SG_LIST_HEADS to DEFAULT_SG_LIST_HEADS.
GetScatterGatherHeadEntries: use allocated buffer instead of fixed
array to handle the condition which the SG list is larger then the
array size.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Signed-off-by: Zhichao gao <zhichao.gao@intel.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
MdeModulePkg/Universal/CapsulePei/UefiCapsule.c

index ce6d95a7866e4b52f375c277be54cce8502f0928..3ac95b7be67c994c1812dec4aa1f11a2a41ceb2e 100644 (file)
@@ -10,6 +10,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 \r
 #include "Capsule.h"\r
 \r
+#define DEFAULT_SG_LIST_HEADS       (20)\r
+\r
 #ifdef MDE_CPU_IA32\r
 //\r
 // Global Descriptor Table (GDT)\r
@@ -841,8 +843,6 @@ AreCapsulesStaged (
   return FALSE;\r
 }\r
 \r
-#define MAX_SG_LIST_HEADS (20)\r
-\r
 /**\r
   Check all the variables for SG list heads and get the count and addresses.\r
 \r
@@ -861,17 +861,19 @@ GetScatterGatherHeadEntries (
   OUT EFI_PHYSICAL_ADDRESS **HeadList\r
   )\r
 {\r
-  EFI_STATUS                       Status;\r
-  UINTN                            Size;\r
-  UINTN                            Index;\r
-  UINTN                            TempIndex;\r
-  UINTN                            ValidIndex;\r
-  BOOLEAN                          Flag;\r
-  CHAR16                           CapsuleVarName[30];\r
-  CHAR16                           *TempVarName;\r
-  EFI_PHYSICAL_ADDRESS             CapsuleDataPtr64;\r
-  EFI_PEI_READ_ONLY_VARIABLE2_PPI  *PPIVariableServices;\r
-  EFI_PHYSICAL_ADDRESS             TempList[MAX_SG_LIST_HEADS];\r
+  EFI_STATUS                        Status;\r
+  UINTN                             Size;\r
+  UINTN                             Index;\r
+  UINTN                             TempIndex;\r
+  UINTN                             ValidIndex;\r
+  BOOLEAN                           Flag;\r
+  CHAR16                            CapsuleVarName[30];\r
+  CHAR16                            *TempVarName;\r
+  EFI_PHYSICAL_ADDRESS              CapsuleDataPtr64;\r
+  EFI_PEI_READ_ONLY_VARIABLE2_PPI   *PPIVariableServices;\r
+  EFI_PHYSICAL_ADDRESS              *TempList;\r
+  EFI_PHYSICAL_ADDRESS              *EnlargedTempList;\r
+  UINTN                             TempListLength;\r
 \r
   Index             = 0;\r
   TempVarName       = NULL;\r
@@ -901,12 +903,22 @@ GetScatterGatherHeadEntries (
     return Status;\r
   }\r
 \r
+  //\r
+  // Allocate memory for sg list head\r
+  //\r
+  TempListLength = DEFAULT_SG_LIST_HEADS * sizeof (EFI_PHYSICAL_ADDRESS);\r
+  TempList = AllocateZeroPool (TempListLength);\r
+  if (TempList == NULL) {\r
+    DEBUG((DEBUG_ERROR, "Failed to allocate memory\n"));\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
   //\r
   // setup var name buffer for update capsules\r
   //\r
   StrCpyS (CapsuleVarName, sizeof (CapsuleVarName) / sizeof (CHAR16), EFI_CAPSULE_VARIABLE_NAME);\r
   TempVarName = CapsuleVarName + StrLen (CapsuleVarName);\r
-  while (ValidIndex < MAX_SG_LIST_HEADS) {\r
+  while (TRUE) {\r
     if (Index != 0) {\r
       UnicodeValueToStringS (\r
         TempVarName,\r
@@ -948,6 +960,17 @@ GetScatterGatherHeadEntries (
       continue;\r
     }\r
 \r
+    //\r
+    // The TempList is full, enlarge it\r
+    //\r
+    if ((ValidIndex + 1) >= TempListLength) {\r
+      EnlargedTempList = AllocateZeroPool (TempListLength * 2);\r
+      CopyMem (EnlargedTempList, TempList, TempListLength);\r
+      FreePool (TempList);\r
+      TempList = EnlargedTempList;\r
+      TempListLength *= 2;\r
+    }\r
+\r
     //\r
     // add it to the cached list\r
     //\r