\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
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
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
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
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