summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg
diff options
context:
space:
mode:
authorZhi Jin <zhi.jin@intel.com>2024-01-15 15:17:04 +0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2024-02-06 17:54:53 +0000
commit9eddbab65042259beb1a75ccdf724996eab9660d (patch)
tree2792dff750de58e06fce0f97673b09938464337e /MdeModulePkg
parent62b43ec8960372abed59c1e1d596c2b324340a07 (diff)
downloadedk2-9eddbab65042259beb1a75ccdf724996eab9660d.tar.gz
edk2-9eddbab65042259beb1a75ccdf724996eab9660d.tar.bz2
edk2-9eddbab65042259beb1a75ccdf724996eab9660d.zip
MdeModulePkg: Remove handle validation check in CoreGetProtocolInterface
CoreGetProtocolInterface() is called by CoreOpenProtocol(), CoreCloseProtocol() and CoreOpenProtocolInformation(). Before CoreOpenProtocol() calls CoreGetProtocolInterface(), the input parameter UserHandle has been already checked for validation. So does CoreCloseProtocol(). Removing the handle validation check in CoreGetProtocolInterface() could improve the performance, as CoreOpenProtocol() is called very frequently. To ensure the assumption that the caller of CoreGetProtocolInterface() must pass in a valid UserHandle that is checked with CoreValidateHandle(), add the parameter check in CoreOpenProtocolInformation(), and declare CoreGetProtocolInterface() as static. Reviewed-by: Ray Ni <ray.ni@intel.com> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com> Signed-off-by: Zhi Jin <zhi.jin@intel.com>
Diffstat (limited to 'MdeModulePkg')
-rw-r--r--MdeModulePkg/Core/Dxe/Hand/Handle.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/MdeModulePkg/Core/Dxe/Hand/Handle.c b/MdeModulePkg/Core/Dxe/Hand/Handle.c
index 51e5b5d3b3..24e4fbf5f3 100644
--- a/MdeModulePkg/Core/Dxe/Hand/Handle.c
+++ b/MdeModulePkg/Core/Dxe/Hand/Handle.c
@@ -918,28 +918,25 @@ CoreUninstallMultipleProtocolInterfaces (
Locate a certain GUID protocol interface in a Handle's protocols.
@param UserHandle The handle to obtain the protocol interface on
+ The caller must pass in a valid UserHandle that
+ is checked with CoreValidateHandle().
@param Protocol The GUID of the protocol
@return The requested protocol interface for the handle
**/
+STATIC
PROTOCOL_INTERFACE *
CoreGetProtocolInterface (
IN EFI_HANDLE UserHandle,
IN EFI_GUID *Protocol
)
{
- EFI_STATUS Status;
PROTOCOL_ENTRY *ProtEntry;
PROTOCOL_INTERFACE *Prot;
IHANDLE *Handle;
LIST_ENTRY *Link;
- Status = CoreValidateHandle (UserHandle);
- if (EFI_ERROR (Status)) {
- return NULL;
- }
-
Handle = (IHANDLE *)UserHandle;
//
@@ -1393,6 +1390,15 @@ CoreOpenProtocolInformation (
CoreAcquireProtocolLock ();
//
+ // Check for invalid UserHandle
+ //
+ Status = CoreValidateHandle (UserHandle);
+ if (EFI_ERROR (Status)) {
+ Status = EFI_NOT_FOUND;
+ goto Done;
+ }
+
+ //
// Look at each protocol interface for a match
//
Status = EFI_NOT_FOUND;