]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.c
MdeModulePkg FaultTolerantWrite: Error handling for erase operation failure
[mirror_edk2.git] / MdeModulePkg / Universal / FaultTolerantWriteDxe / FaultTolerantWrite.c
index f08f280b46adf43fbd25cf5fac4b8afbb2a401eb..7a6c377854d82240e906441a473890282734b1c7 100644 (file)
@@ -3,7 +3,7 @@
   These are the common Fault Tolerant Write (FTW) functions that are shared \r
   by DXE FTW driver and SMM FTW driver.\r
 \r
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
@@ -526,6 +526,11 @@ FtwWrite (
   // Do not assume Spare Block and Target Block have same block size\r
   //\r
   Status  = FtwEraseSpareBlock (FtwDevice);\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (MyBuffer);\r
+    FreePool (SpareBuffer);\r
+    return EFI_ABORTED;\r
+  }\r
   Ptr     = MyBuffer;\r
   for (Index = 0; MyBufferSize > 0; Index += 1) {\r
     if (MyBufferSize > FtwDevice->SpareBlockSize) {\r
@@ -585,6 +590,10 @@ FtwWrite (
   // Restore spare backup buffer into spare block , if no failure happened during FtwWrite.\r
   //\r
   Status  = FtwEraseSpareBlock (FtwDevice);\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (SpareBuffer);\r
+    return EFI_ABORTED;\r
+  }\r
   Ptr     = SpareBuffer;\r
   for (Index = 0; Index < FtwDevice->NumberOfSpareBlock; Index += 1) {\r
     MyLength = FtwDevice->SpareBlockSize;\r
@@ -706,7 +715,10 @@ FtwRestart (
   // Erase Spare block\r
   // This is restart, no need to keep spareblock content.\r
   //\r
-  FtwEraseSpareBlock (FtwDevice);\r
+  Status = FtwEraseSpareBlock (FtwDevice);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_ABORTED;\r
+  }\r
 \r
   DEBUG ((EFI_D_ERROR, "Ftw: Restart() success \n"));\r
   return EFI_SUCCESS;\r