]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
MdeModulePkg FaultTolerantWrite: Error handling for erase operation failure
[mirror_edk2.git] / MdeModulePkg / Universal / FaultTolerantWriteDxe / UpdateWorkingBlock.c
index f3e6eac5d2e30ef0b099d3efbf8cebbbb3efe2e0..31f1e0bda6fe8c1e5cfcdefb5308a110e7122282 100644 (file)
@@ -2,7 +2,7 @@
 \r
    Internal functions to operate Working Block Space.\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
@@ -510,6 +510,11 @@ FtwReclaimWorkSpace (
   // Write the memory buffer to spare block\r
   //\r
   Status  = FtwEraseSpareBlock (FtwDevice);\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (TempBuffer);\r
+    FreePool (SpareBuffer);\r
+    return EFI_ABORTED;\r
+  }\r
   Ptr     = TempBuffer;\r
   for (Index = 0; TempBufferSize > 0; Index += 1) {\r
     if (TempBufferSize > FtwDevice->SpareBlockSize) {\r
@@ -584,6 +589,10 @@ FtwReclaimWorkSpace (
   // 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
     Length = FtwDevice->SpareBlockSize;\r