[edk2] [PATCH] MdeModulePkg/DxeCore: Fixed Interface returned by CoreOpenProtocol

Amit Kumar posted 1 patch 6 years, 10 months ago
Failed in applying to current master (apply log)
There is a newer version of this series
MdeModulePkg/Core/Dxe/Hand/Handle.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
[edk2] [PATCH] MdeModulePkg/DxeCore: Fixed Interface returned by CoreOpenProtocol
Posted by Amit Kumar 6 years, 10 months ago
Modified source code to update Interface as per spec.
1) In case of Protocol is un-supported, interface should be returned NULL.
2) In case of any error, interface should not be modified.
3) In case of Test Protocol, interface is optional.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Amit Kumar <amit.ak@samsung.com>
---
 MdeModulePkg/Core/Dxe/Hand/Handle.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/MdeModulePkg/Core/Dxe/Hand/Handle.c b/MdeModulePkg/Core/Dxe/Hand/Handle.c
index 1c25521..0afa86b 100644
--- a/MdeModulePkg/Core/Dxe/Hand/Handle.c
+++ b/MdeModulePkg/Core/Dxe/Hand/Handle.c
@@ -1004,13 +1004,8 @@ CoreOpenProtocol (
   //
   // Check for invalid Interface
   //
-  if (Attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
-    if (Interface == NULL) {
-      return EFI_INVALID_PARAMETER;
-    } else {
-      *Interface = NULL;
-    }
-  }
+  if ((Attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL) && (Interface == NULL))
+    return EFI_INVALID_PARAMETER;
 
   //
   // Check for invalid UserHandle
@@ -1073,15 +1068,11 @@ CoreOpenProtocol (
   Prot = CoreGetProtocolInterface (UserHandle, Protocol);
   if (Prot == NULL) {
     Status = EFI_UNSUPPORTED;
+    // Return NULL Interface if Unsupported Protocal
+    *Interface = NULL;
     goto Done;
   }
 
-  //
-  // This is the protocol interface entry for this protocol
-  //
-  if (Attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
-    *Interface = Prot->Interface;
-  }
   Status = EFI_SUCCESS;
 
   ByDriver        = FALSE;
@@ -1175,6 +1166,15 @@ CoreOpenProtocol (
   }
 
 Done:
+
+  //
+  // This is the protocol interface entry for this protocol.
+  // In case of any Error, Interface should not be updated as per spec.
+  //
+  if ((Attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL)
+      && (Status == EFI_SUCCESS)) {
+    *Interface = Prot->Interface;
+  }
   //
   // Done. Release the database lock are return
   //
-- 
1.9.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH] MdeModulePkg/DxeCore: Fixed Interface returned by CoreOpenProtocol
Posted by Gao, Liming 6 years, 10 months ago
Amit:
  I have minor comments. 
1) The first changed sentence should have {} for return EFI_INVALID_PARAMETER; to follow coding style. 
2) In the second change, the comment "Return NULL Interface if Unsupported Protocal" should be updated to protocol. 

Thanks
Liming
>-----Original Message-----
>From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
>Amit Kumar
>Sent: Tuesday, June 13, 2017 8:45 PM
>To: edk2-devel@lists.01.org
>Cc: Tian, Feng <feng.tian@intel.com>
>Subject: [edk2] [PATCH] MdeModulePkg/DxeCore: Fixed Interface returned
>by CoreOpenProtocol
>
>Modified source code to update Interface as per spec.
>1) In case of Protocol is un-supported, interface should be returned NULL.
>2) In case of any error, interface should not be modified.
>3) In case of Test Protocol, interface is optional.
>
>Contributed-under: TianoCore Contribution Agreement 1.0
>Signed-off-by: Amit Kumar <amit.ak@samsung.com>
>---
> MdeModulePkg/Core/Dxe/Hand/Handle.c | 26 +++++++++++++-------------
> 1 file changed, 13 insertions(+), 13 deletions(-)
>
>diff --git a/MdeModulePkg/Core/Dxe/Hand/Handle.c
>b/MdeModulePkg/Core/Dxe/Hand/Handle.c
>index 1c25521..0afa86b 100644
>--- a/MdeModulePkg/Core/Dxe/Hand/Handle.c
>+++ b/MdeModulePkg/Core/Dxe/Hand/Handle.c
>@@ -1004,13 +1004,8 @@ CoreOpenProtocol (
>   //
>   // Check for invalid Interface
>   //
>-  if (Attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
>-    if (Interface == NULL) {
>-      return EFI_INVALID_PARAMETER;
>-    } else {
>-      *Interface = NULL;
>-    }
>-  }
>+  if ((Attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL) && (Interface ==
>NULL))
>+    return EFI_INVALID_PARAMETER;
>
>   //
>   // Check for invalid UserHandle
>@@ -1073,15 +1068,11 @@ CoreOpenProtocol (
>   Prot = CoreGetProtocolInterface (UserHandle, Protocol);
>   if (Prot == NULL) {
>     Status = EFI_UNSUPPORTED;
>+    // Return NULL Interface if Unsupported Protocal
>+    *Interface = NULL;
>     goto Done;
>   }
>
>-  //
>-  // This is the protocol interface entry for this protocol
>-  //
>-  if (Attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
>-    *Interface = Prot->Interface;
>-  }
>   Status = EFI_SUCCESS;
>
>   ByDriver        = FALSE;
>@@ -1175,6 +1166,15 @@ CoreOpenProtocol (
>   }
>
> Done:
>+
>+  //
>+  // This is the protocol interface entry for this protocol.
>+  // In case of any Error, Interface should not be updated as per spec.
>+  //
>+  if ((Attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL)
>+      && (Status == EFI_SUCCESS)) {
>+    *Interface = Prot->Interface;
>+  }
>   //
>   // Done. Release the database lock are return
>   //
>--
>1.9.1
>
>_______________________________________________
>edk2-devel mailing list
>edk2-devel@lists.01.org
>https://lists.01.org/mailman/listinfo/edk2-devel
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel