From 690f13fcb4a7b74b30091c7067a18bb7971982d8 Mon Sep 17 00:00:00 2001 From: "levi.yun" Date: Mon, 8 Jul 2024 17:08:48 +0100 Subject: 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 --- ArmPlatformPkg/Drivers/PL061GpioDxe/PL061Gpio.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'ArmPlatformPkg') 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 -- cgit v1.2.3