Revision: 15090
          http://sourceforge.net/p/edk2/code/15090
Author:   erictian
Date:     2014-01-10 07:15:52 +0000 (Fri, 10 Jan 2014)
Log Message:
-----------
MdeModulePkg/NvmExpressDxe: Fix a bug in NvmExpressDxe driver?\226?\128?\153s 
Unload() that forget to uninstall the DriverSupportedEfiVersionProtocol

Signed-off-by: Feng Tian <[email protected]>
Reviewed-by: Elvin Li <[email protected]>

Modified Paths:
--------------
    trunk/edk2/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c

Modified: trunk/edk2/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c
===================================================================
--- trunk/edk2/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c  2014-01-10 
05:25:50 UTC (rev 15089)
+++ trunk/edk2/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c  2014-01-10 
07:15:52 UTC (rev 15090)
@@ -928,97 +928,102 @@
   EFI_HANDLE                        *DeviceHandleBuffer;
   UINTN                             DeviceHandleCount;
   UINTN                             Index;
-  EFI_DRIVER_BINDING_PROTOCOL       *DriverBinding;
   EFI_COMPONENT_NAME_PROTOCOL       *ComponentName;
   EFI_COMPONENT_NAME2_PROTOCOL      *ComponentName2;
 
   //
-  // Get the list of all the handles in the handle database.
-  // If there is an error getting the list, then the unload
-  // operation fails.
+  // Get the list of the device handles managed by this driver.
+  // If there is an error getting the list, then means the driver
+  // doesn't manage any device. At this way, we would only close
+  // those protocols installed at image handle.
   //
+  DeviceHandleBuffer = NULL;
   Status = gBS->LocateHandleBuffer (
-                  AllHandles,
+                  ByProtocol,
+                  &gEfiCallerIdGuid,
                   NULL,
-                  NULL,
                   &DeviceHandleCount,
                   &DeviceHandleBuffer
                   );
 
-  if (EFI_ERROR (Status)) {
-    return Status;
+  if (!EFI_ERROR (Status)) {
+    //
+    // Disconnect the driver specified by ImageHandle from all
+    // the devices in the handle database.
+    //
+    for (Index = 0; Index < DeviceHandleCount; Index++) {
+      Status = gBS->DisconnectController (
+                      DeviceHandleBuffer[Index],
+                      ImageHandle,
+                      NULL
+                      );
+      if (EFI_ERROR (Status)) {
+        goto EXIT;
+      }
+    }
   }
 
   //
-  // Disconnect the driver specified by ImageHandle from all
-  // the devices in the handle database.
+  // Uninstall all the protocols installed in the driver entry point
   //
-  for (Index = 0; Index < DeviceHandleCount; Index++) {
-    Status = gBS->DisconnectController (
-                    DeviceHandleBuffer[Index],
-                    ImageHandle,
-                    NULL
-                    );
+  Status = gBS->UninstallMultipleProtocolInterfaces (
+                  ImageHandle,
+                  &gEfiDriverBindingProtocolGuid,
+                  &gNvmExpressDriverBinding,
+                  &gEfiDriverSupportedEfiVersionProtocolGuid,
+                  &gNvmExpressDriverSupportedEfiVersion,
+                  NULL
+                  );
+
+  if (EFI_ERROR (Status)) {
+    goto EXIT;
   }
 
   //
-  // Uninstall all the protocols installed in the driver entry point
+  // Note we have to one by one uninstall the following protocols.
+  // It's because some of them are optionally installed based on
+  // the following PCD settings.
+  //   gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnosticsDisable
+  //   gEfiMdePkgTokenSpaceGuid.PcdComponentNameDisable
+  //   gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnostics2Disable
+  //   gEfiMdePkgTokenSpaceGuid.PcdComponentName2Disable
   //
-  for (Index = 0; Index < DeviceHandleCount; Index++) {
-    Status = gBS->HandleProtocol (
-                    DeviceHandleBuffer[Index],
-                    &gEfiDriverBindingProtocolGuid,
-                    (VOID **) &DriverBinding
-                    );
+  Status = gBS->HandleProtocol (
+                  ImageHandle,
+                  &gEfiComponentNameProtocolGuid,
+                  (VOID **) &ComponentName
+                  );
+  if (!EFI_ERROR (Status)) {
+    gBS->UninstallProtocolInterface (
+           ImageHandle,
+           &gEfiComponentNameProtocolGuid,
+           ComponentName
+           );
+  }
 
-    if (EFI_ERROR (Status)) {
-      continue;
-    }
-
-    if (DriverBinding->ImageHandle != ImageHandle) {
-      continue;
-    }
-
+  Status = gBS->HandleProtocol (
+                  ImageHandle,
+                  &gEfiComponentName2ProtocolGuid,
+                  (VOID **) &ComponentName2
+                  );
+  if (!EFI_ERROR (Status)) {
     gBS->UninstallProtocolInterface (
            ImageHandle,
-           &gEfiDriverBindingProtocolGuid,
-           DriverBinding
+           &gEfiComponentName2ProtocolGuid,
+           ComponentName2
            );
+  }
 
-    Status = gBS->HandleProtocol (
-                    DeviceHandleBuffer[Index],
-                    &gEfiComponentNameProtocolGuid,
-                    (VOID **) &ComponentName
-                    );
-    if (!EFI_ERROR (Status)) {
-      gBS->UninstallProtocolInterface (
-             ImageHandle,
-             &gEfiComponentNameProtocolGuid,
-             ComponentName
-             );
-    }
+  Status = EFI_SUCCESS;
 
-    Status = gBS->HandleProtocol (
-                    DeviceHandleBuffer[Index],
-                    &gEfiComponentName2ProtocolGuid,
-                    (VOID **) &ComponentName2
-                    );
-    if (!EFI_ERROR (Status)) {
-      gBS->UninstallProtocolInterface (
-             ImageHandle,
-             &gEfiComponentName2ProtocolGuid,
-             ComponentName2
-             );
-    }
-  }
-
+EXIT:
   //
   // Free the buffer containing the list of handles from the handle database
   //
   if (DeviceHandleBuffer != NULL) {
     gBS->FreePool (DeviceHandleBuffer);
   }
-  return EFI_SUCCESS;
+  return Status;
 }
 
 /**

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to