Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: i8042 - don't use negation to mark AUX data

Currently i8042_command() negates data coming from the AUX port
of keyboard controller; this is not a very reliable indicator.
Change i8042_command() to fail if response to I8042_CMD_AUX_LOOP
is not coming from AUX channel and get rid of negation.

Based on patch by Vojtech Pavlik.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>

+33 -29
+33 -29
drivers/input/serio/i8042.c
··· 100 100 static struct i8042_port i8042_ports[I8042_NUM_PORTS] = { 101 101 { 102 102 .disable = I8042_CTR_KBDDIS, 103 - .irqen = I8042_CTR_KBDINT, 103 + .irqen = I8042_CTR_KBDINT, 104 104 .mux = -1, 105 105 .name = "KBD", 106 106 }, ··· 191 191 static int i8042_command(unsigned char *param, int command) 192 192 { 193 193 unsigned long flags; 194 - int retval = 0, i = 0; 194 + int i, retval, auxerr = 0; 195 195 196 196 if (i8042_noloop && command == I8042_CMD_AUX_LOOP) 197 197 return -1; 198 198 199 199 spin_lock_irqsave(&i8042_lock, flags); 200 200 201 - retval = i8042_wait_write(); 202 - if (!retval) { 203 - dbg("%02x -> i8042 (command)", command & 0xff); 204 - i8042_write_command(command & 0xff); 201 + if ((retval = i8042_wait_write())) 202 + goto out; 203 + 204 + dbg("%02x -> i8042 (command)", command & 0xff); 205 + i8042_write_command(command & 0xff); 206 + 207 + for (i = 0; i < ((command >> 12) & 0xf); i++) { 208 + if ((retval = i8042_wait_write())) 209 + goto out; 210 + dbg("%02x -> i8042 (parameter)", param[i]); 211 + i8042_write_data(param[i]); 205 212 } 206 213 207 - if (!retval) 208 - for (i = 0; i < ((command >> 12) & 0xf); i++) { 209 - if ((retval = i8042_wait_write())) break; 210 - dbg("%02x -> i8042 (parameter)", param[i]); 211 - i8042_write_data(param[i]); 214 + for (i = 0; i < ((command >> 8) & 0xf); i++) { 215 + if ((retval = i8042_wait_read())) 216 + goto out; 217 + 218 + if (command == I8042_CMD_AUX_LOOP && 219 + !(i8042_read_status() & I8042_STR_AUXDATA)) { 220 + retval = auxerr = -1; 221 + goto out; 212 222 } 213 223 214 - if (!retval) 215 - for (i = 0; i < ((command >> 8) & 0xf); i++) { 216 - if ((retval = i8042_wait_read())) break; 217 - if (i8042_read_status() & I8042_STR_AUXDATA) 218 - param[i] = ~i8042_read_data(); 219 - else 220 - param[i] = i8042_read_data(); 221 - dbg("%02x <- i8042 (return)", param[i]); 222 - } 223 - 224 - spin_unlock_irqrestore(&i8042_lock, flags); 224 + param[i] = i8042_read_data(); 225 + dbg("%02x <- i8042 (return)", param[i]); 226 + } 225 227 226 228 if (retval) 227 - dbg(" -- i8042 (timeout)"); 229 + dbg(" -- i8042 (%s)", auxerr ? "auxerr" : "timeout"); 228 230 231 + out: 232 + spin_unlock_irqrestore(&i8042_lock, flags); 229 233 return retval; 230 234 } 231 235 ··· 511 507 */ 512 508 513 509 param = 0xf0; 514 - if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param != 0x0f) 510 + if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param != 0xf0) 515 511 return -1; 516 512 param = mode ? 0x56 : 0xf6; 517 - if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param != (mode ? 0xa9 : 0x09)) 513 + if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param != (mode ? 0x56 : 0xf6)) 518 514 return -1; 519 515 param = mode ? 0xa4 : 0xa5; 520 - if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param == (mode ? 0x5b : 0x5a)) 516 + if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param == (mode ? 0xa4 : 0xa5)) 521 517 return -1; 522 518 523 519 if (mux_version) 524 - *mux_version = ~param; 520 + *mux_version = param; 525 521 526 522 return 0; 527 523 } ··· 623 619 */ 624 620 625 621 param = 0x5a; 626 - if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param != 0xa5) { 622 + if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param != 0x5a) { 627 623 628 624 /* 629 625 * External connection test - filters out AT-soldered PS/2 i8042's ··· 634 630 */ 635 631 636 632 if (i8042_command(&param, I8042_CMD_AUX_TEST) 637 - || (param && param != 0xfa && param != 0xff)) 633 + || (param && param != 0xfa && param != 0xff)) 638 634 return -1; 639 635 } 640 636