Skip to content

Commit 2f0d260

Browse files
o2genumdtor
authored andcommitted
Input: i8042 - i8042_flush fix for a full 8042 buffer
When 8042 internal data buffer is full, the driver erroneously decides that the controller is not present. i8042_flush returns the number of flushed bytes, which is in 0 - I8042_BUFFER_SIZE range inclusive. Therefore, i8042_flush has no way to indicate an error. Moreover i8042_controller_check takes initially full buffer (i8042_flush returned I8042_BUFFER_SIZE) as a sign of absence of the controller. Let's change i8042 to return success/error instead and make sure we do not return error prematurely. Signed-off-by: Andrey Moiseev <o2g.org.ru@gmail.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 049d75f commit 2f0d260

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

‎drivers/input/serio/i8042.c‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,21 +223,26 @@ static int i8042_flush(void)
223223
{
224224
unsigned long flags;
225225
unsigned char data, str;
226-
int i = 0;
226+
int count = 0;
227+
int retval = 0;
227228

228229
spin_lock_irqsave(&i8042_lock, flags);
229230

230-
while (((str = i8042_read_status()) & I8042_STR_OBF) && (i < I8042_BUFFER_SIZE)) {
231-
udelay(50);
232-
data = i8042_read_data();
233-
i++;
234-
dbg("%02x <- i8042 (flush, %s)\n",
235-
data, str & I8042_STR_AUXDATA ? "aux" : "kbd");
231+
while ((str = i8042_read_status()) & I8042_STR_OBF) {
232+
if (count++ < I8042_BUFFER_SIZE) {
233+
udelay(50);
234+
data = i8042_read_data();
235+
dbg("%02x <- i8042 (flush, %s)\n",
236+
data, str & I8042_STR_AUXDATA ? "aux" : "kbd");
237+
} else {
238+
retval = -EIO;
239+
break;
240+
}
236241
}
237242

238243
spin_unlock_irqrestore(&i8042_lock, flags);
239244

240-
return i;
245+
return retval;
241246
}
242247

243248
/*
@@ -849,7 +854,7 @@ static int __init i8042_check_aux(void)
849854

850855
static int i8042_controller_check(void)
851856
{
852-
if (i8042_flush() == I8042_BUFFER_SIZE) {
857+
if (i8042_flush()) {
853858
pr_err("No controller found\n");
854859
return -ENODEV;
855860
}

0 commit comments

Comments
 (0)