]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Hand/Handle.c
MdeModulePkg/DxeCore: Fixed Interface returned by CoreOpenProtocol
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Hand / Handle.c
index 9b2809dbe5c3d054403a2c2bcc5bb26b71b55c13..3ed187b27949d3b5d79b28ad52050f73554e1e06 100644 (file)
@@ -1004,12 +1004,8 @@ CoreOpenProtocol (
   //\r
   // Check for invalid Interface\r
   //\r
-  if (Attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {\r
-    if (Interface == NULL) {\r
-      return EFI_INVALID_PARAMETER;\r
-    } else {\r
-      *Interface = NULL;\r
-    }\r
+  if ((Attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL) && (Interface == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   //\r
@@ -1076,12 +1072,6 @@ CoreOpenProtocol (
     goto Done;\r
   }\r
 \r
-  //\r
-  // This is the protocol interface entry for this protocol\r
-  //\r
-  if (Attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {\r
-    *Interface = Prot->Interface;\r
-  }\r
   Status = EFI_SUCCESS;\r
 \r
   ByDriver        = FALSE;\r
@@ -1177,8 +1167,28 @@ CoreOpenProtocol (
   }\r
 \r
 Done:\r
+\r
+  if (Attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {\r
+    //\r
+    // Keep Interface unmodified in case of any Error\r
+    // except EFI_ALREADY_STARTED and EFI_UNSUPPORTED.\r
+    //\r
+    if (!EFI_ERROR (Status) || Status == EFI_ALREADY_STARTED) {\r
+      //\r
+      // EFI_ALREADY_STARTED is not an error for bus driver.\r
+      // Return the corresponding protocol interface.\r
+      //\r
+      *Interface = Prot->Interface;\r
+    } else if (Status == EFI_UNSUPPORTED) {\r
+      //\r
+      // Return NULL Interface if Unsupported Protocol.\r
+      //\r
+      *Interface = NULL;\r
+    }\r
+  }\r
+\r
   //\r
-  // Done. Release the database lock are return\r
+  // Done. Release the database lock and return\r
   //\r
   CoreReleaseProtocolLock ();\r
   return Status;\r