From: Ruiyu Ni Date: Thu, 9 Jan 2014 08:59:24 +0000 (+0000) Subject: Fix a bug that prevents Fat driver being unloaded successfully. X-Git-Tag: edk2-stable201903~7400^2~14 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=b6efb80ad0fe5c3fd89484afd9a057532630b114;p=mirror_edk2.git Fix a bug that prevents Fat driver being unloaded successfully. Signed-off-by: Ruiyu Ni Reviewed-by: Feng Tian (based on FatPkg commit 8e0e11897d92c75a6cd1d0fa8af8cb50a60bfe2d) [jordan.l.justen@intel.com: Use script to relicense to 2-clause BSD] Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jordan Justen Acked-by: Mark Doran Acked-by: Laszlo Ersek --- diff --git a/FatPkg/EnhancedFatDxe/Fat.c b/FatPkg/EnhancedFatDxe/Fat.c index 0dcb3bcb43..2080005adc 100644 --- a/FatPkg/EnhancedFatDxe/Fat.c +++ b/FatPkg/EnhancedFatDxe/Fat.c @@ -1,6 +1,6 @@ /*++ -Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2014, 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 @@ -140,6 +140,8 @@ Returns: EFI_HANDLE *DeviceHandleBuffer; UINTN DeviceHandleCount; UINTN Index; + VOID *ComponentName; + VOID *ComponentName2; Status = gBS->LocateHandleBuffer ( AllHandles, @@ -148,18 +150,75 @@ Returns: &DeviceHandleCount, &DeviceHandleBuffer ); - if (!EFI_ERROR (Status)) { - for (Index = 0; Index < DeviceHandleCount; Index++) { + if (EFI_ERROR (Status)) { + return Status; + } + + for (Index = 0; Index < DeviceHandleCount; Index++) { + Status = EfiTestManagedDevice (DeviceHandleBuffer[Index], ImageHandle, &gEfiDiskIoProtocolGuid); + if (!EFI_ERROR (Status)) { Status = gBS->DisconnectController ( DeviceHandleBuffer[Index], ImageHandle, NULL ); + if (EFI_ERROR (Status)) { + break; + } + } + } + + if (Index == DeviceHandleCount) { + // + // Driver is stopped successfully. + // + Status = gBS->HandleProtocol (ImageHandle, &gEfiComponentNameProtocolGuid, &ComponentName); + if (EFI_ERROR (Status)) { + ComponentName = NULL; } - if (DeviceHandleBuffer != NULL) { - FreePool (DeviceHandleBuffer); + Status = gBS->HandleProtocol (ImageHandle, &gEfiComponentName2ProtocolGuid, &ComponentName2); + if (EFI_ERROR (Status)) { + ComponentName2 = NULL; } + + if (ComponentName == NULL) { + if (ComponentName2 == NULL) { + Status = gBS->UninstallMultipleProtocolInterfaces ( + ImageHandle, + &gEfiDriverBindingProtocolGuid, &gFatDriverBinding, + NULL + ); + } else { + Status = gBS->UninstallMultipleProtocolInterfaces ( + ImageHandle, + &gEfiDriverBindingProtocolGuid, &gFatDriverBinding, + &gEfiComponentName2ProtocolGuid, ComponentName2, + NULL + ); + } + } else { + if (ComponentName2 == NULL) { + Status = gBS->UninstallMultipleProtocolInterfaces ( + ImageHandle, + &gEfiDriverBindingProtocolGuid, &gFatDriverBinding, + &gEfiComponentNameProtocolGuid, ComponentName, + NULL + ); + } else { + Status = gBS->UninstallMultipleProtocolInterfaces ( + ImageHandle, + &gEfiDriverBindingProtocolGuid, &gFatDriverBinding, + &gEfiComponentNameProtocolGuid, ComponentName, + &gEfiComponentName2ProtocolGuid, ComponentName2, + NULL + ); + } + } + } + + if (DeviceHandleBuffer != NULL) { + FreePool (DeviceHandleBuffer); } return Status;