From 9e710bc95e6ac6e8fe2c7814a85e63029e01a4d3 Mon Sep 17 00:00:00 2001 From: Ruiyu Ni Date: Fri, 22 Nov 2013 07:39:02 +0000 Subject: Fix a bug in the Fat Stop() function which may return EFI_NOT_FOUND when the controller handle doesn't support DiskIo2. Signed-off-by: Ruiyu Ni Reviewed-by: Feng Tian (based on FatPkg commit 3454cf4f33cb3b71ebc19705a4d49f1ff3715611) [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 --- FatPkg/EnhancedFatDxe/Fat.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'FatPkg') diff --git a/FatPkg/EnhancedFatDxe/Fat.c b/FatPkg/EnhancedFatDxe/Fat.c index a52e6ea828..0dcb3bcb43 100644 --- a/FatPkg/EnhancedFatDxe/Fat.c +++ b/FatPkg/EnhancedFatDxe/Fat.c @@ -399,7 +399,9 @@ Returns: EFI_STATUS Status; EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem; FAT_VOLUME *Volume; + EFI_DISK_IO2_PROTOCOL *DiskIo2; + DiskIo2 = NULL; // // Get our context back // @@ -413,25 +415,29 @@ Returns: ); if (!EFI_ERROR (Status)) { - Volume = VOLUME_FROM_VOL_INTERFACE (FileSystem); - Status = FatAbandonVolume (Volume); - if (EFI_ERROR (Status)) { - return Status; - } + Volume = VOLUME_FROM_VOL_INTERFACE (FileSystem); + DiskIo2 = Volume->DiskIo2; + Status = FatAbandonVolume (Volume); } - Status = gBS->CloseProtocol ( - ControllerHandle, - &gEfiDiskIoProtocolGuid, - This->DriverBindingHandle, - ControllerHandle - ); - Status = gBS->CloseProtocol ( - ControllerHandle, - &gEfiDiskIo2ProtocolGuid, - This->DriverBindingHandle, - ControllerHandle - ); + if (!EFI_ERROR (Status)) { + if (DiskIo2 != NULL) { + Status = gBS->CloseProtocol ( + ControllerHandle, + &gEfiDiskIo2ProtocolGuid, + This->DriverBindingHandle, + ControllerHandle + ); + ASSERT_EFI_ERROR (Status); + } + Status = gBS->CloseProtocol ( + ControllerHandle, + &gEfiDiskIoProtocolGuid, + This->DriverBindingHandle, + ControllerHandle + ); + ASSERT_EFI_ERROR (Status); + } return Status; } -- cgit v1.2.3