X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FCore%2FDxe%2FHand%2FLocate.c;h=be17f4cbc3ade2b39ef277c8848fc489208b2826;hb=9d510e61fceee7b92955ef9a3c20343752d8ce3f;hp=2b961c14d4e19a5fa1f34e31869c39296f1e57f4;hpb=ec90508b3d3ff22a698a0446cb09d551d7466045;p=mirror_edk2.git
diff --git a/MdeModulePkg/Core/Dxe/Hand/Locate.c b/MdeModulePkg/Core/Dxe/Hand/Locate.c
index 2b961c14d4..be17f4cbc3 100644
--- a/MdeModulePkg/Core/Dxe/Hand/Locate.c
+++ b/MdeModulePkg/Core/Dxe/Hand/Locate.c
@@ -1,14 +1,8 @@
/** @file
Locate handle functions
-Copyright (c) 2006 - 2008, Intel Corporation.
-All rights reserved. This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -129,7 +123,7 @@ CoreLocateHandle (
VOID *Interface;
if (BufferSize == NULL) {
- Status = EFI_INVALID_PARAMETER;
+ return EFI_INVALID_PARAMETER;
}
if ((*BufferSize > 0) && (Buffer == NULL)) {
@@ -200,6 +194,7 @@ CoreLocateHandle (
return Status;
}
+ ASSERT (GetNext != NULL);
//
// Enumerate out the matching handles
//
@@ -246,6 +241,7 @@ CoreLocateHandle (
// If this is a search by register notify and a handle was
// returned, update the register notification position
//
+ ASSERT (SearchKey != NULL);
ProtNotify = SearchKey;
ProtNotify->Position = ProtNotify->Position->ForwardLink;
}
@@ -404,18 +400,19 @@ CoreGetNextLocateByProtocol (
/**
- Locates the handle to a device on the device path that best matches the specified protocol.
+ Locates the handle to a device on the device path that supports the specified protocol.
- @param Protocol The protocol to search for.
- @param DevicePath On input, a pointer to a pointer to the device
- path. On output, the device path pointer is
- modified to point to the remaining part of the
- devicepath.
- @param Device A pointer to the returned device handle.
+ @param Protocol Specifies the protocol to search for.
+ @param DevicePath On input, a pointer to a pointer to the device path. On output, the device
+ path pointer is modified to point to the remaining part of the device
+ path.
+ @param Device A pointer to the returned device handle.
- @retval EFI_SUCCESS The resulting handle was returned.
- @retval EFI_NOT_FOUND No handles matched the search.
- @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
+ @retval EFI_SUCCESS The resulting handle was returned.
+ @retval EFI_NOT_FOUND No handles match the search.
+ @retval EFI_INVALID_PARAMETER Protocol is NULL.
+ @retval EFI_INVALID_PARAMETER DevicePath is NULL.
+ @retval EFI_INVALID_PARAMETER A handle matched the search and Device is NULL.
**/
EFI_STATUS
@@ -434,6 +431,7 @@ CoreLocateDevicePath (
EFI_STATUS Status;
EFI_HANDLE *Handles;
EFI_HANDLE Handle;
+ EFI_HANDLE BestDevice;
EFI_DEVICE_PATH_PROTOCOL *SourcePath;
EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath;
@@ -445,22 +443,23 @@ CoreLocateDevicePath (
return EFI_INVALID_PARAMETER;
}
- if (Device == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- *Device = NULL;
+ Handles = NULL;
+ BestDevice = NULL;
SourcePath = *DevicePath;
- SourceSize = GetDevicePathSize (SourcePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);
-
- //
- // The source path can only have 1 instance
- //
- if (IsDevicePathMultiInstance (SourcePath)) {
- DEBUG((DEBUG_ERROR, "LocateDevicePath: Device path has too many instances\n"));
- return EFI_INVALID_PARAMETER;
+ TmpDevicePath = SourcePath;
+ while (!IsDevicePathEnd (TmpDevicePath)) {
+ if (IsDevicePathEndInstance (TmpDevicePath)) {
+ //
+ // If DevicePath is a multi-instance device path,
+ // the function will operate on the first instance
+ //
+ break;
+ }
+ TmpDevicePath = NextDevicePathNode (TmpDevicePath);
}
+ SourceSize = (UINTN) TmpDevicePath - (UINTN) SourcePath;
+
//
// Get a list of all handles that support the requested protocol
//
@@ -484,10 +483,11 @@ CoreLocateDevicePath (
// Check if DevicePath is first part of SourcePath
//
Size = GetDevicePathSize (TmpDevicePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);
- if ((Size <= SourceSize) && CompareMem (SourcePath, TmpDevicePath, Size) == 0) {
+ ASSERT (Size >= 0);
+ if ((Size <= SourceSize) && CompareMem (SourcePath, TmpDevicePath, (UINTN) Size) == 0) {
//
// If the size is equal to the best match, then we
- // have a duplice device path for 2 different device
+ // have a duplicate device path for 2 different device
// handles
//
ASSERT (Size != BestMatch);
@@ -497,7 +497,7 @@ CoreLocateDevicePath (
//
if (Size > BestMatch) {
BestMatch = Size;
- *Device = Handle;
+ BestDevice = Handle;
}
}
}
@@ -512,6 +512,11 @@ CoreLocateDevicePath (
return EFI_NOT_FOUND;
}
+ if (Device == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+ *Device = BestDevice;
+
//
// Return the remaining part of the device path
//
@@ -522,8 +527,8 @@ CoreLocateDevicePath (
/**
Return the first Protocol Interface that matches the Protocol GUID. If
- Registration is pasased in return a Protocol Instance that was just add
- to the system. If Retistration is NULL return the first Protocol Interface
+ Registration is passed in, return a Protocol Instance that was just add
+ to the system. If Registration is NULL return the first Protocol Interface
you find.
@param Protocol The protocol to search for
@@ -549,14 +554,10 @@ CoreLocateProtocol (
PROTOCOL_NOTIFY *ProtNotify;
IHANDLE *Handle;
- if (Interface == NULL) {
+ if ((Interface == NULL) || (Protocol == NULL)) {
return EFI_INVALID_PARAMETER;
}
- if (Protocol == NULL) {
- return EFI_NOT_FOUND;
- }
-
*Interface = NULL;
Status = EFI_SUCCESS;
@@ -570,7 +571,10 @@ CoreLocateProtocol (
//
// Lock the protocol database
//
- CoreAcquireProtocolLock ();
+ Status = CoreAcquireLockOrFail (&gProtocolDatabaseLock);
+ if (EFI_ERROR (Status)) {
+ return EFI_NOT_FOUND;
+ }
mEfiLocateHandleRequest += 1;
@@ -626,7 +630,7 @@ Done:
@retval EFI_NOT_FOUND No handles match the search.
@retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the
matching results.
- @retval EFI_INVALID_PARAMETER One or more paramters are not valid.
+ @retval EFI_INVALID_PARAMETER One or more parameters are not valid.
**/
EFI_STATUS