From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.1861.1608838745796341824 for ; Thu, 24 Dec 2020 11:39:06 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: samer.el-haj-mahmoud@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E579B1042; Thu, 24 Dec 2020 11:39:04 -0800 (PST) Received: from U203705.Arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9DC263F66E; Thu, 24 Dec 2020 11:39:04 -0800 (PST) From: "Samer El-Haj-Mahmoud" To: devel@edk2.groups.io Cc: Leif Lindholm , Ard Biesheuvel , Pete Batard , Andrei Warkentin Subject: [edk2-platform][PATCH v1 1/1] Platform/RaspberryPi : Fix Usb2Hc SCT issues Date: Thu, 24 Dec 2020 14:39:01 -0500 Message-Id: <20201224193901.29626-1-Samer.El-Haj-Mahmoud@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable REF: https://github.com/pftf/RPi4/issues/88 Fix SCT failures in the RPi USB2_HC_PROTOCOL by adding input parameter validation in Reset(), SetState(), GetState(), and SyncInterruptTransfer() Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Pete Batard Cc: Andrei Warkentin Signed-off-by: Samer El-Haj-Mahmoud --- Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.c | 44 ++++++++++++= ++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.c b/Pla= tform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.c index 4f6f60b1eb5f..0cd833c742cf 100644 --- a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.c +++ b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.c @@ -1,5 +1,6 @@ /** @file=0D *=0D +* Copyright (c) 2020, ARM Limited. All rights reserved.=0D * Copyright (c) 2017-2018, Andrey Warkentin = =0D * Copyright (c) 2015-2016, Linaro Limited. All rights reserved.=0D *=0D @@ -498,6 +499,21 @@ DwHcReset ( DWUSB_OTGHC_DEV *DwHc;=0D DwHc =3D DWHC_FROM_THIS (This);=0D =0D + switch (Attributes) {=0D + case EFI_USB_HC_RESET_GLOBAL:=0D + case EFI_USB_HC_RESET_HOST_CONTROLLER:=0D + break;=0D +=0D + case EFI_USB_HC_RESET_GLOBAL_WITH_DEBUG:=0D + case EFI_USB_HC_RESET_HOST_WITH_DEBUG:=0D + Status =3D EFI_UNSUPPORTED;=0D + goto Exit;=0D +=0D + default:=0D + Status =3D EFI_INVALID_PARAMETER;=0D + goto Exit;=0D + }=0D +=0D Status =3D gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &TimeoutEvt);=0D ASSERT_EFI_ERROR (Status);=0D if (EFI_ERROR (Status)) {=0D @@ -553,6 +569,10 @@ DwHcGetState ( =0D DwHc =3D DWHC_FROM_THIS (This);=0D =0D + if (State =3D=3D NULL) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D *State =3D DwHc->DwHcState;=0D =0D return EFI_SUCCESS;=0D @@ -565,13 +585,25 @@ DwHcSetState ( IN EFI_USB_HC_STATE State=0D )=0D {=0D - DWUSB_OTGHC_DEV *DwHc;=0D + DWUSB_OTGHC_DEV *DwHc;=0D + EFI_STATUS Status;=0D =0D DwHc =3D DWHC_FROM_THIS (This);=0D =0D - DwHc->DwHcState =3D State;=0D + switch (State) {=0D + case EfiUsbHcStateHalt:=0D + case EfiUsbHcStateOperational:=0D + case EfiUsbHcStateSuspend:=0D + DwHc->DwHcState =3D State;=0D + Status =3D EFI_SUCCESS;=0D + break;=0D =0D - return EFI_SUCCESS;=0D + default:=0D + Status =3D EFI_INVALID_PARAMETER;=0D + break;=0D + }=0D +=0D + return Status;=0D }=0D =0D EFI_STATUS=0D @@ -1173,6 +1205,12 @@ DwHcSyncInterruptTransfer ( return EFI_INVALID_PARAMETER;=0D }=0D =0D + if (((DeviceSpeed =3D=3D EFI_USB_SPEED_LOW) && (MaximumPacketLength !=3D= 8)) ||=0D + ((DeviceSpeed =3D=3D EFI_USB_SPEED_FULL) && (MaximumPacketLength > 6= 4)) ||=0D + ((DeviceSpeed =3D=3D EFI_USB_SPEED_HIGH) && (MaximumPacketLength > 3= 072))) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D Status =3D gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &TimeoutEvt);=0D if (EFI_ERROR (Status)) {=0D return Status;=0D --=20 2.25.1