public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Wu, Hao A" <hao.a.wu@intel.com>
To: "Ni, Ruiyu" <ruiyu.ni@intel.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Subject: Re: [PATCH] UefiCpuPkg/MtrrLib: Avoid running unnecessary code
Date: Mon, 17 Apr 2017 04:58:43 +0000	[thread overview]
Message-ID: <B80AF82E9BFB8E4FBD8C89DA810C6A0931C99432@SHSMSX104.ccr.corp.intel.com> (raw)
In-Reply-To: <20170417045636.102048-1-ruiyu.ni@intel.com>

Reviewed-by: Hao Wu <hao.a.wu@intel.com>


Best Regards,
Hao Wu


> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ruiyu
> Ni
> Sent: Monday, April 17, 2017 12:57 PM
> To: edk2-devel@lists.01.org
> Cc: Wu, Hao A
> Subject: [edk2] [PATCH] UefiCpuPkg/MtrrLib: Avoid running unnecessary code
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> ---
>  UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 35 +++++++++++++++++++---------------
> -
>  1 file changed, 19 insertions(+), 16 deletions(-)
> 
> diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
> b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
> index c38191a..9d19272 100644
> --- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
> +++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
> @@ -1536,6 +1536,7 @@ MtrrLibAddVariableMtrr (
> 
>    MTRR_LIB_ASSERT_ALIGNED (BaseAddress, Length);
>    if (Type == CacheInvalid) {
> +    ASSERT (Ranges != NULL);
>      for (Index = 0; Index < RangeCount; Index++) {
>        if (Ranges[Index].BaseAddress <= BaseAddress && BaseAddress <
> Ranges[Index].BaseAddress + Ranges[Index].Length) {
> 
> @@ -2027,25 +2028,27 @@ MtrrSetMemoryAttributeWorker (
>    ASSERT (OriginalVariableMtrrCount - FreeVariableMtrrCount <=
> FirmwareVariableMtrrCount);
> 
>    //
> -  // Move MTRRs after the FirmwraeVariableMtrrCount position to beginning
> +  // Move MTRRs after the FirmwareVariableMtrrCount position to beginning
>    //
> -  WorkingIndex = FirmwareVariableMtrrCount;
> -  for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {
> -    if (!OriginalVariableMtrr[Index].Valid) {
> -      //
> -      // Found an empty MTRR in WorkingIndex position
> -      //
> -      for (; WorkingIndex < OriginalVariableMtrrCount; WorkingIndex++) {
> -        if (OriginalVariableMtrr[WorkingIndex].Valid) {
> -          break;
> +  if (FirmwareVariableMtrrCount < OriginalVariableMtrrCount) {
> +    WorkingIndex = FirmwareVariableMtrrCount;
> +    for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {
> +      if (!OriginalVariableMtrr[Index].Valid) {
> +        //
> +        // Found an empty MTRR in WorkingIndex position
> +        //
> +        for (; WorkingIndex < OriginalVariableMtrrCount; WorkingIndex++) {
> +          if (OriginalVariableMtrr[WorkingIndex].Valid) {
> +            break;
> +          }
>          }
> -      }
> 
> -      if (WorkingIndex != OriginalVariableMtrrCount) {
> -        CopyMem (&OriginalVariableMtrr[Index],
> &OriginalVariableMtrr[WorkingIndex], sizeof (VARIABLE_MTRR));
> -        VariableSettingModified[Index] = TRUE;
> -        VariableSettingModified[WorkingIndex] = TRUE;
> -        OriginalVariableMtrr[WorkingIndex].Valid = FALSE;
> +        if (WorkingIndex != OriginalVariableMtrrCount) {
> +          CopyMem (&OriginalVariableMtrr[Index],
> &OriginalVariableMtrr[WorkingIndex], sizeof (VARIABLE_MTRR));
> +          VariableSettingModified[Index] = TRUE;
> +          VariableSettingModified[WorkingIndex] = TRUE;
> +          OriginalVariableMtrr[WorkingIndex].Valid = FALSE;
> +        }
>        }
>      }
>    }
> --
> 2.9.0.windows.1
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


      reply	other threads:[~2017-04-17  4:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-17  4:56 [PATCH] UefiCpuPkg/MtrrLib: Avoid running unnecessary code Ruiyu Ni
2017-04-17  4:58 ` Wu, Hao A [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=B80AF82E9BFB8E4FBD8C89DA810C6A0931C99432@SHSMSX104.ccr.corp.intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox