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.120; helo=mga04.intel.com; envelope-from=liming.gao@intel.com; receiver=edk2-devel@lists.01.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (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 192D4208AE378 for ; Fri, 15 Feb 2019 06:00:47 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Feb 2019 06:00:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,372,1544515200"; d="scan'208";a="320680035" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by fmsmga005.fm.intel.com with ESMTP; 15 Feb 2019 06:00:46 -0800 Received: from fmsmsx155.amr.corp.intel.com (10.18.116.71) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 15 Feb 2019 06:00:46 -0800 Received: from shsmsx106.ccr.corp.intel.com (10.239.4.159) by FMSMSX155.amr.corp.intel.com (10.18.116.71) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 15 Feb 2019 06:00:45 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.102]) by SHSMSX106.ccr.corp.intel.com ([169.254.10.174]) with mapi id 14.03.0415.000; Fri, 15 Feb 2019 22:00:44 +0800 From: "Gao, Liming" To: "Zeng, Star" , "Bi, Dandan" , "edk2-devel@lists.01.org" CC: "Wu, Hao A" , Michael Turner , Max Knutsen , "Gao, Liming" Thread-Topic: [edk2] [patch V2] MdeModulePkg/ReportStatusCodeLib: Avoid using AllocatePool if possible Thread-Index: AQHUxA6KvMhFa5shzU6UodGyk9AuOqXgEk6AgADRQOA= Date: Fri, 15 Feb 2019 14:00:43 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E3DF6FC@SHSMSX104.ccr.corp.intel.com> References: <20190214023907.52356-1-dandan.bi@intel.com> <0C09AFA07DD0434D9E2A0C6AEB0483104026BD16@shsmsx102.ccr.corp.intel.com> In-Reply-To: <0C09AFA07DD0434D9E2A0C6AEB0483104026BD16@shsmsx102.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNzAyOTU0NzMtNGE1YS00MzdjLWEwZDgtZWVlMGM2Y2RhZDIwIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiNnhkSW5tSU9RNzVuRGN5bzN5TlFjQzBQRUp3MHNCdmhOd0NHSjFJRk1PUlQ1QVh0NjZaMDlOQkpLY0tlY280MCJ9 dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [patch V2] 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: Fri, 15 Feb 2019 14:00:47 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Star: This patch is from MS Project MU. So, the original author is kept. Dandan= contributes this patch to edk2. So, Dandan is as Signed-off-by. This is th= e expected way. Below is author and signed-off-by definition.=20 The author is the person who originally wrote the work, whereas the committ= er is the person who last applied the work. (from https://git-scm.com/book/= en/v2/Git-Basics-Viewing-the-Commit-History) Signed-off-by: tag indicates that the signer was involved in the developmen= t of the patch, or that he/she was in the patch's delivery path. (from http= s://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documen= tation/process/submitting-patches.rst) Thanks Liming > -----Original Message----- > From: Zeng, Star > Sent: Friday, February 15, 2019 5:25 PM > To: Bi, Dandan ; edk2-devel@lists.01.org > Cc: Wu, Hao A ; Michael Turner ; Max Knutsen ; Gao, > Liming ; Zeng, Star > Subject: RE: [edk2] [patch V2] MdeModulePkg/ReportStatusCodeLib: Avoid us= ing AllocatePool if possible >=20 > After applying the patch, the author is Max and the Signed-off-by is Dand= an, is it expected? >=20 > And the code below is better to be into the else condition (stack buffer = is not enough), right? >=20 > if (gBS =3D=3D NULL || gBS->AllocatePool =3D=3D NULL || gBS->FreePool = =3D=3D NULL) { > return EFI_UNSUPPORTED; > } >=20 > // > // Retrieve the current TPL > // > Tpl =3D gBS->RaiseTPL (TPL_HIGH_LEVEL); > gBS->RestoreTPL (Tpl); >=20 >=20 > Thanks, > Star > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Da= ndan Bi > Sent: Thursday, February 14, 2019 10:39 AM > To: edk2-devel@lists.01.org > Cc: Wu, Hao A ; Michael Turner ; Max Knutsen ; Gao, > Liming > Subject: [edk2] [patch V2] MdeModulePkg/ReportStatusCodeLib: Avoid using = AllocatePool if possible >=20 > From: Max Knutsen >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1114 >=20 > V2: simplify the code logic. > update > if (!mHaveExitedBootServices && > (StatusCodeData !=3D (EFI_STATUS_CODE_DATA *) StatusCodeBuffer)) { > gBS->FreePool (StatusCodeData); > } > to > if (StatusCodeData !=3D (EFI_STATUS_CODE_DATA *) StatusCodeBuffer) { > gBS->FreePool (StatusCodeData); > } >=20 > 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. >=20 > This patch is just to do the enhancement to avoid using AllocatePool. >=20 > 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(-) >=20 > diff --git a/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCode= Lib.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 =3D gBS->RaiseTPL (TPL_HIGH_LEVEL); > gBS->RestoreTPL (Tpl); >=20 > StatusCodeData =3D NULL; > - if (Tpl <=3D TPL_NOTIFY) { > + if (ExtendedDataSize <=3D (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 =3D (EFI_STATUS_CODE_DATA *)Buffer; } else if (Tpl <= =3D > + 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); > } >=20 > if (StatusCodeData =3D=3D NULL) { > diff --git a/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportSta= tusCodeLib.c > b/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.= c > index b73103517a..75e2f88ad2 100644 > --- a/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCode= Lib.c > +++ b/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCod > +++ eLib.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 =3D (EFI_STATUS_CODE_DATA *) StatusCodeBuffer; > - } else { > + } else if (sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize > MAX_EXTE= NDED_DATA_SIZE) { > + // > + // Only use AllocatePool for larger ExtendedData. > + // > if (gBS =3D=3D NULL || gBS->AllocatePool =3D=3D NULL || gBS->FreePoo= l =3D=3D NULL) { > return EFI_UNSUPPORTED; > } >=20 > // > @@ -648,10 +651,12 @@ ReportStatusCodeEx ( > StatusCodeData =3D NULL; > gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA= ) + ExtendedDataSize, (VOID **)&StatusCodeData); > if (StatusCodeData =3D=3D NULL) { > return EFI_OUT_OF_RESOURCES; > } > + } else { > + StatusCodeData =3D (EFI_STATUS_CODE_DATA *) StatusCodeBuffer; > } >=20 > // > // Fill in the extended data header > // > @@ -678,11 +683,11 @@ ReportStatusCodeEx ( > Status =3D InternalReportStatusCode (Type, Value, Instance, CallerId, = StatusCodeData); >=20 > // > // Free the allocated buffer > // > - if (!mHaveExitedBootServices) { > + if (StatusCodeData !=3D (EFI_STATUS_CODE_DATA *) StatusCodeBuffer) { > gBS->FreePool (StatusCodeData); > } >=20 > return Status; > } > -- > 2.18.0.windows.1 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel