]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/ReportStatusCodeLib: Avoid using AllocatePool if possible
authorMax Knutsen <maknutse@microsoft.com>
Tue, 4 Sep 2018 17:04:35 +0000 (17:04 +0000)
committerLiming Gao <liming.gao@intel.com>
Tue, 19 Feb 2019 08:14:50 +0000 (16:14 +0800)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1114

V2: simplify the code logic.
update
if (!mHaveExitedBootServices &&
  (StatusCodeData != (EFI_STATUS_CODE_DATA *) StatusCodeBuffer)) {
  gBS->FreePool (StatusCodeData);
}
to
if (StatusCodeData != (EFI_STATUS_CODE_DATA *) StatusCodeBuffer) {
  gBS->FreePool (StatusCodeData);
}

V3:
And the code below into the else condition (stack buffer is not enough)
in /DxeReportStatusCodeLib/ReportStatusCodeLib.c

  if (gBS == NULL || gBS->AllocatePool == NULL || gBS->FreePool == NULL) {
    return EFI_UNSUPPORTED;
  }

V4:
Refine code logic.

When report status code with ExtendedData data,
and the extended data can fit in the local static buffer,
there is no need to use AllocatePool to hold the ExtendedData data.

This patch is just to do the enhancement to avoid using AllocatePool.

Cc: Star Zeng <star.zeng@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c
MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c

index b28dc5c3bbd2e3ebc9ba26622f46ad6ed000cbea..307b95de7c321c8372d12d639ffe17743f79ef8a 100644 (file)
@@ -496,37 +496,34 @@ ReportStatusCodeEx (
   ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));\r
   ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));\r
 \r
-  if (gBS == NULL || gBS->AllocatePool == NULL || gBS->FreePool == NULL) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
-  //\r
-  // Retrieve the current TPL\r
-  //\r
-  Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
-  gBS->RestoreTPL (Tpl);\r
+  if (ExtendedDataSize <= (MAX_EXTENDED_DATA_SIZE - sizeof (EFI_STATUS_CODE_DATA))) {\r
+    //\r
+    // Use Buffer instead of allocating if possible.\r
+    //\r
+    StatusCodeData = (EFI_STATUS_CODE_DATA *)Buffer;\r
+  } else {\r
+    if (gBS == NULL || gBS->AllocatePool == NULL || gBS->FreePool == NULL) {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
 \r
-  StatusCodeData = NULL;\r
-  if (Tpl <= TPL_NOTIFY) {\r
     //\r
-    // Allocate space for the Status Code Header and its buffer\r
+    // Retrieve the current TPL\r
     //\r
-    gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData);\r
-  }\r
+    Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
+    gBS->RestoreTPL (Tpl);\r
+\r
+    if (Tpl > TPL_NOTIFY) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
 \r
-  if (StatusCodeData == NULL) {\r
     //\r
-    // If a buffer could not be allocated, then see if the local variable Buffer can be used\r
+    // Allocate space for the Status Code Header and its buffer\r
     //\r
-    if (ExtendedDataSize > (MAX_EXTENDED_DATA_SIZE - sizeof (EFI_STATUS_CODE_DATA))) {\r
-      //\r
-      // The local variable Buffer not large enough to hold the extended data associated\r
-      // with the status code being reported.\r
-      //\r
-      DEBUG ((EFI_D_ERROR, "Status code extended data is too large to be reported!\n"));\r
+    StatusCodeData = NULL;\r
+    gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData);\r
+    if (StatusCodeData == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
-    StatusCodeData = (EFI_STATUS_CODE_DATA  *)Buffer;\r
   }\r
 \r
   //\r
index b73103517ab2065c29fc593eeb5fbc6b98a91e24..9b79854538dc31945a95f730970701349b3b2738 100644 (file)
@@ -632,12 +632,16 @@ ReportStatusCodeEx (
   ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));\r
   ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));\r
 \r
-  if (mHaveExitedBootServices) {\r
-    if (sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize > MAX_EXTENDED_DATA_SIZE) {\r
+  if (ExtendedDataSize <= (MAX_EXTENDED_DATA_SIZE - sizeof (EFI_STATUS_CODE_DATA))) {\r
+    //\r
+    // Use Buffer instead of allocating if possible.\r
+    //\r
+    StatusCodeData = (EFI_STATUS_CODE_DATA *) StatusCodeBuffer;\r
+  } else {\r
+    if (mHaveExitedBootServices) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
-    StatusCodeData = (EFI_STATUS_CODE_DATA *) StatusCodeBuffer;\r
-  } else  {\r
+\r
     if (gBS == NULL || gBS->AllocatePool == NULL || gBS->FreePool == NULL) {\r
       return EFI_UNSUPPORTED;\r
     }\r
@@ -680,7 +684,7 @@ ReportStatusCodeEx (
   //\r
   // Free the allocated buffer\r
   //\r
-  if (!mHaveExitedBootServices) {\r
+  if (StatusCodeData != (EFI_STATUS_CODE_DATA *) StatusCodeBuffer) {\r
     gBS->FreePool (StatusCodeData);\r
   }\r
 \r