From nobody Sat Nov 2 08:25:59 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1492405006339124.0220686148723; Sun, 16 Apr 2017 21:56:46 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2F72B20D7B8EA; Sun, 16 Apr 2017 21:56:44 -0700 (PDT) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 0F43B20D7A3A4 for ; Sun, 16 Apr 2017 21:56:42 -0700 (PDT) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Apr 2017 21:56:41 -0700 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.25]) by fmsmga004.fm.intel.com with ESMTP; 16 Apr 2017 21:56:39 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,213,1488873600"; d="scan'208";a="249958445" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Mon, 17 Apr 2017 12:56:36 +0800 Message-Id: <20170417045636.102048-1-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 Subject: [edk2] [PATCH] UefiCpuPkg/MtrrLib: Avoid running unnecessary code X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hao A Wu MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Hao A Wu Reviewed-by: Hao Wu --- UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 35 +++++++++++++++++++-------------= --- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/Mtrr= Lib/MtrrLib.c index c38191a..9d19272 100644 --- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c +++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c @@ -1536,6 +1536,7 @@ MtrrLibAddVariableMtrr ( =20 MTRR_LIB_ASSERT_ALIGNED (BaseAddress, Length); if (Type =3D=3D CacheInvalid) { + ASSERT (Ranges !=3D NULL); for (Index =3D 0; Index < RangeCount; Index++) { if (Ranges[Index].BaseAddress <=3D BaseAddress && BaseAddress < Rang= es[Index].BaseAddress + Ranges[Index].Length) { =20 @@ -2027,25 +2028,27 @@ MtrrSetMemoryAttributeWorker ( ASSERT (OriginalVariableMtrrCount - FreeVariableMtrrCount <=3D FirmwareV= ariableMtrrCount); =20 // - // Move MTRRs after the FirmwraeVariableMtrrCount position to beginning + // Move MTRRs after the FirmwareVariableMtrrCount position to beginning // - WorkingIndex =3D FirmwareVariableMtrrCount; - for (Index =3D 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 =3D FirmwareVariableMtrrCount; + for (Index =3D 0; Index < FirmwareVariableMtrrCount; Index++) { + if (!OriginalVariableMtrr[Index].Valid) { + // + // Found an empty MTRR in WorkingIndex position + // + for (; WorkingIndex < OriginalVariableMtrrCount; WorkingIndex++) { + if (OriginalVariableMtrr[WorkingIndex].Valid) { + break; + } } - } =20 - if (WorkingIndex !=3D OriginalVariableMtrrCount) { - CopyMem (&OriginalVariableMtrr[Index], &OriginalVariableMtrr[Worki= ngIndex], sizeof (VARIABLE_MTRR)); - VariableSettingModified[Index] =3D TRUE; - VariableSettingModified[WorkingIndex] =3D TRUE; - OriginalVariableMtrr[WorkingIndex].Valid =3D FALSE; + if (WorkingIndex !=3D OriginalVariableMtrrCount) { + CopyMem (&OriginalVariableMtrr[Index], &OriginalVariableMtrr[Wor= kingIndex], sizeof (VARIABLE_MTRR)); + VariableSettingModified[Index] =3D TRUE; + VariableSettingModified[WorkingIndex] =3D TRUE; + OriginalVariableMtrr[WorkingIndex].Valid =3D FALSE; + } } } } --=20 2.9.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel