summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlevi.yun <yeoreum.yun@arm.com>2024-07-08 17:08:48 +0100
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2024-07-16 15:19:27 +0000
commit690f13fcb4a7b74b30091c7067a18bb7971982d8 (patch)
treea31f710d81c77f165756288bf9f2c679742cbef0
parentf9c373c8388f819166e57365197bc423d56209a6 (diff)
downloadedk2-690f13fcb4a7b74b30091c7067a18bb7971982d8.tar.gz
edk2-690f13fcb4a7b74b30091c7067a18bb7971982d8.tar.bz2
edk2-690f13fcb4a7b74b30091c7067a18bb7971982d8.zip
ArmPlatformPkg/Driver/PL061Gpio: Error checking for pin on release build
ASSERT_EFI_ERROR would be removed in release build. This means it would trigger wrong behavior when invalid pin number given to Get(), Set() and GetMode(). Adding error check routine for invalid pin number and before check the pin number, check first other argument given to each function. Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
-rw-r--r--ArmPlatformPkg/Drivers/PL061GpioDxe/PL061Gpio.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/ArmPlatformPkg/Drivers/PL061GpioDxe/PL061Gpio.c b/ArmPlatformPkg/Drivers/PL061GpioDxe/PL061Gpio.c
index d87ab3d3de..fc062204c0 100644
--- a/ArmPlatformPkg/Drivers/PL061GpioDxe/PL061Gpio.c
+++ b/ArmPlatformPkg/Drivers/PL061GpioDxe/PL061Gpio.c
@@ -177,13 +177,16 @@ Get (
EFI_STATUS Status;
UINTN Index, Offset, RegisterBase;
- Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);
- ASSERT_EFI_ERROR (Status);
-
if (Value == NULL) {
return EFI_INVALID_PARAMETER;
}
+ Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);
+ if (EFI_ERROR (Status)) {
+ ASSERT_EFI_ERROR (Status);
+ return Status;
+ }
+
if (PL061GetPins (RegisterBase, GPIO_PIN_MASK (Offset)) != 0) {
*Value = 1;
} else {
@@ -223,7 +226,10 @@ Set (
UINTN Index, Offset, RegisterBase;
Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);
- ASSERT_EFI_ERROR (Status);
+ if (EFI_ERROR (Status)) {
+ ASSERT_EFI_ERROR (Status);
+ return Status;
+ }
switch (Mode) {
case GPIO_MODE_INPUT:
@@ -285,14 +291,17 @@ GetMode (
EFI_STATUS Status;
UINTN Index, Offset, RegisterBase;
- Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);
- ASSERT_EFI_ERROR (Status);
-
// Check for errors
if (Mode == NULL) {
return EFI_INVALID_PARAMETER;
}
+ Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);
+ if (EFI_ERROR (Status)) {
+ ASSERT_EFI_ERROR (Status);
+ return Status;
+ }
+
// Check if it is input or output
if (MmioRead8 (RegisterBase + PL061_GPIO_DIR_REG) & GPIO_PIN_MASK (Offset)) {
// Pin set to output