// The size of the VariableName, including the Unicode Null in bytes plus\r
// the DataSize is limited to maximum size of MAX_VARIABLE_SIZE (1024) bytes.\r
//\r
- else if (sizeof (VARIABLE_HEADER) + ArrayLength (VariableName) + DataSize > MAX_VARIABLE_SIZE) {\r
+ else if ((DataSize > MAX_VARIABLE_SIZE) ||\r
+ (sizeof (VARIABLE_HEADER) + ArrayLength (VariableName) + DataSize > MAX_VARIABLE_SIZE)) {\r
return EFI_INVALID_PARAMETER;\r
}\r
//\r
(((EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) (TempVariableStoreHeader)) -> HeaderLength);\r
VariableStoreEntry.Length = (UINT64) PcdGet32 (PcdFlashNvStorageVariableSize) - \\r
(((EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) (TempVariableStoreHeader)) -> HeaderLength);\r
-\r
- VariableStoreEntry.Length = (UINT64) PcdGet32 (PcdFlashNvStorageVariableSize);\r
//\r
// Mark the variable storage region of the FLASH as RUNTIME\r
//\r
\r
mVariableModuleGlobal->NonVolatileLastVariableOffset = (UINTN) NextVariable - (UINTN) CurrPtr;\r
\r
+ //\r
+ // Check if the free area is blow a threshold\r
+ //\r
+ if ((((VARIABLE_STORE_HEADER *)((UINTN) CurrPtr))->Size - mVariableModuleGlobal->NonVolatileLastVariableOffset) < VARIABLE_RECLAIM_THRESHOLD) {\r
+ Status = Reclaim (\r
+ mVariableModuleGlobal->VariableBase[Physical].NonVolatileVariableBase,\r
+ &mVariableModuleGlobal->NonVolatileLastVariableOffset,\r
+ FALSE\r
+ );\r
+ }\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ gBS->FreePool (mVariableModuleGlobal);\r
+ gBS->FreePool (VolatileVariableStore);\r
+ return Status;\r
+ }\r
+\r
//\r
// Check if the free area is really free.\r
//\r