Revision: 18320
          http://sourceforge.net/p/edk2/code/18320
Author:   lzeng14
Date:     2015-08-26 09:46:29 +0000 (Wed, 26 Aug 2015)
Log Message:
-----------
MdeModulePkg FaultTolerantWrite: Error handling for erase operation failure

There may be anti-flash wear out feature to forbid erase operation after end of 
dxe.
The code is missing some error handling for erase operation failure,
it should return directly after the erase operation failed.

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/FaultTolerantWriteDxe/FaultTolerantWrite.c
    trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c

Modified: 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.c
===================================================================
--- 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.c    
    2015-08-26 08:31:27 UTC (rev 18319)
+++ 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.c    
    2015-08-26 09:46:29 UTC (rev 18320)
@@ -3,7 +3,7 @@
   These are the common Fault Tolerant Write (FTW) functions that are shared 
   by DXE FTW driver and SMM FTW driver.
 
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2015, 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        
@@ -526,6 +526,11 @@
   // Do not assume Spare Block and Target Block have same block size
   //
   Status  = FtwEraseSpareBlock (FtwDevice);
+  if (EFI_ERROR (Status)) {
+    FreePool (MyBuffer);
+    FreePool (SpareBuffer);
+    return EFI_ABORTED;
+  }
   Ptr     = MyBuffer;
   for (Index = 0; MyBufferSize > 0; Index += 1) {
     if (MyBufferSize > FtwDevice->SpareBlockSize) {
@@ -585,6 +590,10 @@
   // Restore spare backup buffer into spare block , if no failure happened 
during FtwWrite.
   //
   Status  = FtwEraseSpareBlock (FtwDevice);
+  if (EFI_ERROR (Status)) {
+    FreePool (SpareBuffer);
+    return EFI_ABORTED;
+  }
   Ptr     = SpareBuffer;
   for (Index = 0; Index < FtwDevice->NumberOfSpareBlock; Index += 1) {
     MyLength = FtwDevice->SpareBlockSize;
@@ -706,7 +715,10 @@
   // Erase Spare block
   // This is restart, no need to keep spareblock content.
   //
-  FtwEraseSpareBlock (FtwDevice);
+  Status = FtwEraseSpareBlock (FtwDevice);
+  if (EFI_ERROR (Status)) {
+    return EFI_ABORTED;
+  }
 
   DEBUG ((EFI_D_ERROR, "Ftw: Restart() success \n"));
   return EFI_SUCCESS;

Modified: 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
===================================================================
--- 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c    
    2015-08-26 08:31:27 UTC (rev 18319)
+++ 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c    
    2015-08-26 09:46:29 UTC (rev 18320)
@@ -2,7 +2,7 @@
 
    Internal functions to operate Working Block Space.
 
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2015, 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        
@@ -510,6 +510,11 @@
   // Write the memory buffer to spare block
   //
   Status  = FtwEraseSpareBlock (FtwDevice);
+  if (EFI_ERROR (Status)) {
+    FreePool (TempBuffer);
+    FreePool (SpareBuffer);
+    return EFI_ABORTED;
+  }
   Ptr     = TempBuffer;
   for (Index = 0; TempBufferSize > 0; Index += 1) {
     if (TempBufferSize > FtwDevice->SpareBlockSize) {
@@ -584,6 +589,10 @@
   // Restore spare backup buffer into spare block , if no failure happened 
during FtwWrite.
   //
   Status  = FtwEraseSpareBlock (FtwDevice);
+  if (EFI_ERROR (Status)) {
+    FreePool (SpareBuffer);
+    return EFI_ABORTED;
+  }
   Ptr     = SpareBuffer;
   for (Index = 0; Index < FtwDevice->NumberOfSpareBlock; Index += 1) {
     Length = FtwDevice->SpareBlockSize;


------------------------------------------------------------------------------
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to