]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/PiSmmCore/Handle.c
MdeModulePkg: Apply uncrustify changes
[mirror_edk2.git] / MdeModulePkg / Core / PiSmmCore / Handle.c
index 7625c386921ca987fb3a51dc41f6b2096c118eaf..5a8760a430595c0985ff3086bf4159a4f0c9e3df 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   SMM handle & protocol handling.\r
 \r
-  Copyright (c) 2009 - 2010, 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
-  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
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -18,8 +12,8 @@
 // mProtocolDatabase     - A list of all protocols in the system.  (simple list for now)\r
 // gHandleList           - A list of all the handles in the system\r
 //\r
-LIST_ENTRY  mProtocolDatabase  = INITIALIZE_LIST_HEAD_VARIABLE (mProtocolDatabase);\r
-LIST_ENTRY  gHandleList        = INITIALIZE_LIST_HEAD_VARIABLE (gHandleList);\r
+LIST_ENTRY  mProtocolDatabase = INITIALIZE_LIST_HEAD_VARIABLE (mProtocolDatabase);\r
+LIST_ENTRY  gHandleList       = INITIALIZE_LIST_HEAD_VARIABLE (gHandleList);\r
 \r
 /**\r
   Check whether a handle is a valid EFI_HANDLE\r
@@ -41,9 +35,11 @@ SmmValidateHandle (
   if (Handle == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
+\r
   if (Handle->Signature != EFI_HANDLE_SIGNATURE) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -58,13 +54,13 @@ SmmValidateHandle (
 **/\r
 PROTOCOL_ENTRY  *\r
 SmmFindProtocolEntry (\r
-  IN EFI_GUID   *Protocol,\r
-  IN BOOLEAN    Create\r
+  IN EFI_GUID  *Protocol,\r
+  IN BOOLEAN   Create\r
   )\r
 {\r
-  LIST_ENTRY          *Link;\r
-  PROTOCOL_ENTRY      *Item;\r
-  PROTOCOL_ENTRY      *ProtEntry;\r
+  LIST_ENTRY      *Link;\r
+  PROTOCOL_ENTRY  *Item;\r
+  PROTOCOL_ENTRY  *ProtEntry;\r
 \r
   //\r
   // Search the database for the matching GUID\r
@@ -73,9 +69,9 @@ SmmFindProtocolEntry (
   ProtEntry = NULL;\r
   for (Link = mProtocolDatabase.ForwardLink;\r
        Link != &mProtocolDatabase;\r
-       Link = Link->ForwardLink) {\r
-\r
-    Item = CR(Link, PROTOCOL_ENTRY, AllEntries, PROTOCOL_ENTRY_SIGNATURE);\r
+       Link = Link->ForwardLink)\r
+  {\r
+    Item = CR (Link, PROTOCOL_ENTRY, AllEntries, PROTOCOL_ENTRY_SIGNATURE);\r
     if (CompareGuid (&Item->ProtocolID, Protocol)) {\r
       //\r
       // This is the protocol entry\r
@@ -90,7 +86,7 @@ SmmFindProtocolEntry (
   // allocate a new entry\r
   //\r
   if ((ProtEntry == NULL) && Create) {\r
-    ProtEntry = AllocatePool (sizeof(PROTOCOL_ENTRY));\r
+    ProtEntry = AllocatePool (sizeof (PROTOCOL_ENTRY));\r
     if (ProtEntry != NULL) {\r
       //\r
       // Initialize new protocol entry structure\r
@@ -106,6 +102,7 @@ SmmFindProtocolEntry (
       InsertTailList (&mProtocolDatabase, &ProtEntry->AllEntries);\r
     }\r
   }\r
+\r
   return ProtEntry;\r
 }\r
 \r
@@ -142,17 +139,19 @@ SmmFindProtocolInterface (
     //\r
     // Look at each protocol interface for any matches\r
     //\r
-    for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link=Link->ForwardLink) {\r
+    for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link = Link->ForwardLink) {\r
       //\r
       // If this protocol interface matches, remove it\r
       //\r
-      Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);\r
-      if (Prot->Interface == Interface && Prot->Protocol == ProtEntry) {\r
+      Prot = CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);\r
+      if ((Prot->Interface == Interface) && (Prot->Protocol == ProtEntry)) {\r
         break;\r
       }\r
+\r
       Prot = NULL;\r
     }\r
   }\r
+\r
   return Prot;\r
 }\r
 \r
@@ -224,7 +223,7 @@ SmmInstallProtocolInterfaceNotify (
   // returns EFI_INVALID_PARAMETER if InterfaceType is invalid.\r
   // Also added check for invalid UserHandle and Protocol pointers.\r
   //\r
-  if (UserHandle == NULL || Protocol == NULL) {\r
+  if ((UserHandle == NULL) || (Protocol == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -235,10 +234,10 @@ SmmInstallProtocolInterfaceNotify (
   //\r
   // Print debug message\r
   //\r
-  DEBUG((DEBUG_LOAD | DEBUG_INFO, "SmmInstallProtocolInterface: %g %p\n", Protocol, Interface));\r
+  DEBUG ((DEBUG_LOAD | DEBUG_INFO, "SmmInstallProtocolInterface: %g %p\n", Protocol, Interface));\r
 \r
   Status = EFI_OUT_OF_RESOURCES;\r
-  Prot = NULL;\r
+  Prot   = NULL;\r
   Handle = NULL;\r
 \r
   if (*UserHandle != NULL) {\r
@@ -259,7 +258,7 @@ SmmInstallProtocolInterfaceNotify (
   //\r
   // Allocate a new protocol interface structure\r
   //\r
-  Prot = AllocateZeroPool (sizeof(PROTOCOL_INTERFACE));\r
+  Prot = AllocateZeroPool (sizeof (PROTOCOL_INTERFACE));\r
   if (Prot == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
@@ -270,7 +269,7 @@ SmmInstallProtocolInterfaceNotify (
   //\r
   Handle = (IHANDLE *)*UserHandle;\r
   if (Handle == NULL) {\r
-    Handle = AllocateZeroPool (sizeof(IHANDLE));\r
+    Handle = AllocateZeroPool (sizeof (IHANDLE));\r
     if (Handle == NULL) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
       goto Done;\r
@@ -287,11 +286,12 @@ SmmInstallProtocolInterfaceNotify (
     // in the system\r
     //\r
     InsertTailList (&gHandleList, &Handle->AllHandles);\r
-  }\r
-\r
-  Status = SmmValidateHandle (Handle);\r
-  if (EFI_ERROR (Status)) {\r
-    goto Done;\r
+  } else {\r
+    Status = SmmValidateHandle (Handle);\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((DEBUG_ERROR, "SmmInstallProtocolInterface: input handle at 0x%x is invalid\n", Handle));\r
+      goto Done;\r
+    }\r
   }\r
 \r
   //\r
@@ -303,8 +303,8 @@ SmmInstallProtocolInterfaceNotify (
   // Initialize the protocol interface structure\r
   //\r
   Prot->Signature = PROTOCOL_INTERFACE_SIGNATURE;\r
-  Prot->Handle = Handle;\r
-  Prot->Protocol = ProtEntry;\r
+  Prot->Handle    = Handle;\r
+  Prot->Protocol  = ProtEntry;\r
   Prot->Interface = Interface;\r
 \r
   //\r
@@ -325,6 +325,7 @@ SmmInstallProtocolInterfaceNotify (
   if (Notify) {\r
     SmmNotifyProtocol (Prot);\r
   }\r
+\r
   Status = EFI_SUCCESS;\r
 \r
 Done:\r
@@ -340,7 +341,10 @@ Done:
     if (Prot != NULL) {\r
       FreePool (Prot);\r
     }\r
+\r
+    DEBUG ((DEBUG_ERROR, "SmmInstallProtocolInterface: %g %p failed with %r\n", Protocol, Interface, Status));\r
   }\r
+\r
   return Status;\r
 }\r
 \r
@@ -421,6 +425,7 @@ SmmUninstallProtocolInterface (
     RemoveEntryList (&Handle->AllHandles);\r
     FreePool (Handle);\r
   }\r
+\r
   return Status;\r
 }\r
 \r
@@ -456,12 +461,13 @@ SmmGetProtocolInterface (
   // Look at each protocol interface for a match\r
   //\r
   for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link = Link->ForwardLink) {\r
-    Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);\r
+    Prot      = CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);\r
     ProtEntry = Prot->Protocol;\r
     if (CompareGuid (&ProtEntry->ProtocolID, Protocol)) {\r
       return Prot;\r
     }\r
   }\r
+\r
   return NULL;\r
 }\r
 \r