]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Fix a bug in DebugPort driver's Unload() that leaves the DriverBinding/ComponentName...
authorRuiyu Ni <ruiyu.ni@intel.com>
Fri, 10 Jan 2014 03:42:36 +0000 (03:42 +0000)
committerniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 10 Jan 2014 03:42:36 +0000 (03:42 +0000)
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15087 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/DebugPortDxe/DebugPort.c
MdeModulePkg/Universal/DebugPortDxe/DebugPort.h

index 2616299df7d48c21a71a608dbb93cf61828b15c2..984288e30267a6e0c12761db8098cad01895e657 100644 (file)
@@ -4,7 +4,7 @@
   ALL CODE IN THE SERIALIO STACK MUST BE RE-ENTRANT AND CALLABLE FROM\r
   INTERRUPT CONTEXT\r
 \r
   ALL CODE IN THE SERIALIO STACK MUST BE RE-ENTRANT AND CALLABLE FROM\r
   INTERRUPT CONTEXT\r
 \r
-Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -33,7 +33,6 @@ DEBUGPORT_DEVICE mDebugPortDevice = {
   DEBUGPORT_DEVICE_SIGNATURE,\r
   (EFI_HANDLE) 0,\r
   (EFI_HANDLE) 0,\r
   DEBUGPORT_DEVICE_SIGNATURE,\r
   (EFI_HANDLE) 0,\r
   (EFI_HANDLE) 0,\r
-  (VOID *) NULL,\r
   (EFI_DEVICE_PATH_PROTOCOL *) NULL,\r
   {\r
     DebugPortReset,\r
   (EFI_DEVICE_PATH_PROTOCOL *) NULL,\r
   {\r
     DebugPortReset,\r
@@ -57,72 +56,52 @@ DEBUGPORT_DEVICE mDebugPortDevice = {
   Records requested settings in DebugPort device structure.\r
 \r
 **/\r
   Records requested settings in DebugPort device structure.\r
 \r
 **/\r
-VOID\r
+EFI_DEVICE_PATH_PROTOCOL *\r
 GetDebugPortVariable (\r
   VOID\r
   )\r
 {\r
   UINTN                     DataSize;\r
 GetDebugPortVariable (\r
   VOID\r
   )\r
 {\r
   UINTN                     DataSize;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DebugPortVariable;\r
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
-  EFI_STATUS                Status;\r
-\r
-  DataSize = 0;\r
 \r
 \r
-  Status = gRT->GetVariable (\r
-                  (CHAR16 *) EFI_DEBUGPORT_VARIABLE_NAME,\r
-                  &gEfiDebugPortVariableGuid,\r
-                  NULL,\r
-                  &DataSize,\r
-                  mDebugPortDevice.DebugPortVariable\r
-                  );\r
-\r
-  if (Status == EFI_BUFFER_TOO_SMALL) {\r
-    if (mDebugPortDevice.DebugPortVariable != NULL) {\r
-      FreePool (mDebugPortDevice.DebugPortVariable);\r
-    }\r
+  GetVariable2 (EFI_DEBUGPORT_VARIABLE_NAME, &gEfiDebugPortVariableGuid, &DebugPortVariable, &DataSize);\r
+  if (DebugPortVariable == NULL) {\r
+    return NULL;\r
+  }\r
 \r
 \r
-    mDebugPortDevice.DebugPortVariable = AllocatePool (DataSize);\r
-    if (mDebugPortDevice.DebugPortVariable != NULL) {\r
-      gRT->GetVariable (\r
-            (CHAR16 *) EFI_DEBUGPORT_VARIABLE_NAME,\r
-            &gEfiDebugPortVariableGuid,\r
-            NULL,\r
-            &DataSize,\r
-            mDebugPortDevice.DebugPortVariable\r
-            );\r
-      DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) mDebugPortDevice.DebugPortVariable;\r
-      while (!IsDevicePathEnd (DevicePath) && !IS_UART_DEVICEPATH (DevicePath)) {\r
-        DevicePath = NextDevicePathNode (DevicePath);\r
-      }\r
+  DevicePath = DebugPortVariable;\r
+  while (!IsDevicePathEnd (DevicePath) && !IS_UART_DEVICEPATH (DevicePath)) {\r
+    DevicePath = NextDevicePathNode (DevicePath);\r
+  }\r
 \r
 \r
-      if (IsDevicePathEnd (DevicePath)) {\r
-        FreePool (mDebugPortDevice.DebugPortVariable);\r
-        mDebugPortDevice.DebugPortVariable = NULL;\r
-      } else {\r
-        CopyMem (\r
-          &mDebugPortDevice.BaudRate,\r
-          &((UART_DEVICE_PATH *) DevicePath)->BaudRate,\r
-          sizeof (((UART_DEVICE_PATH *) DevicePath)->BaudRate)\r
-          );\r
-        mDebugPortDevice.ReceiveFifoDepth = DEBUGPORT_UART_DEFAULT_FIFO_DEPTH;\r
-        mDebugPortDevice.Timeout          = DEBUGPORT_UART_DEFAULT_TIMEOUT;\r
-        CopyMem (\r
-          &mDebugPortDevice.Parity,\r
-          &((UART_DEVICE_PATH *) DevicePath)->Parity,\r
-          sizeof (((UART_DEVICE_PATH *) DevicePath)->Parity)\r
-          );\r
-        CopyMem (\r
-          &mDebugPortDevice.DataBits,\r
-          &((UART_DEVICE_PATH *) DevicePath)->DataBits,\r
-          sizeof (((UART_DEVICE_PATH *) DevicePath)->DataBits)\r
-          );\r
-        CopyMem (\r
-          &mDebugPortDevice.StopBits,\r
-          &((UART_DEVICE_PATH *) DevicePath)->StopBits,\r
-          sizeof (((UART_DEVICE_PATH *) DevicePath)->StopBits)\r
-          );\r
-      }\r
-    }\r
+  if (IsDevicePathEnd (DevicePath)) {\r
+    FreePool (DebugPortVariable);\r
+    return NULL;\r
+  } else {\r
+    CopyMem (\r
+      &mDebugPortDevice.BaudRate,\r
+      &((UART_DEVICE_PATH *) DevicePath)->BaudRate,\r
+      sizeof (((UART_DEVICE_PATH *) DevicePath)->BaudRate)\r
+      );\r
+    mDebugPortDevice.ReceiveFifoDepth = DEBUGPORT_UART_DEFAULT_FIFO_DEPTH;\r
+    mDebugPortDevice.Timeout          = DEBUGPORT_UART_DEFAULT_TIMEOUT;\r
+    CopyMem (\r
+      &mDebugPortDevice.Parity,\r
+      &((UART_DEVICE_PATH *) DevicePath)->Parity,\r
+      sizeof (((UART_DEVICE_PATH *) DevicePath)->Parity)\r
+      );\r
+    CopyMem (\r
+      &mDebugPortDevice.DataBits,\r
+      &((UART_DEVICE_PATH *) DevicePath)->DataBits,\r
+      sizeof (((UART_DEVICE_PATH *) DevicePath)->DataBits)\r
+      );\r
+    CopyMem (\r
+      &mDebugPortDevice.StopBits,\r
+      &((UART_DEVICE_PATH *) DevicePath)->StopBits,\r
+      sizeof (((UART_DEVICE_PATH *) DevicePath)->StopBits)\r
+      );\r
+    return DebugPortVariable;\r
   }\r
 }\r
 \r
   }\r
 }\r
 \r
@@ -196,8 +175,8 @@ DebugPortSupported (
   )\r
 {\r
   EFI_STATUS                Status;\r
   )\r
 {\r
   EFI_STATUS                Status;\r
-  EFI_DEVICE_PATH_PROTOCOL  *Dp1;\r
-  EFI_DEVICE_PATH_PROTOCOL  *Dp2;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DebugPortVariable;\r
   EFI_SERIAL_IO_PROTOCOL    *SerialIo;\r
   EFI_DEBUGPORT_PROTOCOL    *DebugPortInterface;\r
   EFI_HANDLE                TempHandle;\r
   EFI_SERIAL_IO_PROTOCOL    *SerialIo;\r
   EFI_DEBUGPORT_PROTOCOL    *DebugPortInterface;\r
   EFI_HANDLE                TempHandle;\r
@@ -212,25 +191,19 @@ DebugPortSupported (
   //\r
   // Read DebugPort variable to determine debug port selection and parameters\r
   //\r
   //\r
   // Read DebugPort variable to determine debug port selection and parameters\r
   //\r
-  GetDebugPortVariable ();\r
+  DebugPortVariable = GetDebugPortVariable ();\r
 \r
 \r
-  if (mDebugPortDevice.DebugPortVariable != NULL) {\r
+  if (DebugPortVariable != NULL) {\r
     //\r
     // There's a DEBUGPORT variable, so do LocateDevicePath and check to see if\r
     // the closest matching handle matches the controller handle, and if it does,\r
     // check to see that the remaining device path has the DebugPort GUIDed messaging\r
     // device path only.  Otherwise, it's a mismatch and EFI_UNSUPPORTED is returned.\r
     //\r
     //\r
     // There's a DEBUGPORT variable, so do LocateDevicePath and check to see if\r
     // the closest matching handle matches the controller handle, and if it does,\r
     // check to see that the remaining device path has the DebugPort GUIDed messaging\r
     // device path only.  Otherwise, it's a mismatch and EFI_UNSUPPORTED is returned.\r
     //\r
-    Dp1 = DuplicateDevicePath ((EFI_DEVICE_PATH_PROTOCOL *) mDebugPortDevice.DebugPortVariable);\r
-    if (Dp1 == NULL) {\r
-      return EFI_OUT_OF_RESOURCES;\r
-    }\r
-\r
-    Dp2 = Dp1;\r
-\r
+    DevicePath = DebugPortVariable;\r
     Status = gBS->LocateDevicePath (\r
                     &gEfiSerialIoProtocolGuid,\r
     Status = gBS->LocateDevicePath (\r
                     &gEfiSerialIoProtocolGuid,\r
-                    &Dp2,\r
+                    &DevicePath,\r
                     &TempHandle\r
                     );\r
 \r
                     &TempHandle\r
                     );\r
 \r
@@ -239,18 +212,18 @@ DebugPortSupported (
     }\r
 \r
     if (Status == EFI_SUCCESS &&\r
     }\r
 \r
     if (Status == EFI_SUCCESS &&\r
-        (Dp2->Type != MESSAGING_DEVICE_PATH ||\r
-         Dp2->SubType != MSG_VENDOR_DP ||\r
-         *((UINT16 *) Dp2->Length) != sizeof (DEBUGPORT_DEVICE_PATH))) {\r
+        (DevicePath->Type != MESSAGING_DEVICE_PATH ||\r
+         DevicePath->SubType != MSG_VENDOR_DP ||\r
+         *((UINT16 *) DevicePath->Length) != sizeof (DEBUGPORT_DEVICE_PATH))) {\r
 \r
       Status = EFI_UNSUPPORTED;\r
     }\r
 \r
 \r
       Status = EFI_UNSUPPORTED;\r
     }\r
 \r
-    if (Status == EFI_SUCCESS && !CompareGuid (&gEfiDebugPortDevicePathGuid, (GUID *) (Dp2 + 1))) {\r
+    if (Status == EFI_SUCCESS && !CompareGuid (&gEfiDebugPortDevicePathGuid, (GUID *) (DevicePath + 1))) {\r
       Status = EFI_UNSUPPORTED;\r
     }\r
 \r
       Status = EFI_UNSUPPORTED;\r
     }\r
 \r
-    FreePool (Dp1);\r
+    FreePool (DebugPortVariable);\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
@@ -713,16 +686,60 @@ ImageUnloadHandler (
   EFI_HANDLE ImageHandle\r
   )\r
 {\r
   EFI_HANDLE ImageHandle\r
   )\r
 {\r
+  EFI_STATUS  Status;\r
+  VOID        *ComponentName;\r
+  VOID        *ComponentName2;\r
+\r
   if (mDebugPortDevice.SerialIoBinding != NULL) {\r
     return EFI_ABORTED;\r
   }\r
 \r
   //\r
   if (mDebugPortDevice.SerialIoBinding != NULL) {\r
     return EFI_ABORTED;\r
   }\r
 \r
   //\r
-  // Clean up allocations\r
+  // Driver is stopped already.\r
   //\r
   //\r
-  if (mDebugPortDevice.DebugPortVariable != NULL) {\r
-    FreePool (mDebugPortDevice.DebugPortVariable);\r
+  Status = gBS->HandleProtocol (ImageHandle, &gEfiComponentNameProtocolGuid, &ComponentName);\r
+  if (EFI_ERROR (Status)) {\r
+    ComponentName = NULL;\r
   }\r
 \r
   }\r
 \r
-  return EFI_SUCCESS;\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,  &gDebugPortDriverBinding,\r
+                      NULL\r
+                      );\r
+    } else {\r
+      Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                      ImageHandle,\r
+                      &gEfiDriverBindingProtocolGuid,  &gDebugPortDriverBinding,\r
+                      &gEfiComponentName2ProtocolGuid, ComponentName2,\r
+                      NULL\r
+                      );\r
+    }\r
+  } else {\r
+    if (ComponentName2 == NULL) {\r
+      Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                      ImageHandle,\r
+                      &gEfiDriverBindingProtocolGuid,  &gDebugPortDriverBinding,\r
+                      &gEfiComponentNameProtocolGuid,  ComponentName,\r
+                      NULL\r
+                      );\r
+    } else {\r
+      Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                      ImageHandle,\r
+                      &gEfiDriverBindingProtocolGuid,  &gDebugPortDriverBinding,\r
+                      &gEfiComponentNameProtocolGuid,  ComponentName,\r
+                      &gEfiComponentName2ProtocolGuid, ComponentName2,\r
+                      NULL\r
+                      );\r
+    }\r
+  }\r
+\r
+  return Status;\r
 }\r
 }\r
index f108223650549d547effe8c4159b139b39d2e8da..3ce702dfa46b5a1588cffbd2b2d7a717dd10cdbf 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Definitions and prototypes for DebugPort driver.\r
 \r
 /** @file\r
   Definitions and prototypes for DebugPort driver.\r
 \r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -52,7 +52,6 @@ typedef struct {
   UINT32                      Signature;\r
   EFI_HANDLE                  DriverBindingHandle;\r
   EFI_HANDLE                  DebugPortDeviceHandle;\r
   UINT32                      Signature;\r
   EFI_HANDLE                  DriverBindingHandle;\r
   EFI_HANDLE                  DebugPortDeviceHandle;\r
-  VOID                        *DebugPortVariable;\r
 \r
   EFI_DEVICE_PATH_PROTOCOL    *DebugPortDevicePath;\r
   EFI_DEBUGPORT_PROTOCOL      DebugPortInterface;\r
 \r
   EFI_DEVICE_PATH_PROTOCOL    *DebugPortDevicePath;\r
   EFI_DEBUGPORT_PROTOCOL      DebugPortInterface;\r