From: Ruiyu Ni <ruiyu.ni@intel.com>
To: edk2-devel@lists.01.org
Cc: Star Zeng <star.zeng@intel.com>
Subject: [PATCH] MdeModulePkg/TerminalDxe: Avoid always append device path to *Dev
Date: Wed, 19 Apr 2017 10:42:50 +0800 [thread overview]
Message-ID: <20170419024250.84916-1-ruiyu.ni@intel.com> (raw)
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 <ruiyu.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
---
.../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
next reply other threads:[~2017-04-19 2:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-19 2:42 Ruiyu Ni [this message]
2017-04-19 2:53 ` [PATCH] MdeModulePkg/TerminalDxe: Avoid always append device path to *Dev Zeng, Star
2017-04-19 5:13 ` Ni, Ruiyu
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=20170419024250.84916-1-ruiyu.ni@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