Revision: 14832
          http://sourceforge.net/p/edk2/code/14832
Author:   lzeng14
Date:     2013-11-12 13:31:43 +0000 (Tue, 12 Nov 2013)
Log Message:
-----------
MdeModulePkg and SecurityPkg Variable: Optimize the code to reduce some SMRAM 
consumption during variable reclaiming.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <[email protected]>
Reviewed-by: Liming Gao <[email protected]>

Modified Paths:
--------------
    trunk/edk2/MdeModulePkg/Universal/Variable/RuntimeDxe/Reclaim.c
    trunk/edk2/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
    trunk/edk2/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h
    trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/Reclaim.c
    trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c
    trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.h

Modified: trunk/edk2/MdeModulePkg/Universal/Variable/RuntimeDxe/Reclaim.c
===================================================================
--- trunk/edk2/MdeModulePkg/Universal/Variable/RuntimeDxe/Reclaim.c     
2013-11-08 03:35:14 UTC (rev 14831)
+++ trunk/edk2/MdeModulePkg/Universal/Variable/RuntimeDxe/Reclaim.c     
2013-11-12 13:31:43 UTC (rev 14832)
@@ -3,7 +3,7 @@
   Handles non-volatile variable store garbage collection, using FTW
   (Fault Tolerant Write) protocol.
 
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
@@ -99,8 +99,7 @@
   VariableBase. Fault Tolerant Write protocol is used for writing.
 
   @param  VariableBase   Base address of variable to write
-  @param  Buffer         Point to the data buffer.
-  @param  BufferSize     The number of bytes of the data Buffer.
+  @param  VariableBuffer Point to the variable data buffer.
 
   @retval EFI_SUCCESS    The function completed successfully.
   @retval EFI_NOT_FOUND  Fail to locate Fault Tolerant Write protocol.
@@ -110,15 +109,13 @@
 EFI_STATUS
 FtwVariableSpace (
   IN EFI_PHYSICAL_ADDRESS   VariableBase,
-  IN UINT8                  *Buffer,
-  IN UINTN                  BufferSize
+  IN VARIABLE_STORE_HEADER  *VariableBuffer
   )
 {
   EFI_STATUS                         Status;
   EFI_HANDLE                         FvbHandle;
   EFI_LBA                            VarLba;
   UINTN                              VarOffset;
-  UINT8                              *FtwBuffer;
   UINTN                              FtwBufferSize;
   EFI_FAULT_TOLERANT_WRITE_PROTOCOL  *FtwProtocol;
 
@@ -143,18 +140,10 @@
   if (EFI_ERROR (Status)) {
     return EFI_ABORTED;
   }
-  //
-  // Prepare for the variable data.
-  //
+
   FtwBufferSize = ((VARIABLE_STORE_HEADER *) ((UINTN) VariableBase))->Size;
-  FtwBuffer     = AllocatePool (FtwBufferSize);
-  if (FtwBuffer == NULL) {
-    return EFI_OUT_OF_RESOURCES;
-  }
+  ASSERT (FtwBufferSize == VariableBuffer->Size);
 
-  SetMem (FtwBuffer, FtwBufferSize, (UINT8) 0xff);
-  CopyMem (FtwBuffer, Buffer, BufferSize);
-
   //
   // FTW write record.
   //
@@ -165,9 +154,8 @@
                           FtwBufferSize,  // NumBytes
                           NULL,           // PrivateData NULL
                           FvbHandle,      // Fvb Handle
-                          FtwBuffer       // write buffer
+                          (VOID *) VariableBuffer // write buffer
                           );
 
-  FreePool (FtwBuffer);
   return Status;
 }

Modified: trunk/edk2/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
===================================================================
--- trunk/edk2/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c    
2013-11-08 03:35:14 UTC (rev 14831)
+++ trunk/edk2/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c    
2013-11-12 13:31:43 UTC (rev 14832)
@@ -615,42 +615,51 @@
   CommonVariableTotalSize = 0;
   HwErrVariableTotalSize  = 0;
 
-  //
-  // Start Pointers for the variable.
-  //
-  Variable          = GetStartPointer (VariableStoreHeader);
-  MaximumBufferSize = sizeof (VARIABLE_STORE_HEADER);
+  if (IsVolatile) {
+    //
+    // Start Pointers for the variable.
+    //
+    Variable          = GetStartPointer (VariableStoreHeader);
+    MaximumBufferSize = sizeof (VARIABLE_STORE_HEADER);
 
-  while (IsValidVariableHeader (Variable)) {
-    NextVariable = GetNextVariablePtr (Variable);
-    if ((Variable->State == VAR_ADDED || Variable->State == 
(VAR_IN_DELETED_TRANSITION & VAR_ADDED)) &&
-        Variable != UpdatingVariable &&
-        Variable != UpdatingInDeletedTransition
-       ) {
-      VariableSize = (UINTN) NextVariable - (UINTN) Variable;
-      MaximumBufferSize += VariableSize;
+    while (IsValidVariableHeader (Variable)) {
+      NextVariable = GetNextVariablePtr (Variable);
+      if ((Variable->State == VAR_ADDED || Variable->State == 
(VAR_IN_DELETED_TRANSITION & VAR_ADDED)) &&
+          Variable != UpdatingVariable &&
+          Variable != UpdatingInDeletedTransition
+         ) {
+        VariableSize = (UINTN) NextVariable - (UINTN) Variable;
+        MaximumBufferSize += VariableSize;
+      }
+
+      Variable = NextVariable;
     }
 
-    Variable = NextVariable;
-  }
+    if (NewVariable != NULL) {
+      //
+      // Add the new variable size.
+      //
+      MaximumBufferSize += NewVariableSize;
+    }
 
-  if (NewVariable != NULL) {
     //
-    // Add the new variable size.
+    // Reserve the 1 Bytes with Oxff to identify the
+    // end of the variable buffer.
     //
-    MaximumBufferSize += NewVariableSize;
+    MaximumBufferSize += 1;
+    ValidBuffer = AllocatePool (MaximumBufferSize);
+    if (ValidBuffer == NULL) {
+      return EFI_OUT_OF_RESOURCES;
+    }
+  } else {
+    //
+    // For NV variable reclaim, don't allocate pool here and just use 
mNvVariableCache
+    // as the buffer to reduce SMRAM consumption for SMM variable driver.
+    //
+    MaximumBufferSize = mNvVariableCache->Size;
+    ValidBuffer = (UINT8 *) mNvVariableCache;
   }
 
-  //
-  // Reserve the 1 Bytes with Oxff to identify the 
-  // end of the variable buffer. 
-  // 
-  MaximumBufferSize += 1;
-  ValidBuffer = AllocatePool (MaximumBufferSize);
-  if (ValidBuffer == NULL) {
-    return EFI_OUT_OF_RESOURCES;
-  }
-
   SetMem (ValidBuffer, MaximumBufferSize, 0xff);
 
   //
@@ -770,6 +779,7 @@
     //
     SetMem ((UINT8 *) (UINTN) VariableBase, VariableStoreHeader->Size, 0xff);
     CopyMem ((UINT8 *) (UINTN) VariableBase, ValidBuffer, (UINTN) (CurrPtr - 
ValidBuffer));
+    *LastVariableOffset = (UINTN) (CurrPtr - ValidBuffer);
     Status  = EFI_SUCCESS;
   } else {
     //
@@ -777,34 +787,37 @@
     //
     Status = FtwVariableSpace (
               VariableBase,
-              ValidBuffer,
-              (UINTN) (CurrPtr - ValidBuffer)
+              (VARIABLE_STORE_HEADER *) ValidBuffer
               );
-    CopyMem (mNvVariableCache, (CHAR8 *)(UINTN)VariableBase, 
VariableStoreHeader->Size);
-  }
-  if (!EFI_ERROR (Status)) {
-    *LastVariableOffset = (UINTN) (CurrPtr - ValidBuffer);
-    if (!IsVolatile) {
+    if (!EFI_ERROR (Status)) {
+      *LastVariableOffset = (UINTN) (CurrPtr - ValidBuffer);
       mVariableModuleGlobal->HwErrVariableTotalSize = HwErrVariableTotalSize;
       mVariableModuleGlobal->CommonVariableTotalSize = CommonVariableTotalSize;
-    }
-  } else {
-    NextVariable  = GetStartPointer ((VARIABLE_STORE_HEADER 
*)(UINTN)VariableBase);
-    while (IsValidVariableHeader (NextVariable)) {
-      VariableSize = NextVariable->NameSize + NextVariable->DataSize + sizeof 
(VARIABLE_HEADER);
-      if ((!IsVolatile) && ((Variable->Attributes & 
EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {
-        mVariableModuleGlobal->HwErrVariableTotalSize += HEADER_ALIGN 
(VariableSize);
-      } else if ((!IsVolatile) && ((Variable->Attributes & 
EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {
-        mVariableModuleGlobal->CommonVariableTotalSize += HEADER_ALIGN 
(VariableSize);
+    } else {
+      NextVariable  = GetStartPointer ((VARIABLE_STORE_HEADER 
*)(UINTN)VariableBase);
+      while (IsValidVariableHeader (NextVariable)) {
+        VariableSize = NextVariable->NameSize + NextVariable->DataSize + 
sizeof (VARIABLE_HEADER);
+        if ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == 
EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
+          mVariableModuleGlobal->HwErrVariableTotalSize += HEADER_ALIGN 
(VariableSize);
+        } else if ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) 
!= EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
+          mVariableModuleGlobal->CommonVariableTotalSize += HEADER_ALIGN 
(VariableSize);
+        }
+
+        NextVariable = GetNextVariablePtr (NextVariable);
       }
-
-      NextVariable = GetNextVariablePtr (NextVariable);
+      *LastVariableOffset = (UINTN) NextVariable - (UINTN) VariableBase;
     }
-    *LastVariableOffset = (UINTN) NextVariable - (UINTN) VariableBase;
   }
 
 Done:
-  FreePool (ValidBuffer);
+  if (IsVolatile) {
+    FreePool (ValidBuffer);
+  } else {
+    //
+    // For NV variable reclaim, we use mNvVariableCache as the buffer, so copy 
the data back.
+    //
+    CopyMem (mNvVariableCache, (UINT8 *)(UINTN)VariableBase, 
VariableStoreHeader->Size);
+  }
 
   return Status;
 }

Modified: trunk/edk2/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h
===================================================================
--- trunk/edk2/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h    
2013-11-08 03:35:14 UTC (rev 14831)
+++ trunk/edk2/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h    
2013-11-12 13:31:43 UTC (rev 14832)
@@ -133,8 +133,7 @@
   VariableBase. Fault Tolerant Write protocol is used for writing.
 
   @param  VariableBase   Base address of the variable to write.
-  @param  Buffer         Point to the data buffer.
-  @param  BufferSize     The number of bytes of the data Buffer.
+  @param  VariableBuffer Point to the variable data buffer.
 
   @retval EFI_SUCCESS    The function completed successfully.
   @retval EFI_NOT_FOUND  Fail to locate Fault Tolerant Write protocol.
@@ -144,8 +143,7 @@
 EFI_STATUS
 FtwVariableSpace (
   IN EFI_PHYSICAL_ADDRESS   VariableBase,
-  IN UINT8                  *Buffer,
-  IN UINTN                  BufferSize
+  IN VARIABLE_STORE_HEADER  *VariableBuffer
   );
 
 

Modified: trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/Reclaim.c
===================================================================
--- trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/Reclaim.c   
2013-11-08 03:35:14 UTC (rev 14831)
+++ trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/Reclaim.c   
2013-11-12 13:31:43 UTC (rev 14832)
@@ -2,7 +2,7 @@
   Handles non-volatile variable store garbage collection, using FTW
   (Fault Tolerant Write) protocol.
 
-Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials 
 are licensed and made available under the terms and conditions of the BSD 
License 
 which accompanies this distribution.  The full text of the license may be 
found at 
@@ -98,8 +98,7 @@
   VariableBase. Fault Tolerant Write protocol is used for writing.
 
   @param  VariableBase   Base address of variable to write
-  @param  Buffer         Point to the data buffer.
-  @param  BufferSize     The number of bytes of the data Buffer.
+  @param  VariableBuffer Point to the variable data buffer.
 
   @retval EFI_SUCCESS    The function completed successfully.
   @retval EFI_NOT_FOUND  Fail to locate Fault Tolerant Write protocol.
@@ -109,15 +108,13 @@
 EFI_STATUS
 FtwVariableSpace (
   IN EFI_PHYSICAL_ADDRESS   VariableBase,
-  IN UINT8                  *Buffer,
-  IN UINTN                  BufferSize
+  IN VARIABLE_STORE_HEADER  *VariableBuffer
   )
 {
   EFI_STATUS                         Status;
   EFI_HANDLE                         FvbHandle;
   EFI_LBA                            VarLba;
   UINTN                              VarOffset;
-  UINT8                              *FtwBuffer;
   UINTN                              FtwBufferSize;
   EFI_FAULT_TOLERANT_WRITE_PROTOCOL  *FtwProtocol;
 
@@ -142,18 +139,10 @@
   if (EFI_ERROR (Status)) {
     return EFI_ABORTED;
   }
-  //
-  // Prepare for the variable data.
-  //
+
   FtwBufferSize = ((VARIABLE_STORE_HEADER *) ((UINTN) VariableBase))->Size;
-  FtwBuffer     = AllocatePool (FtwBufferSize);
-  if (FtwBuffer == NULL) {
-    return EFI_OUT_OF_RESOURCES;
-  }
+  ASSERT (FtwBufferSize == VariableBuffer->Size);
 
-  SetMem (FtwBuffer, FtwBufferSize, (UINT8) 0xff);
-  CopyMem (FtwBuffer, Buffer, BufferSize);
-
   //
   // FTW write record.
   //
@@ -164,9 +153,8 @@
                           FtwBufferSize,  // NumBytes
                           NULL,           // PrivateData NULL
                           FvbHandle,      // Fvb Handle
-                          FtwBuffer       // write buffer
+                          (VOID *) VariableBuffer // write buffer
                           );
 
-  FreePool (FtwBuffer);
   return Status;
 }

Modified: trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c
===================================================================
--- trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c  
2013-11-08 03:35:14 UTC (rev 14831)
+++ trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c  
2013-11-12 13:31:43 UTC (rev 14832)
@@ -701,6 +701,7 @@
   *NewPubKeyIndex = AllocateZeroPool ((PubKeyNumber + 1) * sizeof (UINT32));
   if (*NewPubKeyIndex == NULL) {
     FreePool (*NewPubKeyStore);
+    *NewPubKeyStore = NULL;
     return EFI_OUT_OF_RESOURCES;
   }
 
@@ -790,43 +791,52 @@
   NewPubKeyStore = NULL;
   NewPubKeySize  = 0;
   PubKeyHeader   = NULL;
-  
-  //
-  // Start Pointers for the variable.
-  //
-  Variable          = GetStartPointer (VariableStoreHeader);
-  MaximumBufferSize = sizeof (VARIABLE_STORE_HEADER);
 
-  while (IsValidVariableHeader (Variable)) {
-    NextVariable = GetNextVariablePtr (Variable);
-    if ((Variable->State == VAR_ADDED || Variable->State == 
(VAR_IN_DELETED_TRANSITION & VAR_ADDED)) &&
-        Variable != UpdatingVariable &&
-        Variable != UpdatingInDeletedTransition
-       ) {
-      VariableSize = (UINTN) NextVariable - (UINTN) Variable;
-      MaximumBufferSize += VariableSize;
+  if (IsVolatile) {
+    //
+    // Start Pointers for the variable.
+    //
+    Variable          = GetStartPointer (VariableStoreHeader);
+    MaximumBufferSize = sizeof (VARIABLE_STORE_HEADER);
+
+    while (IsValidVariableHeader (Variable)) {
+      NextVariable = GetNextVariablePtr (Variable);
+      if ((Variable->State == VAR_ADDED || Variable->State == 
(VAR_IN_DELETED_TRANSITION & VAR_ADDED)) &&
+          Variable != UpdatingVariable &&
+          Variable != UpdatingInDeletedTransition
+         ) {
+        VariableSize = (UINTN) NextVariable - (UINTN) Variable;
+        MaximumBufferSize += VariableSize;
+      }
+
+      Variable = NextVariable;
     }
 
-    Variable = NextVariable;
-  }
+    if (NewVariable != NULL) {
+      //
+      // Add the new variable size.
+      //
+      MaximumBufferSize += NewVariableSize;
+    }
 
-  if (NewVariable != NULL) {
     //
-    // Add the new variable size.
+    // Reserve the 1 Bytes with Oxff to identify the
+    // end of the variable buffer.
     //
-    MaximumBufferSize += NewVariableSize;
+    MaximumBufferSize += 1;
+    ValidBuffer = AllocatePool (MaximumBufferSize);
+    if (ValidBuffer == NULL) {
+      return EFI_OUT_OF_RESOURCES;
+    }
+  } else {
+    //
+    // For NV variable reclaim, don't allocate pool here and just use 
mNvVariableCache
+    // as the buffer to reduce SMRAM consumption for SMM variable driver.
+    //
+    MaximumBufferSize = mNvVariableCache->Size;
+    ValidBuffer = (UINT8 *) mNvVariableCache;
   }
 
-  //
-  // Reserve the 1 Bytes with Oxff to identify the
-  // end of the variable buffer.
-  //
-  MaximumBufferSize += 1;
-  ValidBuffer = AllocatePool (MaximumBufferSize);
-  if (ValidBuffer == NULL) {
-    return EFI_OUT_OF_RESOURCES;
-  }
-
   SetMem (ValidBuffer, MaximumBufferSize, 0xff);
 
   //
@@ -848,14 +858,13 @@
                &NewPubKeySize
                );
     if (EFI_ERROR (Status)) {
-      FreePool (ValidBuffer);
-      return Status;
+      goto Done;
     }
 
     //
     // Refresh the PubKeyIndex for all valid variables (ADDED and 
IN_DELETED_TRANSITION).
     //
-    Variable = GetStartPointer (mNvVariableCache);
+    Variable = GetStartPointer (VariableStoreHeader);
     while (IsValidVariableHeader (Variable)) {
       NextVariable = GetNextVariablePtr (Variable);
       if (Variable->State == VAR_ADDED || Variable->State == 
(VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
@@ -887,10 +896,8 @@
     //
     ASSERT (PubKeyHeader != NULL);
     if (PubKeyHeader == NULL) {
-      FreePool (ValidBuffer);
-      FreePool (NewPubKeyIndex);
-      FreePool (NewPubKeyStore);
-      return EFI_DEVICE_ERROR;
+      Status = EFI_DEVICE_ERROR;
+      goto Done;
     }
     CopyMem (CurrPtr, (UINT8*) PubKeyHeader, sizeof (VARIABLE_HEADER));
     Variable = (VARIABLE_HEADER*) CurrPtr;
@@ -1012,6 +1019,7 @@
     //
     SetMem ((UINT8 *) (UINTN) VariableBase, VariableStoreHeader->Size, 0xff);
     CopyMem ((UINT8 *) (UINTN) VariableBase, ValidBuffer, (UINTN) (CurrPtr - 
ValidBuffer));
+    *LastVariableOffset = (UINTN) (CurrPtr - ValidBuffer);
     Status  = EFI_SUCCESS;
   } else {
     //
@@ -1019,43 +1027,46 @@
     //
     Status = FtwVariableSpace (
               VariableBase,
-              ValidBuffer,
-              (UINTN) (CurrPtr - ValidBuffer)
+              (VARIABLE_STORE_HEADER *) ValidBuffer
               );
-    CopyMem (mNvVariableCache, (CHAR8 *)(UINTN)VariableBase, 
VariableStoreHeader->Size);
-  }
-  if (!EFI_ERROR (Status)) {
-    *LastVariableOffset = (UINTN) (CurrPtr - ValidBuffer);
-    if (!IsVolatile) {
+    if (!EFI_ERROR (Status)) {
+      *LastVariableOffset = (UINTN) (CurrPtr - ValidBuffer);
       mVariableModuleGlobal->HwErrVariableTotalSize = HwErrVariableTotalSize;
       mVariableModuleGlobal->CommonVariableTotalSize = CommonVariableTotalSize;
+    } else {
+      NextVariable  = GetStartPointer ((VARIABLE_STORE_HEADER 
*)(UINTN)VariableBase);
+      while (IsValidVariableHeader (NextVariable)) {
+        VariableSize = NextVariable->NameSize + NextVariable->DataSize + 
sizeof (VARIABLE_HEADER);
+        if ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == 
EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
+          mVariableModuleGlobal->HwErrVariableTotalSize += HEADER_ALIGN 
(VariableSize);
+        } else if ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) 
!= EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
+          mVariableModuleGlobal->CommonVariableTotalSize += HEADER_ALIGN 
(VariableSize);
+        }
+
+        NextVariable = GetNextVariablePtr (NextVariable);
+      }
+      *LastVariableOffset = (UINTN) NextVariable - (UINTN) VariableBase;
     }
+  }
+
+Done:
+  if (IsVolatile) {
+    FreePool (ValidBuffer);
   } else {
-    NextVariable  = GetStartPointer ((VARIABLE_STORE_HEADER 
*)(UINTN)VariableBase);
-    while (IsValidVariableHeader (NextVariable)) {
-      VariableSize = NextVariable->NameSize + NextVariable->DataSize + sizeof 
(VARIABLE_HEADER);
-      if ((!IsVolatile) && ((Variable->Attributes & 
EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {
-        mVariableModuleGlobal->HwErrVariableTotalSize += HEADER_ALIGN 
(VariableSize);
-      } else if ((!IsVolatile) && ((Variable->Attributes & 
EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {
-        mVariableModuleGlobal->CommonVariableTotalSize += HEADER_ALIGN 
(VariableSize);
-      }
+    //
+    // For NV variable reclaim, we use mNvVariableCache as the buffer, so copy 
the data back.
+    //
+    CopyMem (mNvVariableCache, (UINT8 *)(UINTN)VariableBase, 
VariableStoreHeader->Size);
 
-      NextVariable = GetNextVariablePtr (NextVariable);
+    if (NewPubKeyStore != NULL) {
+      FreePool (NewPubKeyStore);
     }
-    *LastVariableOffset = (UINTN) NextVariable - (UINTN) VariableBase;
-  }
 
-  if (NewPubKeyStore != NULL) {
-    FreePool (NewPubKeyStore);
+    if (NewPubKeyIndex != NULL) {
+      FreePool (NewPubKeyIndex);
+    }
   }
 
-  if (NewPubKeyIndex != NULL) {
-    FreePool (NewPubKeyIndex);
-  }
-
-Done:
-  FreePool (ValidBuffer);
-
   return Status;
 }
 

Modified: trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.h
===================================================================
--- trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.h  
2013-11-08 03:35:14 UTC (rev 14831)
+++ trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.h  
2013-11-12 13:31:43 UTC (rev 14832)
@@ -143,8 +143,7 @@
   VariableBase. Fault Tolerant Write protocol is used for writing.
 
   @param  VariableBase   Base address of the variable to write.
-  @param  Buffer         Point to the data buffer.
-  @param  BufferSize     The number of bytes of the data Buffer.
+  @param  VariableBuffer Point to the variable data buffer.
 
   @retval EFI_SUCCESS    The function completed successfully.
   @retval EFI_NOT_FOUND  Fail to locate Fault Tolerant Write protocol.
@@ -154,8 +153,7 @@
 EFI_STATUS
 FtwVariableSpace (
   IN EFI_PHYSICAL_ADDRESS   VariableBase,
-  IN UINT8                  *Buffer,
-  IN UINTN                  BufferSize
+  IN VARIABLE_STORE_HEADER  *VariableBuffer
   );
 
 /**

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore
techniques for threading, error checking, porting, and tuning. Get the most 
from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to