]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c
MdeModulePkg/ReportStatusCodeLib: Avoid using AllocatePool if possible
[mirror_edk2.git] / MdeModulePkg / Library / DxeReportStatusCodeLib / 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