From d097611506bb7d854eb0d951a143b2438638d7be Mon Sep 17 00:00:00 2001 From: Furquan Shaikh Date: Mon, 23 Jul 2018 18:31:27 -0700 Subject: keyboard_8042: Clear buffer before adding command byte When the host attempts to read CTR, first clear the keyboard buffer to ensure that we do not have any stale data in it. If the buffered data is not cleared, host could end up interpreting the keypress data as CTR thus resulting in unwanted side-effects. Reason for putting in this change is because Linux kernel does not disable keyboard scanning when doing a reboot or poweroff. Now, if user keeps pressing keys while the system is booting up, kernel could end up reading key press data as CTR thus resulting in keyboard being disabled on boot-up. This change ensures that keyboard buffer is cleared before adding CTR data to it. BUG=b:111228655,b:199820376,b:172214981 BRANCH=poppy,eve,nami TEST=Verified on nautilus that keyboard is still functional after doing a reboot from AP shell and continuously pressing keys while system is booting up in normal mode. Change-Id: I5cbc904629fbd40b39625e37abccb80c83447d39 Signed-off-by: Furquan Shaikh Reviewed-on: https://chromium-review.googlesource.com/1147866 Commit-Ready: Furquan Shaikh Tested-by: Furquan Shaikh Reviewed-by: Randall Spangler (cherry picked from commit 30b2d3917316970182c8ada8ac6d95f8ae631838) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4159231 Commit-Queue: Daisuke Nojiri Reviewed-by: Patrick Georgi Tested-by: Daisuke Nojiri --- common/keyboard_8042.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/common/keyboard_8042.c b/common/keyboard_8042.c index 41729266f0..a99416aa04 100644 --- a/common/keyboard_8042.c +++ b/common/keyboard_8042.c @@ -667,6 +667,13 @@ static int handle_keyboard_command(uint8_t command, uint8_t *output) switch (command) { case I8042_READ_CMD_BYTE: + /* + * Ensure that the keyboard buffer is cleared before adding + * command byte to it. Since the host is asking for command + * byte, sending it buffered key press data can confuse the + * host and result in it taking incorrect action. + */ + keyboard_clear_buffer(); output[out_len++] = read_ctl_ram(0); break; -- cgit v1.2.1