]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Hand/Notify.c
Fix a bug by adding CoreReleaseProtocolLock.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Hand / Notify.c
index 7ee81b984e78b965114104231373966c577318a3..572ba12eed776d74691a9afe82c43321e569658e 100644 (file)
@@ -1,19 +1,18 @@
-/** @file \r
+/** @file\r
+  Support functions for UEFI protocol notification infrastructure.\r
 \r
-  UEFI notify infrastructure\r
+Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
+All rights reserved. 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
+http://opensource.org/licenses/bsd-license.php\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation                                                         \r
-All rights reserved. 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
-http://opensource.org/licenses/bsd-license.php                                            \r
-                                                                                          \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 **/\r
 \r
-#include <DxeMain.h>\r
+#include "DxeMain.h"\r
 \r
 \r
 /**\r
@@ -43,9 +42,9 @@ CoreNotifyProtocolEntry (
 /**\r
   Removes Protocol from the protocol list (but not the handle list).\r
 \r
-  @param  Handle                 The handle to remove protocol on. \r
-  @param  Protocol               GUID of the protocol to be moved \r
-  @param  Interface              The interface of the protocol \r
+  @param  Handle                 The handle to remove protocol on.\r
+  @param  Protocol               GUID of the protocol to be moved\r
+  @param  Interface              The interface of the protocol\r
 \r
   @return Protocol Entry\r
 \r
@@ -72,7 +71,6 @@ CoreRemoveInterfaceFromProtocol (
     //\r
     // If there's a protocol notify location pointing to this entry, back it up one\r
     //\r
-\r
     for(Link = ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link=Link->ForwardLink) {\r
       ProtNotify = CR(Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);\r
 \r
@@ -84,7 +82,6 @@ CoreRemoveInterfaceFromProtocol (
     //\r
     // Remove the protocol interface entry\r
     //\r
-\r
     RemoveEntryList (&Prot->ByProtocol);\r
   }\r
 \r
@@ -92,18 +89,16 @@ CoreRemoveInterfaceFromProtocol (
 }\r
 \r
 \r
-\r
-\r
 /**\r
   Add a new protocol notification record for the request protocol.\r
 \r
-  @param  Protocol               The requested protocol to add the notify \r
-                                 registration \r
-  @param  Event                  The event to signal \r
-  @param  Registration           Returns the registration record \r
+  @param  Protocol               The requested protocol to add the notify\r
+                                 registration\r
+  @param  Event                  The event to signal\r
+  @param  Registration           Returns the registration record\r
 \r
-  @retval EFI_INVALID_PARAMETER  Invalid parameter \r
-  @retval EFI_SUCCESS            Successfully returned the registration record \r
+  @retval EFI_INVALID_PARAMETER  Invalid parameter\r
+  @retval EFI_SUCCESS            Successfully returned the registration record\r
                                  that has been added\r
 \r
 **/\r
@@ -112,13 +107,13 @@ EFIAPI
 CoreRegisterProtocolNotify (\r
   IN EFI_GUID       *Protocol,\r
   IN EFI_EVENT      Event,\r
-  OUT  VOID           **Registration\r
+  OUT  VOID         **Registration\r
   )\r
 {\r
-  PROTOCOL_ENTRY      *ProtEntry;\r
-  PROTOCOL_NOTIFY     *ProtNotify;\r
+  PROTOCOL_ENTRY    *ProtEntry;\r
+  PROTOCOL_NOTIFY   *ProtNotify;\r
   EFI_STATUS        Status;\r
-  \r
+\r
   if ((Protocol == NULL) || (Event == NULL) || (Registration == NULL))  {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -126,7 +121,7 @@ CoreRegisterProtocolNotify (
   CoreAcquireProtocolLock ();\r
 \r
   ProtNotify = NULL;\r
-  \r
+\r
   //\r
   // Get the protocol entry to add the notification too\r
   //\r
@@ -137,18 +132,16 @@ CoreRegisterProtocolNotify (
     //\r
     // Allocate a new notification record\r
     //\r
-\r
-    ProtNotify = CoreAllocateBootServicesPool (sizeof(PROTOCOL_NOTIFY));\r
-\r
+    ProtNotify = AllocatePool (sizeof(PROTOCOL_NOTIFY));\r
     if (ProtNotify != NULL) {\r
-      \r
+\r
       ProtNotify->Signature = PROTOCOL_NOTIFY_SIGNATURE;\r
       ProtNotify->Protocol = ProtEntry;\r
       ProtNotify->Event = Event;\r
       //\r
       // start at the begining\r
       //\r
-      ProtNotify->Position = &ProtEntry->Protocols; \r
+      ProtNotify->Position = &ProtEntry->Protocols;\r
 \r
       InsertTailList (&ProtEntry->Notify, &ProtNotify->Link);\r
     }\r
@@ -171,16 +164,14 @@ CoreRegisterProtocolNotify (
 }\r
 \r
 \r
-\r
-\r
 /**\r
   Reinstall a protocol interface on a device handle.  The OldInterface for Protocol is replaced by the NewInterface.\r
 \r
-  @param  UserHandle             Handle on which the interface is to be \r
-                                 reinstalled \r
-  @param  Protocol               The numeric ID of the interface \r
-  @param  OldInterface           A pointer to the old interface \r
-  @param  NewInterface           A pointer to the new interface \r
+  @param  UserHandle             Handle on which the interface is to be\r
+                                 reinstalled\r
+  @param  Protocol               The numeric ID of the interface\r
+  @param  OldInterface           A pointer to the old interface\r
+  @param  NewInterface           A pointer to the new interface\r
 \r
   @retval EFI_SUCCESS            The protocol interface was installed\r
   @retval EFI_NOT_FOUND          The OldInterface on the handle was not found\r
@@ -222,8 +213,8 @@ CoreReinstallProtocolInterface (
   //\r
   Prot = CoreFindProtocolInterface (UserHandle, Protocol, OldInterface);\r
   if (Prot == NULL) {\r
-    CoreReleaseProtocolLock ();\r
-    return EFI_NOT_FOUND;\r
+    Status = EFI_NOT_FOUND;\r
+    goto Done;\r
   }\r
 \r
   //\r
@@ -237,8 +228,7 @@ CoreReinstallProtocolInterface (
     //\r
     // One or more drivers refused to release, so return the error\r
     //\r
-    CoreReleaseProtocolLock ();\r
-    return Status;\r
+    goto Done;\r
   }\r
 \r
   //\r
@@ -247,8 +237,8 @@ CoreReinstallProtocolInterface (
   Prot = CoreRemoveInterfaceFromProtocol (Handle, Protocol, OldInterface);\r
 \r
   if (Prot == NULL) {\r
-    CoreReleaseProtocolLock ();\r
-    return EFI_NOT_FOUND;\r
+    Status = EFI_NOT_FOUND;\r
+    goto Done;\r
   }\r
 \r
   ProtEntry = Prot->Protocol;\r
@@ -274,20 +264,26 @@ CoreReinstallProtocolInterface (
   // Release the lock and connect all drivers to UserHandle\r
   //\r
   CoreReleaseProtocolLock ();\r
-  Status = CoreConnectController (\r
-                  UserHandle, \r
-                  NULL, \r
-                  NULL, \r
-                  TRUE\r
-                  );\r
+  //\r
+  // Return code is ignored on purpose.\r
+  //\r
+  CoreConnectController (\r
+    UserHandle,\r
+    NULL,\r
+    NULL,\r
+    TRUE\r
+    );\r
   CoreAcquireProtocolLock ();\r
-  \r
+\r
   //\r
   // Notify the notification list for this protocol\r
   //\r
   CoreNotifyProtocolEntry (ProtEntry);\r
 \r
+  Status = EFI_SUCCESS;\r
+\r
+Done:\r
   CoreReleaseProtocolLock ();\r
-  \r
-  return EFI_SUCCESS;\r
+\r
+  return Status;\r
 }\r