diff mbox

[U-Boot,v2] x86: Fix some bugs in the i8402 driver when no controller is present

Message ID 1321337892-12367-1-git-send-email-gabeblack@chromium.org
State Accepted
Commit 22e0f5a9ecab85f36a0fe69892d950c1ac212c91
Delegated to: Graeme Russ
Headers show

Commit Message

Gabe Black Nov. 15, 2011, 6:18 a.m. UTC
If no controller is present, the i8402 driver should return immediately and
not attempt to operate on the missing hardware.

In kbd_input_empty, the status register is checked every millisecond to see
whether the input buffer is empty, up to a timeout which is tracked by
decrimenting a counter each time the check is performed. The decrement is
performed with a postfix -- operator, and the value of the counter is
checked in place. That means that when the counter reaches zero and the
loop terminates, it will actually be decrimented one more time and become
-1. That value is returned as the return value of the function. That would
give the right answer if it wasn't for that extra decrement because a
timeout would indicate that the buffer never became empty.

This change fixes both of those bugs.

Signed-off-by: Gabe Black <gabeblack@chromium.org>
---
Changes in v2:
- Change summary tag style.
- Rebase onto checkpatch cleaned file.

 drivers/input/i8042.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

Comments

Graeme Russ Nov. 30, 2011, 11:04 a.m. UTC | #1
Hi Gabe,

On 15/11/11 17:18, Gabe Black wrote:
> If no controller is present, the i8402 driver should return immediately and
> not attempt to operate on the missing hardware.
> 
> In kbd_input_empty, the status register is checked every millisecond to see
> whether the input buffer is empty, up to a timeout which is tracked by
> decrimenting a counter each time the check is performed. The decrement is
> performed with a postfix -- operator, and the value of the counter is
> checked in place. That means that when the counter reaches zero and the
> loop terminates, it will actually be decrimented one more time and become
> -1. That value is returned as the return value of the function. That would
> give the right answer if it wasn't for that extra decrement because a
> timeout would indicate that the buffer never became empty.
> 
> This change fixes both of those bugs.
> 
> Signed-off-by: Gabe Black <gabeblack@chromium.org>
> ---
> Changes in v2:
> - Change summary tag style.
> - Rebase onto checkpatch cleaned file.
> 
>  drivers/input/i8042.c |   12 +++++++++++-
>  1 files changed, 11 insertions(+), 1 deletions(-)

Applied to u-boot-x86/master

Thanks,

Graeme
diff mbox

Patch

diff --git a/drivers/input/i8042.c b/drivers/input/i8042.c
index 83b1bf4..c3bc536 100644
--- a/drivers/input/i8042.c
+++ b/drivers/input/i8042.c
@@ -313,6 +313,13 @@  static unsigned char ext_key_map[] = {
 	0x00  /* map end */
 	};
 
+/******************************************************************************/
+
+static int kbd_controller_present(void)
+{
+	return in8(I8042_STATUS_REG) != 0xff;
+}
+
 /*******************************************************************************
  *
  * i8042_kbd_init - reset keyboard and init state flags
@@ -322,6 +329,9 @@  int i8042_kbd_init(void)
 	int keymap, try;
 	char *penv;
 
+	if (!kbd_controller_present())
+		return -1;
+
 #ifdef CONFIG_USE_CPCIDVI
 	penv = getenv("console");
 	if (penv != NULL) {
@@ -603,7 +613,7 @@  static int kbd_input_empty(void)
 	while ((in8(I8042_STATUS_REG) & 0x02) && kbdTimeout--)
 		udelay(1000);
 
-	return kbdTimeout;
+	return kbdTimeout != -1;
 }
 
 /******************************************************************************/