[edk2-devel] [edk2-platform][PATCH v1 2/3] Platforms/RaspberryPi: Fix DwUsbHostDxe ComponentName2 error checking

Samer El-Haj-Mahmoud posted 3 patches 5 years, 5 months ago
[edk2-devel] [edk2-platform][PATCH v1 2/3] Platforms/RaspberryPi: Fix DwUsbHostDxe ComponentName2 error checking
Posted by Samer El-Haj-Mahmoud 5 years, 5 months ago
Fix input param error checking for the DwUsbHostDxe ComponentName2
protocol.

This fixes https://github.com/pftf/RPi4/issues/86

Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Pete Batard <pete@akeo.ie>
Cc: Andrei Warkentin <awarkentin@vmware.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Signed-off-by: Samer El-Haj-Mahmoud <samer.el-haj-mahmoud@arm.com>
---
 Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.h  |  4 +++-
 Platform/RaspberryPi/Drivers/DwUsbHostDxe/ComponentName.c | 18 ++++++++++++++++++
 Platform/RaspberryPi/Drivers/DwUsbHostDxe/DriverBinding.c |  2 +-
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.h b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.h
index 106e5425355e..cf6c81b64ab5 100644
--- a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.h
+++ b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.h
@@ -1,5 +1,6 @@
 /** @file
  *
+ *  Copyright (c) 2020, ARM Limited. All rights reserved.
  *  Copyright (c) 2017-2018, Andrey Warkentin <andrey.warkentin@gmail.com>
  *  Copyright (c) 2015-2016, Linaro Limited. All rights reserved.
  *
@@ -121,8 +122,9 @@ typedef struct _DWUSB_OTGHC_DEV {
   UINT16                          LastMicroFrame;
 } DWUSB_OTGHC_DEV;
 
-extern EFI_COMPONENT_NAME_PROTOCOL gComponentName;
+extern EFI_COMPONENT_NAME_PROTOCOL  gComponentName;
 extern EFI_COMPONENT_NAME2_PROTOCOL gComponentName2;
+extern EFI_DRIVER_BINDING_PROTOCOL  mDriverBinding;
 
 EFI_STATUS
 CreateDwUsbHc (
diff --git a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/ComponentName.c b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/ComponentName.c
index 2f3c53323bf1..8639ab7d39c5 100644
--- a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/ComponentName.c
+++ b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/ComponentName.c
@@ -1,5 +1,6 @@
 /** @file
  *
+ *  Copyright (c) 2020, ARM Limited. All rights reserved.
  *  Copyright (c) 2018, Andrey Warkentin <andrey.warkentin@gmail.com>
  *
  *  SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -205,10 +206,27 @@ ComponentNameGetControllerName (
   OUT CHAR16                      **ControllerName
   )
 {
+  EFI_STATUS  Status;
+
+  //
+  // This is a device driver, so ChildHandle must be NULL.
+  //
   if (ChildHandle != NULL) {
     return EFI_UNSUPPORTED;
   }
 
+  //
+  // Make sure this driver is currently managing ControllHandle
+  //
+  Status = EfiTestManagedDevice (
+             ControllerHandle,
+             mDriverBinding.DriverBindingHandle,
+             &gEfiUsb2HcProtocolGuid
+             );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
   return LookupUnicodeString2 (
            Language,
            This->SupportedLanguages,
diff --git a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DriverBinding.c b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DriverBinding.c
index 7f78179d4c06..bada13a6cd7c 100644
--- a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DriverBinding.c
+++ b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DriverBinding.c
@@ -36,7 +36,7 @@ DriverStop (
   IN  EFI_HANDLE                  *ChildHandleBuffer
   );
 
-STATIC EFI_DRIVER_BINDING_PROTOCOL mDriverBinding = {
+EFI_DRIVER_BINDING_PROTOCOL mDriverBinding = {
   DriverSupported,
   DriverStart,
   DriverStop,
-- 
2.17.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#64300): https://edk2.groups.io/g/devel/message/64300
Mute This Topic: https://groups.io/mt/76213600/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [edk2-platform][PATCH v1 2/3] Platforms/RaspberryPi: Fix DwUsbHostDxe ComponentName2 error checking
Posted by Pete Batard 5 years, 5 months ago
Same typo as previous patch:

On 2020.08.15 21:26, Samer El-Haj-Mahmoud wrote:
> Fix input param error checking for the DwUsbHostDxe ComponentName2
> protocol.
> 
> This fixes https://github.com/pftf/RPi4/issues/86
> 
> Cc: Leif Lindholm <leif@nuviainc.com>
> Cc: Pete Batard <pete@akeo.ie>
> Cc: Andrei Warkentin <awarkentin@vmware.com>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Signed-off-by: Samer El-Haj-Mahmoud <samer.el-haj-mahmoud@arm.com>
> ---
>   Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.h  |  4 +++-
>   Platform/RaspberryPi/Drivers/DwUsbHostDxe/ComponentName.c | 18 ++++++++++++++++++
>   Platform/RaspberryPi/Drivers/DwUsbHostDxe/DriverBinding.c |  2 +-
>   3 files changed, 22 insertions(+), 2 deletions(-)
> 
> diff --git a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.h b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.h
> index 106e5425355e..cf6c81b64ab5 100644
> --- a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.h
> +++ b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.h
> @@ -1,5 +1,6 @@
>   /** @file
>    *
> + *  Copyright (c) 2020, ARM Limited. All rights reserved.
>    *  Copyright (c) 2017-2018, Andrey Warkentin <andrey.warkentin@gmail.com>
>    *  Copyright (c) 2015-2016, Linaro Limited. All rights reserved.
>    *
> @@ -121,8 +122,9 @@ typedef struct _DWUSB_OTGHC_DEV {
>     UINT16                          LastMicroFrame;
>   } DWUSB_OTGHC_DEV;
>   
> -extern EFI_COMPONENT_NAME_PROTOCOL gComponentName;
> +extern EFI_COMPONENT_NAME_PROTOCOL  gComponentName;
>   extern EFI_COMPONENT_NAME2_PROTOCOL gComponentName2;
> +extern EFI_DRIVER_BINDING_PROTOCOL  mDriverBinding;
>   
>   EFI_STATUS
>   CreateDwUsbHc (
> diff --git a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/ComponentName.c b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/ComponentName.c
> index 2f3c53323bf1..8639ab7d39c5 100644
> --- a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/ComponentName.c
> +++ b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/ComponentName.c
> @@ -1,5 +1,6 @@
>   /** @file
>    *
> + *  Copyright (c) 2020, ARM Limited. All rights reserved.
>    *  Copyright (c) 2018, Andrey Warkentin <andrey.warkentin@gmail.com>
>    *
>    *  SPDX-License-Identifier: BSD-2-Clause-Patent
> @@ -205,10 +206,27 @@ ComponentNameGetControllerName (
>     OUT CHAR16                      **ControllerName
>     )
>   {
> +  EFI_STATUS  Status;
> +
> +  //
> +  // This is a device driver, so ChildHandle must be NULL.
> +  //
>     if (ChildHandle != NULL) {
>       return EFI_UNSUPPORTED;
>     }
>   
> +  //
> +  // Make sure this driver is currently managing ControllHandle

Shouldn't it be 'ControllerHandle' rather than 'ControllHandle'?

> +  //
> +  Status = EfiTestManagedDevice (
> +             ControllerHandle,
> +             mDriverBinding.DriverBindingHandle,
> +             &gEfiUsb2HcProtocolGuid
> +             );
> +  if (EFI_ERROR (Status)) {
> +    return Status;
> +  }
> +
>     return LookupUnicodeString2 (
>              Language,
>              This->SupportedLanguages,
> diff --git a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DriverBinding.c b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DriverBinding.c
> index 7f78179d4c06..bada13a6cd7c 100644
> --- a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DriverBinding.c
> +++ b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DriverBinding.c
> @@ -36,7 +36,7 @@ DriverStop (
>     IN  EFI_HANDLE                  *ChildHandleBuffer
>     );
>   
> -STATIC EFI_DRIVER_BINDING_PROTOCOL mDriverBinding = {
> +EFI_DRIVER_BINDING_PROTOCOL mDriverBinding = {
>     DriverSupported,
>     DriverStart,
>     DriverStop,
> 

Reviewed-by: Pete Batard <pete@akeo.ie>

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#64316): https://edk2.groups.io/g/devel/message/64316
Mute This Topic: https://groups.io/mt/76213600/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-