From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.136; helo=mga12.intel.com; envelope-from=dandan.bi@intel.com; receiver=edk2-devel@lists.01.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 30DC0211C574E for ; Sat, 2 Feb 2019 00:47:10 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Feb 2019 00:47:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,551,1539673200"; d="scan'208";a="121462486" Received: from shwdeopenpsi114.ccr.corp.intel.com ([10.239.157.135]) by fmsmga008.fm.intel.com with ESMTP; 02 Feb 2019 00:47:09 -0800 From: Dandan Bi To: edk2-devel@lists.01.org Cc: Max Knutsen , Jian J Wang , Hao Wu , Michael Turner , Liming Gao Date: Sat, 2 Feb 2019 16:46:54 +0800 Message-Id: <20190202084654.34868-1-dandan.bi@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 Subject: [patch] MdeModulePkg/ReportStatusCodeLib: Avoid using AllocatePool if possible X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Feb 2019 08:47:12 -0000 From: Max Knutsen REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1114 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: Jian J Wang Cc: Hao Wu Cc: Michael Turner Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Dandan Bi --- .../Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c | 9 +++++++-- .../RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c b/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c index b28dc5c3bb..c88be5a1a3 100644 --- a/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c +++ b/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c @@ -505,13 +505,18 @@ ReportStatusCodeEx ( // Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL); gBS->RestoreTPL (Tpl); StatusCodeData = NULL; - if (Tpl <= TPL_NOTIFY) { + if (ExtendedDataSize <= (MAX_EXTENDED_DATA_SIZE - sizeof (EFI_STATUS_CODE_DATA))) { // - // Allocate space for the Status Code Header and its buffer + // Use Buffer instead of allocating if possible. + // + StatusCodeData = (EFI_STATUS_CODE_DATA *)Buffer; + } else if (Tpl <= TPL_NOTIFY){ + // + // If Buffer is not big enough, allocate space for the Status Code Header and its buffer // gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData); } if (StatusCodeData == NULL) { diff --git a/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c b/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c index b73103517a..3380469759 100644 --- a/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c +++ b/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c @@ -635,11 +635,14 @@ ReportStatusCodeEx ( if (mHaveExitedBootServices) { if (sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize > MAX_EXTENDED_DATA_SIZE) { return EFI_OUT_OF_RESOURCES; } StatusCodeData = (EFI_STATUS_CODE_DATA *) StatusCodeBuffer; - } else { + } else if (sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize > MAX_EXTENDED_DATA_SIZE) { + // + // Only use AllocatePool for larger ExtendedData. + // if (gBS == NULL || gBS->AllocatePool == NULL || gBS->FreePool == NULL) { return EFI_UNSUPPORTED; } // @@ -648,10 +651,12 @@ ReportStatusCodeEx ( StatusCodeData = NULL; gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData); if (StatusCodeData == NULL) { return EFI_OUT_OF_RESOURCES; } + } else { + StatusCodeData = (EFI_STATUS_CODE_DATA *) StatusCodeBuffer; } // // Fill in the extended data header // @@ -678,11 +683,11 @@ ReportStatusCodeEx ( Status = InternalReportStatusCode (Type, Value, Instance, CallerId, StatusCodeData); // // Free the allocated buffer // - if (!mHaveExitedBootServices) { + if (!mHaveExitedBootServices && (StatusCodeData != (EFI_STATUS_CODE_DATA *) StatusCodeBuffer)) { gBS->FreePool (StatusCodeData); } return Status; } -- 2.18.0.windows.1