Revision: 15087
          http://sourceforge.net/p/edk2/code/15087
Author:   niruiyu
Date:     2014-01-10 03:42:36 +0000 (Fri, 10 Jan 2014)
Log Message:
-----------
Fix a bug in DebugPort driver's Unload() that leaves the 
DriverBinding/ComponentName(2) installed.

Signed-off-by: Ruiyu Ni <[email protected]>
Reviewed-by: Feng Tian <[email protected]>

Modified Paths:
--------------
    trunk/edk2/MdeModulePkg/Universal/DebugPortDxe/DebugPort.c
    trunk/edk2/MdeModulePkg/Universal/DebugPortDxe/DebugPort.h

Modified: trunk/edk2/MdeModulePkg/Universal/DebugPortDxe/DebugPort.c
===================================================================
--- trunk/edk2/MdeModulePkg/Universal/DebugPortDxe/DebugPort.c  2014-01-10 
02:48:49 UTC (rev 15086)
+++ trunk/edk2/MdeModulePkg/Universal/DebugPortDxe/DebugPort.c  2014-01-10 
03:42:36 UTC (rev 15087)
@@ -4,7 +4,7 @@
   ALL CODE IN THE SERIALIO STACK MUST BE RE-ENTRANT AND CALLABLE FROM
   INTERRUPT CONTEXT
 
-Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
 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
@@ -33,7 +33,6 @@
   DEBUGPORT_DEVICE_SIGNATURE,
   (EFI_HANDLE) 0,
   (EFI_HANDLE) 0,
-  (VOID *) NULL,
   (EFI_DEVICE_PATH_PROTOCOL *) NULL,
   {
     DebugPortReset,
@@ -57,72 +56,52 @@
   Records requested settings in DebugPort device structure.
 
 **/
-VOID
+EFI_DEVICE_PATH_PROTOCOL *
 GetDebugPortVariable (
   VOID
   )
 {
   UINTN                     DataSize;
+  EFI_DEVICE_PATH_PROTOCOL  *DebugPortVariable;
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
-  EFI_STATUS                Status;
 
-  DataSize = 0;
+  GetVariable2 (EFI_DEBUGPORT_VARIABLE_NAME, &gEfiDebugPortVariableGuid, 
&DebugPortVariable, &DataSize);
+  if (DebugPortVariable == NULL) {
+    return NULL;
+  }
 
-  Status = gRT->GetVariable (
-                  (CHAR16 *) EFI_DEBUGPORT_VARIABLE_NAME,
-                  &gEfiDebugPortVariableGuid,
-                  NULL,
-                  &DataSize,
-                  mDebugPortDevice.DebugPortVariable
-                  );
+  DevicePath = DebugPortVariable;
+  while (!IsDevicePathEnd (DevicePath) && !IS_UART_DEVICEPATH (DevicePath)) {
+    DevicePath = NextDevicePathNode (DevicePath);
+  }
 
-  if (Status == EFI_BUFFER_TOO_SMALL) {
-    if (mDebugPortDevice.DebugPortVariable != NULL) {
-      FreePool (mDebugPortDevice.DebugPortVariable);
-    }
-
-    mDebugPortDevice.DebugPortVariable = AllocatePool (DataSize);
-    if (mDebugPortDevice.DebugPortVariable != NULL) {
-      gRT->GetVariable (
-            (CHAR16 *) EFI_DEBUGPORT_VARIABLE_NAME,
-            &gEfiDebugPortVariableGuid,
-            NULL,
-            &DataSize,
-            mDebugPortDevice.DebugPortVariable
-            );
-      DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) 
mDebugPortDevice.DebugPortVariable;
-      while (!IsDevicePathEnd (DevicePath) && !IS_UART_DEVICEPATH 
(DevicePath)) {
-        DevicePath = NextDevicePathNode (DevicePath);
-      }
-
-      if (IsDevicePathEnd (DevicePath)) {
-        FreePool (mDebugPortDevice.DebugPortVariable);
-        mDebugPortDevice.DebugPortVariable = NULL;
-      } else {
-        CopyMem (
-          &mDebugPortDevice.BaudRate,
-          &((UART_DEVICE_PATH *) DevicePath)->BaudRate,
-          sizeof (((UART_DEVICE_PATH *) DevicePath)->BaudRate)
-          );
-        mDebugPortDevice.ReceiveFifoDepth = DEBUGPORT_UART_DEFAULT_FIFO_DEPTH;
-        mDebugPortDevice.Timeout          = DEBUGPORT_UART_DEFAULT_TIMEOUT;
-        CopyMem (
-          &mDebugPortDevice.Parity,
-          &((UART_DEVICE_PATH *) DevicePath)->Parity,
-          sizeof (((UART_DEVICE_PATH *) DevicePath)->Parity)
-          );
-        CopyMem (
-          &mDebugPortDevice.DataBits,
-          &((UART_DEVICE_PATH *) DevicePath)->DataBits,
-          sizeof (((UART_DEVICE_PATH *) DevicePath)->DataBits)
-          );
-        CopyMem (
-          &mDebugPortDevice.StopBits,
-          &((UART_DEVICE_PATH *) DevicePath)->StopBits,
-          sizeof (((UART_DEVICE_PATH *) DevicePath)->StopBits)
-          );
-      }
-    }
+  if (IsDevicePathEnd (DevicePath)) {
+    FreePool (DebugPortVariable);
+    return NULL;
+  } else {
+    CopyMem (
+      &mDebugPortDevice.BaudRate,
+      &((UART_DEVICE_PATH *) DevicePath)->BaudRate,
+      sizeof (((UART_DEVICE_PATH *) DevicePath)->BaudRate)
+      );
+    mDebugPortDevice.ReceiveFifoDepth = DEBUGPORT_UART_DEFAULT_FIFO_DEPTH;
+    mDebugPortDevice.Timeout          = DEBUGPORT_UART_DEFAULT_TIMEOUT;
+    CopyMem (
+      &mDebugPortDevice.Parity,
+      &((UART_DEVICE_PATH *) DevicePath)->Parity,
+      sizeof (((UART_DEVICE_PATH *) DevicePath)->Parity)
+      );
+    CopyMem (
+      &mDebugPortDevice.DataBits,
+      &((UART_DEVICE_PATH *) DevicePath)->DataBits,
+      sizeof (((UART_DEVICE_PATH *) DevicePath)->DataBits)
+      );
+    CopyMem (
+      &mDebugPortDevice.StopBits,
+      &((UART_DEVICE_PATH *) DevicePath)->StopBits,
+      sizeof (((UART_DEVICE_PATH *) DevicePath)->StopBits)
+      );
+    return DebugPortVariable;
   }
 }
 
@@ -196,8 +175,8 @@
   )
 {
   EFI_STATUS                Status;
-  EFI_DEVICE_PATH_PROTOCOL  *Dp1;
-  EFI_DEVICE_PATH_PROTOCOL  *Dp2;
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
+  EFI_DEVICE_PATH_PROTOCOL  *DebugPortVariable;
   EFI_SERIAL_IO_PROTOCOL    *SerialIo;
   EFI_DEBUGPORT_PROTOCOL    *DebugPortInterface;
   EFI_HANDLE                TempHandle;
@@ -212,25 +191,19 @@
   //
   // Read DebugPort variable to determine debug port selection and parameters
   //
-  GetDebugPortVariable ();
+  DebugPortVariable = GetDebugPortVariable ();
 
-  if (mDebugPortDevice.DebugPortVariable != NULL) {
+  if (DebugPortVariable != NULL) {
     //
     // There's a DEBUGPORT variable, so do LocateDevicePath and check to see if
     // the closest matching handle matches the controller handle, and if it 
does,
     // check to see that the remaining device path has the DebugPort GUIDed 
messaging
     // device path only.  Otherwise, it's a mismatch and EFI_UNSUPPORTED is 
returned.
     //
-    Dp1 = DuplicateDevicePath ((EFI_DEVICE_PATH_PROTOCOL *) 
mDebugPortDevice.DebugPortVariable);
-    if (Dp1 == NULL) {
-      return EFI_OUT_OF_RESOURCES;
-    }
-
-    Dp2 = Dp1;
-
+    DevicePath = DebugPortVariable;
     Status = gBS->LocateDevicePath (
                     &gEfiSerialIoProtocolGuid,
-                    &Dp2,
+                    &DevicePath,
                     &TempHandle
                     );
 
@@ -239,18 +212,18 @@
     }
 
     if (Status == EFI_SUCCESS &&
-        (Dp2->Type != MESSAGING_DEVICE_PATH ||
-         Dp2->SubType != MSG_VENDOR_DP ||
-         *((UINT16 *) Dp2->Length) != sizeof (DEBUGPORT_DEVICE_PATH))) {
+        (DevicePath->Type != MESSAGING_DEVICE_PATH ||
+         DevicePath->SubType != MSG_VENDOR_DP ||
+         *((UINT16 *) DevicePath->Length) != sizeof (DEBUGPORT_DEVICE_PATH))) {
 
       Status = EFI_UNSUPPORTED;
     }
 
-    if (Status == EFI_SUCCESS && !CompareGuid (&gEfiDebugPortDevicePathGuid, 
(GUID *) (Dp2 + 1))) {
+    if (Status == EFI_SUCCESS && !CompareGuid (&gEfiDebugPortDevicePathGuid, 
(GUID *) (DevicePath + 1))) {
       Status = EFI_UNSUPPORTED;
     }
 
-    FreePool (Dp1);
+    FreePool (DebugPortVariable);
     if (EFI_ERROR (Status)) {
       return Status;
     }
@@ -713,16 +686,60 @@
   EFI_HANDLE ImageHandle
   )
 {
+  EFI_STATUS  Status;
+  VOID        *ComponentName;
+  VOID        *ComponentName2;
+
   if (mDebugPortDevice.SerialIoBinding != NULL) {
     return EFI_ABORTED;
   }
 
   //
-  // Clean up allocations
+  // Driver is stopped already.
   //
-  if (mDebugPortDevice.DebugPortVariable != NULL) {
-    FreePool (mDebugPortDevice.DebugPortVariable);
+  Status = gBS->HandleProtocol (ImageHandle, &gEfiComponentNameProtocolGuid, 
&ComponentName);
+  if (EFI_ERROR (Status)) {
+    ComponentName = NULL;
   }
 
-  return EFI_SUCCESS;
+  Status = gBS->HandleProtocol (ImageHandle, &gEfiComponentName2ProtocolGuid, 
&ComponentName2);
+  if (EFI_ERROR (Status)) {
+    ComponentName2 = NULL;
+  }
+
+  if (ComponentName == NULL) {
+    if (ComponentName2 == NULL) {
+      Status = gBS->UninstallMultipleProtocolInterfaces (
+                      ImageHandle,
+                      &gEfiDriverBindingProtocolGuid,  
&gDebugPortDriverBinding,
+                      NULL
+                      );
+    } else {
+      Status = gBS->UninstallMultipleProtocolInterfaces (
+                      ImageHandle,
+                      &gEfiDriverBindingProtocolGuid,  
&gDebugPortDriverBinding,
+                      &gEfiComponentName2ProtocolGuid, ComponentName2,
+                      NULL
+                      );
+    }
+  } else {
+    if (ComponentName2 == NULL) {
+      Status = gBS->UninstallMultipleProtocolInterfaces (
+                      ImageHandle,
+                      &gEfiDriverBindingProtocolGuid,  
&gDebugPortDriverBinding,
+                      &gEfiComponentNameProtocolGuid,  ComponentName,
+                      NULL
+                      );
+    } else {
+      Status = gBS->UninstallMultipleProtocolInterfaces (
+                      ImageHandle,
+                      &gEfiDriverBindingProtocolGuid,  
&gDebugPortDriverBinding,
+                      &gEfiComponentNameProtocolGuid,  ComponentName,
+                      &gEfiComponentName2ProtocolGuid, ComponentName2,
+                      NULL
+                      );
+    }
+  }
+
+  return Status;
 }

Modified: trunk/edk2/MdeModulePkg/Universal/DebugPortDxe/DebugPort.h
===================================================================
--- trunk/edk2/MdeModulePkg/Universal/DebugPortDxe/DebugPort.h  2014-01-10 
02:48:49 UTC (rev 15086)
+++ trunk/edk2/MdeModulePkg/Universal/DebugPortDxe/DebugPort.h  2014-01-10 
03:42:36 UTC (rev 15087)
@@ -1,7 +1,7 @@
 /** @file
   Definitions and prototypes for DebugPort driver.
 
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
 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
@@ -52,7 +52,6 @@
   UINT32                      Signature;
   EFI_HANDLE                  DriverBindingHandle;
   EFI_HANDLE                  DebugPortDeviceHandle;
-  VOID                        *DebugPortVariable;
 
   EFI_DEVICE_PATH_PROTOCOL    *DebugPortDevicePath;
   EFI_DEBUGPORT_PROTOCOL      DebugPortInterface;

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