]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Upon BootOption failure, Destroy RamDisk memory before RSC.
authorKrishnadasX Veliyathuparambil Prakashan <krishnadasx.veliyathuparambil.prakashan@intel.com>
Fri, 19 Jun 2020 02:40:26 +0000 (10:40 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 20 Jul 2020 15:00:18 +0000 (15:00 +0000)
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2818

For better memory management, re-ordered the DestroyRamDisk and
ReportStatusCode calls inside the EfiBootManagerBoot() function.

This will help to clean the unused memory before reporting the
failure status, so that OEMs can use RSC Listener to launch
custom boot option or application for recovering the failed
hard drive.

This change will help to ensure that the allocated pool of memory
for the failed boot option is freed before executing OEM's RSC
listener callback to handle every boot option failure.

Signed-off-by: KrishnadasX Veliyathuparambil Prakashan <krishnadasx.veliyathuparambil.prakashan@intel.com>
Cc: "Gao, Zhichao" <zhichao.gao@intel.com>
Cc: "Ni, Ray" <ray.ni@intel.com>
Reviewed-by: Sunny Wang <sunnywang@hpe.com>
Reviewed-by: Zhichao Gao <zhichao.gao@intel.com>
MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c

index 540d169ec1a6a0170b81581e25c023549a8931b2..aff620ad52eec6e51bffad40ba982bd9885b0a85 100644 (file)
@@ -2,7 +2,7 @@
   Library functions which relates with booting.\r
 \r
 Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.\r
-Copyright (c) 2011 - 2019, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 - 2020, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r
 SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
@@ -1903,17 +1903,17 @@ EfiBootManagerBoot (
         gBS->UnloadImage (ImageHandle);\r
       }\r
       //\r
-      // Report Status Code with the failure status to indicate that the failure to load boot option\r
-      //\r
-      BmReportLoadFailure (EFI_SW_DXE_BS_EC_BOOT_OPTION_LOAD_ERROR, Status);\r
-      BootOption->Status = Status;\r
-      //\r
       // Destroy the RAM disk\r
       //\r
       if (RamDiskDevicePath != NULL) {\r
         BmDestroyRamDisk (RamDiskDevicePath);\r
         FreePool (RamDiskDevicePath);\r
       }\r
+      //\r
+      // Report Status Code with the failure status to indicate that the failure to load boot option\r
+      //\r
+      BmReportLoadFailure (EFI_SW_DXE_BS_EC_BOOT_OPTION_LOAD_ERROR, Status);\r
+      BootOption->Status = Status;\r
       return;\r
     }\r
   }\r
@@ -1982,13 +1982,6 @@ EfiBootManagerBoot (
   Status = gBS->StartImage (ImageHandle, &BootOption->ExitDataSize, &BootOption->ExitData);\r
   DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Image Return Status = %r\n", Status));\r
   BootOption->Status = Status;\r
-  if (EFI_ERROR (Status)) {\r
-    //\r
-    // Report Status Code with the failure status to indicate that boot failure\r
-    //\r
-    BmReportLoadFailure (EFI_SW_DXE_BS_EC_BOOT_OPTION_FAILED, Status);\r
-  }\r
-  PERF_END_EX (gImageHandle, "BdsAttempt", NULL, 0, (UINT32) OptionNumber);\r
 \r
   //\r
   // Destroy the RAM disk\r
@@ -1998,6 +1991,15 @@ EfiBootManagerBoot (
     FreePool (RamDiskDevicePath);\r
   }\r
 \r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Report Status Code with the failure status to indicate that boot failure\r
+    //\r
+    BmReportLoadFailure (EFI_SW_DXE_BS_EC_BOOT_OPTION_FAILED, Status);\r
+  }\r
+  PERF_END_EX (gImageHandle, "BdsAttempt", NULL, 0, (UINT32) OptionNumber);\r
+\r
+\r
   //\r
   // Clear the Watchdog Timer after the image returns\r
   //\r