From a36a9b37940a8b7f6ccfe0a9cafe4195530f3891 Mon Sep 17 00:00:00 2001 From: mdkinney Date: Wed, 16 Mar 2011 16:17:09 +0000 Subject: [PATCH] Fix LocateDevicePath() to return proper error status code. It was returning EFI_INVALID_PARAMETER if Device was NULL even if not handles matched the search criteria. The proper behavior is to return EFI_NOT_FOUND if not handles match the search criteria, and only return EFI_INVALID_PARAMETER if at least one match is found and Device is NULL. Also update function header comment block for LocateDevicePath() to match UEFI Specification. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11406 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Core/Dxe/Hand/Locate.c | 37 ++++++++++++++++------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Hand/Locate.c b/MdeModulePkg/Core/Dxe/Hand/Locate.c index df7fa8fa6d..d4bc63c2ee 100644 --- a/MdeModulePkg/Core/Dxe/Hand/Locate.c +++ b/MdeModulePkg/Core/Dxe/Hand/Locate.c @@ -1,7 +1,7 @@ /** @file Locate handle functions -Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2011, 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 @@ -406,18 +406,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 @@ -436,6 +437,7 @@ CoreLocateDevicePath ( EFI_STATUS Status; EFI_HANDLE *Handles; EFI_HANDLE Handle; + EFI_HANDLE BestDevice; EFI_DEVICE_PATH_PROTOCOL *SourcePath; EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath; @@ -447,11 +449,7 @@ CoreLocateDevicePath ( return EFI_INVALID_PARAMETER; } - if (Device == NULL) { - return EFI_INVALID_PARAMETER; - } - - *Device = NULL; + BestDevice = NULL; SourcePath = *DevicePath; TmpDevicePath = SourcePath; while (!IsDevicePathEnd (TmpDevicePath)) { @@ -504,7 +502,7 @@ CoreLocateDevicePath ( // if (Size > BestMatch) { BestMatch = Size; - *Device = Handle; + BestDevice = Handle; } } } @@ -519,6 +517,11 @@ CoreLocateDevicePath ( return EFI_NOT_FOUND; } + if (Device == NULL) { + return EFI_INVALID_PARAMETER; + } + *Device = BestDevice; + // // Return the remaining part of the device path // -- 2.39.2