]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
MdeModulePkg: Refine casting expression result to bigger size
[mirror_edk2.git] / MdeModulePkg / Universal / FaultTolerantWriteDxe / UpdateWorkingBlock.c
index f3e6eac5d2e30ef0b099d3efbf8cebbbb3efe2e0..b4327b56192124252096cd2397c653db70742df2 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 - 2017, 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
@@ -55,7 +55,7 @@ InitializeLocalWorkSpaceHeader (
     &gEdkiiWorkingBlockSignatureGuid,\r
     sizeof (EFI_GUID)\r
     );\r
-  mWorkingBlockHeader.WriteQueueSize = (UINT64) (PcdGet32 (PcdFlashNvStorageFtwWorkingSize) - sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER));\r
+  mWorkingBlockHeader.WriteQueueSize = PcdGet32 (PcdFlashNvStorageFtwWorkingSize) - sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER);\r
 \r
   //\r
   // Crc is calculated with all the fields except Crc and STATE, so leave them as FTW_ERASED_BYTE.\r
@@ -98,7 +98,7 @@ IsValidWorkSpace (
     return TRUE;\r
   }\r
 \r
-  DEBUG ((EFI_D_ERROR, "Ftw: Work block header check error\n"));\r
+  DEBUG ((EFI_D_INFO, "Ftw: Work block header check mismatch\n"));\r
   return FALSE;\r
 }\r
 \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