From nobody Sun Dec 29 01:41:20 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 149256977886372.03237299737577; Tue, 18 Apr 2017 19:42:58 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 1DFAE21A6F108; Tue, 18 Apr 2017 19:42:56 -0700 (PDT) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 C7D0921A6F106 for ; Tue, 18 Apr 2017 19:42:53 -0700 (PDT) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP; 18 Apr 2017 19:42:53 -0700 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.25]) by fmsmga005.fm.intel.com with ESMTP; 18 Apr 2017 19:42:52 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,219,1488873600"; d="scan'208";a="91145573" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Wed, 19 Apr 2017 10:42:50 +0800 Message-Id: <20170419024250.84916-1-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 Subject: [edk2] [PATCH] MdeModulePkg/TerminalDxe: Avoid always append device path to *Dev 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: Star Zeng 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" When TerminalDxe Start() is called multiple times, the old logic unconditionally appended the terminal device path candidates to *Dev (ConInDev/ConOutDev/ErrOutDev), resulting the volatile storage is full. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Star Zeng Reviewed-by: Star Zeng --- .../Universal/Console/TerminalDxe/Terminal.c | 67 ++++++++++++++++++= +--- 1 file changed, 59 insertions(+), 8 deletions(-) diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c b/MdeMod= ulePkg/Universal/Console/TerminalDxe/Terminal.c index 5d55969..60de2d4 100644 --- a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c +++ b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c @@ -994,6 +994,49 @@ TerminalDriverBindingStop ( } =20 /** + Compare a device path data structure to that of all the nodes of a + second device path instance. + + @param Multi A pointer to a multi-instance device path data st= ructure. + @param Single A pointer to a single-instance device path data s= tructure. + + @retval TRUE If the Single is contained within Multi. + @retval FALSE The Single is not match within Multi. + +**/ +BOOLEAN +MatchDevicePaths ( + IN EFI_DEVICE_PATH_PROTOCOL *Multi, + IN EFI_DEVICE_PATH_PROTOCOL *Single + ) +{ + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_DEVICE_PATH_PROTOCOL *DevicePathInst; + UINTN Size; + + DevicePath =3D Multi; + DevicePathInst =3D GetNextDevicePathInstance (&DevicePath, &Size); + // + // Search for the match of 'Single' in 'Multi' + // + while (DevicePathInst !=3D NULL) { + // + // If the single device path is found in multiple device paths, + // return success + // + if (CompareMem (Single, DevicePathInst, Size) =3D=3D 0) { + FreePool (DevicePathInst); + return TRUE; + } + + FreePool (DevicePathInst); + DevicePathInst =3D GetNextDevicePathInstance (&DevicePath, &Size); + } + + return FALSE; +} + +/** Update terminal device path in Console Device Environment Variables. =20 @param VariableName The Console Device Environment Variable. @@ -1018,8 +1061,12 @@ TerminalUpdateConsoleDevVariable ( // // Get global variable and its size according to the name given. // - GetEfiGlobalVariable2 (VariableName, (VOID**)&Variable, NULL); - if (Variable =3D=3D NULL) { + Status =3D GetEfiGlobalVariable2 (VariableName, (VOID**)&Variable, NULL); + if (Status =3D=3D EFI_NOT_FOUND) { + Status =3D EFI_SUCCESS; + Variable =3D NULL; + } + if (EFI_ERROR (Status)) { return; } =20 @@ -1028,17 +1075,21 @@ TerminalUpdateConsoleDevVariable ( // for (TerminalType =3D 0; TerminalType < ARRAY_SIZE (mTerminalType); Term= inalType++) { SetTerminalDevicePath (TerminalType, ParentDevicePath, &TempDevicePath= ); - NewVariable =3D AppendDevicePathInstance (Variable, TempDevicePath); - ASSERT (NewVariable !=3D NULL); - if (Variable !=3D NULL) { - FreePool (Variable); - } =20 if (TempDevicePath !=3D NULL) { + if (!MatchDevicePaths (Variable, TempDevicePath)) { + NewVariable =3D AppendDevicePathInstance (Variable, TempDevicePath= ); + if (NewVariable !=3D NULL) { + if (Variable !=3D NULL) { + FreePool (Variable); + } + Variable =3D NewVariable; + } + } + FreePool (TempDevicePath); } =20 - Variable =3D NewVariable; } =20 VariableSize =3D GetDevicePathSize (Variable); --=20 2.9.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel