MdeModulePkg FaultTolerantWritePei: Refine the code to avoid error report.
[mirror_edk2.git] / MdeModulePkg / Universal / FaultTolerantWritePei / FaultTolerantWritePei.c
index ec03216..14e18e5 100644 (file)
@@ -254,23 +254,26 @@ PeimFaultTolerantWriteInitialize (
                  );\r
     }\r
 \r
-    if (!EFI_ERROR (Status) && ((FtwLastWriteRecord->SpareComplete == FTW_VALID_STATE) && (FtwLastWriteRecord->DestinationComplete != FTW_VALID_STATE))) {\r
-      //\r
-      // If FTW last write was still in progress with SpareComplete set and DestinationComplete not set.\r
-      // It means the target buffer has been backed up in spare block, then target block has been erased,\r
-      // but the target buffer has not been writen in target block from spare block, we need to build\r
-      // FAULT_TOLERANT_WRITE_LAST_WRITE_DATA GUID hob to hold the FTW last write data.\r
-      //\r
-      FtwLastWrite.TargetAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) ((INT64) SpareAreaAddress + FtwLastWriteRecord->RelativeOffset);\r
-      FtwLastWrite.SpareAddress = SpareAreaAddress;\r
-      FtwLastWrite.Length = SpareAreaLength;\r
-      DEBUG ((\r
-        EFI_D_INFO,\r
-        "FtwPei last write data: TargetAddress - 0x%x SpareAddress - 0x%x Length - 0x%x\n",\r
-        (UINTN) FtwLastWrite.TargetAddress,\r
-        (UINTN) FtwLastWrite.SpareAddress,\r
-        (UINTN) FtwLastWrite.Length));\r
-      BuildGuidDataHob (&gEdkiiFaultTolerantWriteGuid, (VOID *) &FtwLastWrite, sizeof (FAULT_TOLERANT_WRITE_LAST_WRITE_DATA));\r
+    if (!EFI_ERROR (Status)) {\r
+      ASSERT (FtwLastWriteRecord != NULL);\r
+      if ((FtwLastWriteRecord->SpareComplete == FTW_VALID_STATE) && (FtwLastWriteRecord->DestinationComplete != FTW_VALID_STATE)) {\r
+        //\r
+        // If FTW last write was still in progress with SpareComplete set and DestinationComplete not set.\r
+        // It means the target buffer has been backed up in spare block, then target block has been erased,\r
+        // but the target buffer has not been writen in target block from spare block, we need to build\r
+        // FAULT_TOLERANT_WRITE_LAST_WRITE_DATA GUID hob to hold the FTW last write data.\r
+        //\r
+        FtwLastWrite.TargetAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) ((INT64) SpareAreaAddress + FtwLastWriteRecord->RelativeOffset);\r
+        FtwLastWrite.SpareAddress = SpareAreaAddress;\r
+        FtwLastWrite.Length = SpareAreaLength;\r
+        DEBUG ((\r
+          EFI_D_INFO,\r
+          "FtwPei last write data: TargetAddress - 0x%x SpareAddress - 0x%x Length - 0x%x\n",\r
+          (UINTN) FtwLastWrite.TargetAddress,\r
+          (UINTN) FtwLastWrite.SpareAddress,\r
+          (UINTN) FtwLastWrite.Length));\r
+        BuildGuidDataHob (&gEdkiiFaultTolerantWriteGuid, (VOID *) &FtwLastWrite, sizeof (FAULT_TOLERANT_WRITE_LAST_WRITE_DATA));\r
+      }\r
     }\r
   } else {\r
     FtwWorkingBlockHeader = NULL;\r