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>
This commit is contained in:
levi.yun 2024-07-08 17:08:48 +01:00 committed by mergify[bot]
parent f9c373c838
commit 690f13fcb4
1 changed files with 16 additions and 7 deletions

View File

@ -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