From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,219,1488873600"; d="scan'208";a="91145573" 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 From: Ruiyu Ni To: edk2-devel@lists.01.org Cc: Star Zeng 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: [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:42:54 -0000 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 --- .../Universal/Console/TerminalDxe/Terminal.c | 67 +++++++++++++++++++--- 1 file changed, 59 insertions(+), 8 deletions(-) diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c b/MdeModulePkg/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 ( } /** + 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 structure. + @param Single A pointer to a single-instance device path data structure. + + @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 = Multi; + DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size); + // + // Search for the match of 'Single' in 'Multi' + // + while (DevicePathInst != NULL) { + // + // If the single device path is found in multiple device paths, + // return success + // + if (CompareMem (Single, DevicePathInst, Size) == 0) { + FreePool (DevicePathInst); + return TRUE; + } + + FreePool (DevicePathInst); + DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size); + } + + return FALSE; +} + +/** Update terminal device path in Console Device Environment Variables. @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 == NULL) { + Status = GetEfiGlobalVariable2 (VariableName, (VOID**)&Variable, NULL); + if (Status == EFI_NOT_FOUND) { + Status = EFI_SUCCESS; + Variable = NULL; + } + if (EFI_ERROR (Status)) { return; } @@ -1028,17 +1075,21 @@ TerminalUpdateConsoleDevVariable ( // for (TerminalType = 0; TerminalType < ARRAY_SIZE (mTerminalType); TerminalType++) { SetTerminalDevicePath (TerminalType, ParentDevicePath, &TempDevicePath); - NewVariable = AppendDevicePathInstance (Variable, TempDevicePath); - ASSERT (NewVariable != NULL); - if (Variable != NULL) { - FreePool (Variable); - } if (TempDevicePath != NULL) { + if (!MatchDevicePaths (Variable, TempDevicePath)) { + NewVariable = AppendDevicePathInstance (Variable, TempDevicePath); + if (NewVariable != NULL) { + if (Variable != NULL) { + FreePool (Variable); + } + Variable = NewVariable; + } + } + FreePool (TempDevicePath); } - Variable = NewVariable; } VariableSize = GetDevicePathSize (Variable); -- 2.9.0.windows.1