From b81362a82e40fac5c6debd8e0034feacb00d5e0a Mon Sep 17 00:00:00 2001 From: Hannah Williams Date: Sun, 27 May 2018 09:58:25 -0700 Subject: libpayload-x86: i8042: fix i8042_data_ready_ps2 and i8042_data_ready_aux keyboard_disconnect was called without keyboard_init being called and in this case keyboard_havechar returns true because i8042_data_ready_ps2 is dereferencing uninitialized variable ps2_fifo from within fifo_is_empty causing keyboard_disconnect to be stuck in this while loop. while (keyboard_havechar()) keyboard_getchar(); BUG=b:80299098 TEST=Check if the normal mode path in depthcharge is not causing a hang Change-Id: I944b4836005c887a2715717dff2df1b5a220818e Signed-off-by: Hannah Williams Reviewed-on: https://review.coreboot.org/26590 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin Reviewed-by: Furquan Shaikh --- payloads/libpayload/drivers/i8042/i8042.c | 6 ++++++ payloads/libpayload/drivers/i8042/keyboard.c | 3 +++ 2 files changed, 9 insertions(+) (limited to 'payloads/libpayload/drivers') diff --git a/payloads/libpayload/drivers/i8042/i8042.c b/payloads/libpayload/drivers/i8042/i8042.c index 1bf18556f2..b67944871f 100644 --- a/payloads/libpayload/drivers/i8042/i8042.c +++ b/payloads/libpayload/drivers/i8042/i8042.c @@ -87,6 +87,8 @@ static void fifo_push(struct fifo *fifo, u8 c) */ static int fifo_is_empty(struct fifo *fifo) { + if (!fifo) + return 1; return fifo->tx == fifo->rx; } @@ -332,6 +334,8 @@ static void i8042_data_poll(void) */ u8 i8042_data_ready_ps2(void) { + if (!initialized) + return 0; i8042_data_poll(); return !fifo_is_empty(ps2_fifo); } @@ -341,6 +345,8 @@ u8 i8042_data_ready_ps2(void) */ u8 i8042_data_ready_aux(void) { + if (!initialized) + return 0; i8042_data_poll(); return !fifo_is_empty(aux_fifo); } diff --git a/payloads/libpayload/drivers/i8042/keyboard.c b/payloads/libpayload/drivers/i8042/keyboard.c index a4f91b047a..a24d5a22cb 100644 --- a/payloads/libpayload/drivers/i8042/keyboard.c +++ b/payloads/libpayload/drivers/i8042/keyboard.c @@ -324,6 +324,9 @@ void keyboard_disconnect(void) if (inb(0x64) == 0xFF) return; + if (!i8042_has_ps2()) + return; + /* Empty keyboard buffer */ while (keyboard_havechar()) keyboard_getchar(); -- cgit v1.2.3