Skip to content

Commit

Permalink
console: add a clear_screen() primitive
Browse files Browse the repository at this point in the history
Several places in e.g. MokManager and our console library use
ST->ConOut->ClearScreen directly, without checking for the existence of
a console output device.

This patch adds function to our console library to do that correctly,
instead of using the bug-prone ad hoc implementation everywhere.

Signed-off-by: Peter Jones <pjones@redhat.com>
  • Loading branch information
vathpela committed Sep 16, 2021
1 parent ad7f057 commit 971d4b9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
10 changes: 5 additions & 5 deletions MokManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ static EFI_STATUS mok_reset_prompt(BOOLEAN MokX)
EFI_STATUS efi_status;
CHAR16 *prompt[] = { NULL, NULL };

ST->ConOut->ClearScreen(ST->ConOut);
clear_screen();

if (MokX)
prompt[0] = L"Erase all stored keys in MokListX?";
Expand Down Expand Up @@ -1468,7 +1468,7 @@ static EFI_STATUS mok_sb_prompt(void *MokSB, UINTN MokSBSize)
return EFI_INVALID_PARAMETER;
}

ST->ConOut->ClearScreen(ST->ConOut);
clear_screen();

message[0] = L"Change Secure Boot state";
message[1] = NULL;
Expand Down Expand Up @@ -1583,7 +1583,7 @@ static EFI_STATUS mok_db_prompt(void *MokDB, UINTN MokDBSize)
return EFI_INVALID_PARAMETER;
}

ST->ConOut->ClearScreen(ST->ConOut);
clear_screen();

message[0] = L"Change DB state";
message[1] = NULL;
Expand Down Expand Up @@ -1691,7 +1691,7 @@ static EFI_STATUS mok_pw_prompt(void *MokPW, UINTN MokPWSize)
return EFI_INVALID_PARAMETER;
}

ST->ConOut->ClearScreen(ST->ConOut);
clear_screen();

SetMem(hash, PASSWORD_CRYPT_SIZE, 0);

Expand Down Expand Up @@ -2008,7 +2008,7 @@ static BOOLEAN verify_pw(BOOLEAN * protected)
if (attributes & EFI_VARIABLE_RUNTIME_ACCESS)
return TRUE;

ST->ConOut->ClearScreen(ST->ConOut);
clear_screen();

/* Draw the background */
console_save_and_set_mode(&SavedMode);
Expand Down
3 changes: 3 additions & 0 deletions include/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ void
console_reset(void);
void
console_mode_handle(void);
void
clear_screen(void);

#define NOSEL 0x7fffffff

typedef struct _EFI_CONSOLE_CONTROL_PROTOCOL EFI_CONSOLE_CONTROL_PROTOCOL;
Expand Down
13 changes: 12 additions & 1 deletion lib/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ console_mode_handle(VOID)
efi_status = co->SetMode(co, mode_set);
}

co->ClearScreen(co);
clear_screen();

if (EFI_ERROR(efi_status)) {
console_error(L"Console set mode fail", efi_status);
Expand Down Expand Up @@ -683,6 +683,17 @@ console_reset(void)
co->ClearScreen(co);
}

void
clear_screen(void)
{
SIMPLE_TEXT_OUTPUT_INTERFACE *co = ST->ConOut;

if (!co)
return;

co->ClearScreen(co);
}

VOID
setup_verbosity(VOID)
{
Expand Down

0 comments on commit 971d4b9

Please sign in to comment.