From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 4AD1421A6F106 for ; Tue, 18 Apr 2017 19:54:00 -0700 (PDT) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Apr 2017 19:54:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,219,1488873600"; d="scan'208";a="91507636" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga006.fm.intel.com with ESMTP; 18 Apr 2017 19:53:59 -0700 Received: from fmsmsx123.amr.corp.intel.com (10.18.125.38) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 18 Apr 2017 19:53:59 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by fmsmsx123.amr.corp.intel.com (10.18.125.38) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 18 Apr 2017 19:53:59 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.246]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.224]) with mapi id 14.03.0319.002; Wed, 19 Apr 2017 10:53:57 +0800 From: "Zeng, Star" To: "Ni, Ruiyu" , "edk2-devel@lists.01.org" CC: "Zeng, Star" Thread-Topic: [edk2] [PATCH] MdeModulePkg/TerminalDxe: Avoid always append device path to *Dev Thread-Index: AQHSuLarE9XHNuqAL0KCfdI8nzxl2qHL/WgA Date: Wed, 19 Apr 2017 02:53:56 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB0483103B87BE9C@shsmsx102.ccr.corp.intel.com> References: <20170419024250.84916-1-ruiyu.ni@intel.com> In-Reply-To: <20170419024250.84916-1-ruiyu.ni@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [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: , X-List-Received-Date: Wed, 19 Apr 2017 02:54:00 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Star Zeng BTW: May the MatchDevicePaths could be proposed to DevicePathLib? :) ---- MatchDevicePaths Matches (5 in 1 files) ---- ConsoleOption.c (F:\GIT\edk2Git\edk2\MdeModulePkg\Library\BootMaintenanceMa= nagerUiLib):MatchDevicePaths ( ConsoleOption.c (F:\GIT\edk2Git\edk2\MdeModulePkg\Library\BootMaintenanceMa= nagerUiLib): if (MatchDevicePaths (OutDevicePath, NewDevicePath)) { ConsoleOption.c (F:\GIT\edk2Git\edk2\MdeModulePkg\Library\BootMaintenanceMa= nagerUiLib): if (MatchDevicePaths (InpDevicePath, NewDevicePath)) { ConsoleOption.c (F:\GIT\edk2Git\edk2\MdeModulePkg\Library\BootMaintenanceMa= nagerUiLib): if (MatchDevicePaths (ErrDevicePath, NewDevicePath)) { ConsoleOption.c (F:\GIT\edk2Git\edk2\MdeModulePkg\Library\BootMaintenanceMa= nagerUiLib): NewConsoleContext->IsActive =3D MatchDevicePaths ( ---- BmMatchDevicePaths Matches (4 in 4 files) ---- BmBoot.c (F:\GIT\edk2Git\edk2\MdeModulePkg\Library\UefiBootManagerLib): if= (BmMatchDevicePaths (*CachedDevicePath, DevicePath)) { BmConsole.c (F:\GIT\edk2Git\edk2\MdeModulePkg\Library\UefiBootManagerLib): = if (!BmMatchDevicePaths (NewDevicePath, CustomizedConDevicePath)) { BmMisc.c (F:\GIT\edk2Git\edk2\MdeModulePkg\Library\UefiBootManagerLib):BmMa= tchDevicePaths ( InternalBm.h (F:\GIT\edk2Git\edk2\MdeModulePkg\Library\UefiBootManagerLib):= BmMatchDevicePaths ( ---- BdsLibMatchDevicePaths Matches (11 in 8 files) ---- BdsBoot.c (F:\GIT\edk2Git\edk2\IntelFrameworkModulePkg\Library\GenericBdsLi= b): if (BdsLibMatchDevicePaths (CachedDevicePath, BlockIoDevicePath)= ) { BdsBoot.c (F:\GIT\edk2Git\edk2\Vlv2TbltDevicePkg\Override\IntelFrameworkMod= ulePkg\Library\GenericBdsLib): if (BdsLibMatchDevicePaths (CachedDev= icePath, BlockIoDevicePath)) { BdsConsole.c (F:\GIT\edk2Git\edk2\IntelFrameworkModulePkg\Library\GenericBd= sLib): if (!BdsLibMatchDevicePaths (NewDevicePath, CustomizedConDevicePa= th)) { BdsConsole.c (F:\GIT\edk2Git\edk2\Vlv2TbltDevicePkg\Override\IntelFramework= ModulePkg\Library\GenericBdsLib): if (!BdsLibMatchDevicePaths (NewDevice= Path, CustomizedConDevicePath)) { BdsMisc.c (F:\GIT\edk2Git\edk2\IntelFrameworkModulePkg\Library\GenericBdsLi= b):BdsLibMatchDevicePaths ( BdsMisc.c (F:\GIT\edk2Git\edk2\Vlv2TbltDevicePkg\Override\IntelFrameworkMod= ulePkg\Library\GenericBdsLib):BdsLibMatchDevicePaths ( ConsoleOption.c (F:\GIT\edk2Git\edk2\IntelFrameworkModulePkg\Universal\BdsD= xe\BootMaint): if (BdsLibMatchDevicePaths (OutDevicePath, NewDevicePat= h)) { ConsoleOption.c (F:\GIT\edk2Git\edk2\IntelFrameworkModulePkg\Universal\BdsD= xe\BootMaint): if (BdsLibMatchDevicePaths (InpDevicePath, NewDevicePat= h)) { ConsoleOption.c (F:\GIT\edk2Git\edk2\IntelFrameworkModulePkg\Universal\BdsD= xe\BootMaint): if (BdsLibMatchDevicePaths (ErrDevicePath, NewDevicePat= h)) { ConsoleOption.c (F:\GIT\edk2Git\edk2\IntelFrameworkModulePkg\Universal\BdsD= xe\BootMaint): NewConsoleContext->IsActive =3D BdsLibMatchDevicePaths ( GenericBdsLib.h (F:\GIT\edk2Git\edk2\IntelFrameworkModulePkg\Include\Librar= y):BdsLibMatchDevicePaths ( ---- ConPlatformMatchDevicePaths Matches (4 in 2 files) ---- ConPlatform.c (F:\GIT\edk2Git\edk2\MdeModulePkg\Universal\Console\ConPlatfo= rmDxe):ConPlatformMatchDevicePaths ( ConPlatform.c (F:\GIT\edk2Git\edk2\MdeModulePkg\Universal\Console\ConPlatfo= rmDxe): Status =3D ConPlatformMatchDevicePaths ( ConPlatform.c (F:\GIT\edk2Git\edk2\MdeModulePkg\Universal\Console\ConPlatfo= rmDxe): Status =3D ConPlatformMatchDevicePaths ( ConPlatform.h (F:\GIT\edk2Git\edk2\MdeModulePkg\Universal\Console\ConPlatfo= rmDxe):ConPlatformMatchDevicePaths ( Thanks, Star -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ruiy= u Ni Sent: Wednesday, April 19, 2017 10:43 AM To: edk2-devel@lists.01.org Cc: Zeng, Star Subject: [edk2] [PATCH] MdeModulePkg/TerminalDxe: Avoid always append devic= e path to *Dev When TerminalDxe Start() is called multiple times, the old logic unconditio= nally appended the terminal device path candidates to *Dev (ConInDev/ConOut= Dev/ErrOutDev), resulting the volatile storage is full. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: 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 =20 + 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); // = =20 + // 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,=20 + 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); -- 2.9.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel