[edk2-devel] [PATCH 1/2] BoardModulePkg: Copy device path before processing
Isaac Oram
isaac.w.oram at intel.com
Tue Jan 17 20:31:26 UTC 2023
Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHookLib.c
Line 168: Don't we need to free buffer on this path?
Lines 655, 1083: Please put a newline between while and the block to free resources.
Regards,
Isaac
-----Original Message-----
From: devel at edk2.groups.io <devel at edk2.groups.io> On Behalf Of Abdul Lateef Attar via groups.io
Sent: Tuesday, November 15, 2022 4:04 AM
To: devel at edk2.groups.io
Cc: Dong, Eric <eric.dong at intel.com>; Gao, Liming <gaoliming at byosoft.com.cn>
Subject: [edk2-devel] [PATCH 1/2] BoardModulePkg: Copy device path before processing
From: Abdul Lateef Attar <abdattar at amd.com>
GCC compiler puts the DevicePath PCDs to the read-only section. During boot if try to process the device path after PtrGetPtr it throws a page fault exception.
Hence making a local copy using DuplicateDevicePath() to avoid the page fault exception.
Cc: Eric Dong <eric.dong at intel.com>
Cc: Liming Gao <gaoliming at byosoft.com.cn>
Signed-off-by: Abdul Lateef Attar <abdattar at amd.com>
---
.../Library/BoardBdsHookLib/BoardBdsHookLib.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHookLib.c b/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHookLib.c
index 0bcee7c9a4ba..8700118d255a 100644
--- a/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHookLib.c
+++ b/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHook
+++ Lib.c
@@ -3,6 +3,7 @@
implementation instance of the BDS hook library
Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+ Copyright (C) 2022 Advanced Micro Devices, Inc. All rights
+ reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -131,7 +132,7 @@ IsTrustedConsole (
switch (ConsoleType) {
case ConIn:
- TrustedConsoleDevicepath = PcdGetPtr (PcdTrustedConsoleInputDevicePath);
+ TrustedConsoleDevicepath = DuplicateDevicePath (PcdGetPtr
+ (PcdTrustedConsoleInputDevicePath));
break;
case ConOut:
//
@@ -147,7 +148,7 @@ IsTrustedConsole (
TempDevicePath = NextDevicePathNode (TempDevicePath);
}
- TrustedConsoleDevicepath = PcdGetPtr (PcdTrustedConsoleOutputDevicePath);
+ TrustedConsoleDevicepath = DuplicateDevicePath (PcdGetPtr
+ (PcdTrustedConsoleOutputDevicePath));
break;
default:
ASSERT (FALSE);
@@ -171,7 +172,9 @@ IsTrustedConsole (
} while (TempDevicePath != NULL);
FreePool (ConsoleDevice);
-
+ if (TrustedConsoleDevicepath != NULL) {
+ FreePool (TrustedConsoleDevicepath);
+ }
return FALSE;
}
@@ -624,7 +627,7 @@ ConnectTrustedStorage (
EFI_STATUS Status;
EFI_HANDLE DeviceHandle;
- TrustedStorageDevicepath = PcdGetPtr (PcdTrustedStorageDevicePath);
+ TrustedStorageDevicepath = DuplicateDevicePath (PcdGetPtr
+ (PcdTrustedStorageDevicePath));
DumpDevicePath (L"TrustedStorage", TrustedStorageDevicepath);
TempDevicePath = TrustedStorageDevicepath;
@@ -649,6 +652,9 @@ ConnectTrustedStorage (
FreePool (Instance);
} while (TempDevicePath != NULL);
+ if (TrustedStorageDevicepath != NULL) {
+ FreePool (TrustedStorageDevicepath);
+ }
}
@@ -1031,7 +1037,7 @@ AddConsoleVariable (
EFI_HANDLE GraphicsControllerHandle;
EFI_DEVICE_PATH *GopDevicePath;
- TempDevicePath = ConsoleDevicePath;
+ TempDevicePath = DuplicateDevicePath (ConsoleDevicePath);
do {
Instance = GetNextDevicePathInstance (&TempDevicePath, &Size);
if (Instance == NULL) {
@@ -1074,6 +1080,9 @@ AddConsoleVariable (
FreePool (Instance);
} while (TempDevicePath != NULL);
+ if (TempDevicePath != NULL) {
+ FreePool (TempDevicePath);
+ }
}
--
2.25.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#98728): https://edk2.groups.io/g/devel/message/98728
Mute This Topic: https://groups.io/mt/95046164/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-
More information about the edk2-devel-archive
mailing list