]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Fix a bug that prevents Fat driver being unloaded successfully.
authorRuiyu Ni <ruiyu.ni@intel.com>
Thu, 9 Jan 2014 08:59:24 +0000 (08:59 +0000)
committerJordan Justen <jordan.l.justen@intel.com>
Thu, 7 Apr 2016 06:22:43 +0000 (23:22 -0700)
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
(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 <jordan.l.justen@intel.com>
Acked-by: Mark Doran <mark.doran@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
FatPkg/EnhancedFatDxe/Fat.c

index 0dcb3bcb432b6234a3ebf7c2c06b08320151954a..2080005adc95321806ee03708a3883b4bce5d628 100644 (file)
@@ -1,6 +1,6 @@
 /*++\r
 \r
-Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials are licensed and made available\r
 under the terms and conditions of the BSD License which accompanies this\r
 distribution. The full text of the license may be found at\r
@@ -140,6 +140,8 @@ Returns:
   EFI_HANDLE  *DeviceHandleBuffer;\r
   UINTN       DeviceHandleCount;\r
   UINTN       Index;\r
+  VOID        *ComponentName;\r
+  VOID        *ComponentName2;\r
 \r
   Status = gBS->LocateHandleBuffer (\r
                   AllHandles,\r
@@ -148,18 +150,75 @@ Returns:
                   &DeviceHandleCount,\r
                   &DeviceHandleBuffer\r
                   );\r
-  if (!EFI_ERROR (Status)) {\r
-    for (Index = 0; Index < DeviceHandleCount; Index++) {\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  for (Index = 0; Index < DeviceHandleCount; Index++) {\r
+    Status = EfiTestManagedDevice (DeviceHandleBuffer[Index], ImageHandle, &gEfiDiskIoProtocolGuid);\r
+    if (!EFI_ERROR (Status)) {\r
       Status = gBS->DisconnectController (\r
                       DeviceHandleBuffer[Index],\r
                       ImageHandle,\r
                       NULL\r
                       );\r
+      if (EFI_ERROR (Status)) {\r
+        break;\r
+      }\r
+    }\r
+  }\r
+\r
+  if (Index == DeviceHandleCount) {\r
+    //\r
+    // Driver is stopped successfully.\r
+    //\r
+    Status = gBS->HandleProtocol (ImageHandle, &gEfiComponentNameProtocolGuid, &ComponentName);\r
+    if (EFI_ERROR (Status)) {\r
+      ComponentName = NULL;\r
     }\r
 \r
-    if (DeviceHandleBuffer != NULL) {\r
-      FreePool (DeviceHandleBuffer);\r
+    Status = gBS->HandleProtocol (ImageHandle, &gEfiComponentName2ProtocolGuid, &ComponentName2);\r
+    if (EFI_ERROR (Status)) {\r
+      ComponentName2 = NULL;\r
     }\r
+\r
+    if (ComponentName == NULL) {\r
+      if (ComponentName2 == NULL) {\r
+        Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                        ImageHandle,\r
+                        &gEfiDriverBindingProtocolGuid,  &gFatDriverBinding,\r
+                        NULL\r
+                        );\r
+      } else {\r
+        Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                        ImageHandle,\r
+                        &gEfiDriverBindingProtocolGuid,  &gFatDriverBinding,\r
+                        &gEfiComponentName2ProtocolGuid, ComponentName2,\r
+                        NULL\r
+                        );\r
+      }\r
+    } else {\r
+      if (ComponentName2 == NULL) {\r
+        Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                        ImageHandle,\r
+                        &gEfiDriverBindingProtocolGuid,  &gFatDriverBinding,\r
+                        &gEfiComponentNameProtocolGuid,  ComponentName,\r
+                        NULL\r
+                        );\r
+      } else {\r
+        Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                        ImageHandle,\r
+                        &gEfiDriverBindingProtocolGuid,  &gFatDriverBinding,\r
+                        &gEfiComponentNameProtocolGuid,  ComponentName,\r
+                        &gEfiComponentName2ProtocolGuid, ComponentName2,\r
+                        NULL\r
+                        );\r
+      }\r
+    }\r
+  }\r
+\r
+  if (DeviceHandleBuffer != NULL) {\r
+    FreePool (DeviceHandleBuffer);\r
   }\r
 \r
   return Status;\r