arrfab / rpms / shim

Forked from rpms/shim 4 years ago
Clone

Blame SOURCES/0033-MokManager-handle-the-error-status-from-ReadKeyStrok.patch

4210fa
From 22254e2633d58edd0176ccdfab9dd35171f89963 Mon Sep 17 00:00:00 2001
4210fa
From: Gary Ching-Pang Lin <glin@suse.com>
4210fa
Date: Tue, 3 Dec 2013 15:52:02 +0800
4210fa
Subject: [PATCH 33/74] MokManager: handle the error status from ReadKeyStroke
4210fa
4210fa
On some machines, even though the key event was signaled, ReadKeyStroke
4210fa
still got EFI_NOT_READY. This commit handles the error status to avoid
4210fa
console_get_keystroke from returning unexpected keys.
4210fa
4210fa
Signed-off-by: Gary Ching-Pang Lin <glin@suse.com>
4210fa
4210fa
Conflicts:
4210fa
	MokManager.c
4210fa
---
4210fa
 MokManager.c      | 17 +++++++++++++----
4210fa
 include/console.h |  4 ++--
4210fa
 lib/console.c     | 26 ++++++++++++++++++--------
4210fa
 3 files changed, 33 insertions(+), 14 deletions(-)
4210fa
4210fa
diff --git a/MokManager.c b/MokManager.c
4210fa
index 0ab308f..50cb9d7 100644
4210fa
--- a/MokManager.c
4210fa
+++ b/MokManager.c
4210fa
@@ -488,13 +488,19 @@ static EFI_STATUS list_keys (void *KeyList, UINTN KeyListSize, CHAR16 *title)
4210fa
 	return EFI_SUCCESS;
4210fa
 }
4210fa
 
4210fa
-static UINT8 get_line (UINT32 *length, CHAR16 *line, UINT32 line_max, UINT8 show)
4210fa
+static EFI_STATUS get_line (UINT32 *length, CHAR16 *line, UINT32 line_max, UINT8 show)
4210fa
 {
4210fa
 	EFI_INPUT_KEY key;
4210fa
+	EFI_STATUS status;
4210fa
 	unsigned int count = 0;
4210fa
 
4210fa
 	do {
4210fa
-		key = console_get_keystroke();
4210fa
+		status = console_get_keystroke(&key);
4210fa
+		if (EFI_ERROR (status)) {
4210fa
+			console_error(L"Failed to read the keystroke", status);
4210fa
+			*length = 0;
4210fa
+			return status;
4210fa
+		}
4210fa
 
4210fa
 		if ((count >= line_max &&
4210fa
 		     key.UnicodeChar != CHAR_BACKSPACE) ||
4210fa
@@ -525,7 +531,7 @@ static UINT8 get_line (UINT32 *length, CHAR16 *line, UINT32 line_max, UINT8 show
4210fa
 
4210fa
 	*length = count;
4210fa
 
4210fa
-	return 1;
4210fa
+	return EFI_SUCCESS;
4210fa
 }
4210fa
 
4210fa
 static EFI_STATUS compute_pw_hash (void *Data, UINTN DataSize, UINT8 *password,
4210fa
@@ -989,6 +995,7 @@ static INTN mok_deletion_prompt (void *MokDel, UINTN MokDelSize)
4210fa
 static CHAR16 get_password_charater (CHAR16 *prompt)
4210fa
 {
4210fa
 	SIMPLE_TEXT_OUTPUT_MODE SavedMode;
4210fa
+	EFI_STATUS status;
4210fa
 	CHAR16 *message[2];
4210fa
 	CHAR16 character;
4210fa
 	UINTN length;
4210fa
@@ -1003,7 +1010,9 @@ static CHAR16 get_password_charater (CHAR16 *prompt)
4210fa
 	message[1] = NULL;
4210fa
 	length = StrLen(message[0]);
4210fa
 	console_print_box_at(message, -1, -length-4, -5, length+4, 3, 0, 1);
4210fa
-	get_line(&pw_length, &character, 1, 0);
4210fa
+	status = get_line(&pw_length, &character, 1, 0);
4210fa
+	if (EFI_ERROR(status))
4210fa
+		character = 0;
4210fa
 
4210fa
 	console_restore_mode(&SavedMode);
4210fa
 
4210fa
diff --git a/include/console.h b/include/console.h
4210fa
index e6c2818..9c793ea 100644
4210fa
--- a/include/console.h
4210fa
+++ b/include/console.h
4210fa
@@ -1,8 +1,8 @@
4210fa
 #ifndef _SHIM_LIB_CONSOLE_H
4210fa
 #define _SHIM_LIB_CONSOLE_H 1
4210fa
 
4210fa
-EFI_INPUT_KEY
4210fa
-console_get_keystroke(void);
4210fa
+EFI_STATUS
4210fa
+console_get_keystroke(EFI_INPUT_KEY *key);
4210fa
 void
4210fa
 console_print_box_at(CHAR16 *str_arr[], int highlight, int start_col, int start_row, int size_cols, int size_rows, int offset, int lines);
4210fa
 void
4210fa
diff --git a/lib/console.c b/lib/console.c
4210fa
index 2fc8db3..41ed83a 100644
4210fa
--- a/lib/console.c
4210fa
+++ b/lib/console.c
4210fa
@@ -40,16 +40,18 @@ SetMem16(CHAR16 *dst, UINT32 n, CHAR16 c)
4210fa
 	}
4210fa
 }
4210fa
 
4210fa
-EFI_INPUT_KEY
4210fa
-console_get_keystroke(void)
4210fa
+EFI_STATUS
4210fa
+console_get_keystroke(EFI_INPUT_KEY *key)
4210fa
 {
4210fa
-	EFI_INPUT_KEY key;
4210fa
 	UINTN EventIndex;
4210fa
+	EFI_STATUS status;
4210fa
 
4210fa
-	uefi_call_wrapper(BS->WaitForEvent, 3, 1, &ST->ConIn->WaitForKey, &EventIndex);
4210fa
-	uefi_call_wrapper(ST->ConIn->ReadKeyStroke, 2, ST->ConIn, &key);
4210fa
+	do {
4210fa
+		uefi_call_wrapper(BS->WaitForEvent, 3, 1, &ST->ConIn->WaitForKey, &EventIndex);
4210fa
+		status = uefi_call_wrapper(ST->ConIn->ReadKeyStroke, 2, ST->ConIn, key);
4210fa
+	} while (status == EFI_NOT_READY);
4210fa
 
4210fa
-	return key;
4210fa
+	return status;
4210fa
 }
4210fa
 
4210fa
 void
4210fa
@@ -162,6 +164,8 @@ console_print_box(CHAR16 *str_arr[], int highlight)
4210fa
 {
4210fa
 	SIMPLE_TEXT_OUTPUT_MODE SavedConsoleMode;
4210fa
 	SIMPLE_TEXT_OUTPUT_INTERFACE *co = ST->ConOut;
4210fa
+	EFI_INPUT_KEY key;
4210fa
+
4210fa
 	CopyMem(&SavedConsoleMode, co->Mode, sizeof(SavedConsoleMode));
4210fa
 	uefi_call_wrapper(co->EnableCursor, 2, co, FALSE);
4210fa
 	uefi_call_wrapper(co->SetAttribute, 2, co, EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE);
4210fa
@@ -169,7 +173,7 @@ console_print_box(CHAR16 *str_arr[], int highlight)
4210fa
 	console_print_box_at(str_arr, highlight, 0, 0, -1, -1, 0,
4210fa
 			     count_lines(str_arr));
4210fa
 
4210fa
-	console_get_keystroke();
4210fa
+	console_get_keystroke(&key);
4210fa
 
4210fa
 	uefi_call_wrapper(co->EnableCursor, 2, co, SavedConsoleMode.CursorVisible);
4210fa
 
4210fa
@@ -184,6 +188,7 @@ console_select(CHAR16 *title[], CHAR16* selectors[], int start)
4210fa
 	SIMPLE_TEXT_OUTPUT_MODE SavedConsoleMode;
4210fa
 	SIMPLE_TEXT_OUTPUT_INTERFACE *co = ST->ConOut;
4210fa
 	EFI_INPUT_KEY k;
4210fa
+	EFI_STATUS status;
4210fa
 	int selector;
4210fa
 	int selector_lines = count_lines(selectors);
4210fa
 	int selector_max_cols = 0;
4210fa
@@ -237,7 +242,12 @@ console_select(CHAR16 *title[], CHAR16* selectors[], int start)
4210fa
 			     size_cols, size_rows, 0, lines);
4210fa
 
4210fa
 	do {
4210fa
-		k = console_get_keystroke();
4210fa
+		status = console_get_keystroke(&k);
4210fa
+		if (EFI_ERROR (status)) {
4210fa
+			Print(L"Failed to read the keystroke: %r", status);
4210fa
+			selector = -1;
4210fa
+			break;
4210fa
+		}
4210fa
 
4210fa
 		if (k.ScanCode == SCAN_ESC) {
4210fa
 			selector = -1;
4210fa
-- 
4210fa
1.9.3
4210fa