summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib
diff options
context:
space:
mode:
authorMax Knutsen <maknutse@microsoft.com>2018-09-04 17:04:35 +0000
committerLiming Gao <liming.gao@intel.com>2019-02-19 16:14:50 +0800
commitc22f52c5e79b9782648576efb8382bb04da60b5b (patch)
tree744413c4c7093c65c31e2e6e2cf2cda4562a884c /MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib
parenta169a04fd2cd529527f21575131ba3379ab72df8 (diff)
downloadedk2-c22f52c5e79b9782648576efb8382bb04da60b5b.tar.gz
edk2-c22f52c5e79b9782648576efb8382bb04da60b5b.tar.bz2
edk2-c22f52c5e79b9782648576efb8382bb04da60b5b.zip
MdeModulePkg/ReportStatusCodeLib: Avoid using AllocatePool if possible
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>
Diffstat (limited to 'MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib')
-rw-r--r--MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c b/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c
index b73103517a..9b79854538 100644
--- a/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c
+++ b/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c
@@ -632,12 +632,16 @@ ReportStatusCodeEx (
ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));
ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));
- if (mHaveExitedBootServices) {
- if (sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize > MAX_EXTENDED_DATA_SIZE) {
+ if (ExtendedDataSize <= (MAX_EXTENDED_DATA_SIZE - sizeof (EFI_STATUS_CODE_DATA))) {
+ //
+ // Use Buffer instead of allocating if possible.
+ //
+ StatusCodeData = (EFI_STATUS_CODE_DATA *) StatusCodeBuffer;
+ } else {
+ if (mHaveExitedBootServices) {
return EFI_OUT_OF_RESOURCES;
}
- StatusCodeData = (EFI_STATUS_CODE_DATA *) StatusCodeBuffer;
- } else {
+
if (gBS == NULL || gBS->AllocatePool == NULL || gBS->FreePool == NULL) {
return EFI_UNSUPPORTED;
}
@@ -680,7 +684,7 @@ ReportStatusCodeEx (
//
// Free the allocated buffer
//
- if (!mHaveExitedBootServices) {
+ if (StatusCodeData != (EFI_STATUS_CODE_DATA *) StatusCodeBuffer) {
gBS->FreePool (StatusCodeData);
}