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

Configure Feed

Select the types of activity you want to include in your feed.

Input: cypress_ps2 - fix error handling when sending command fails

Stop layering error handling in cypress_ps2_sendbyte() and simply
pass on error code from ps2_sendbyte() and use it in the callers.

This fixes mishandling of error condition in
cypress_ps2_read_cmd_status() which expects errors to be negative.

Reported-by: Igor Artemiev <Igor.A.Artemiev@mcst.ru>
Link: https://lore.kernel.org/r/20240628224728.2180126-2-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+15 -23
+15 -17
drivers/input/mouse/cypress_ps2.c
··· 38 38 static int cypress_ps2_sendbyte(struct psmouse *psmouse, int value) 39 39 { 40 40 struct ps2dev *ps2dev = &psmouse->ps2dev; 41 + int error; 41 42 42 - if (ps2_sendbyte(ps2dev, value & 0xff, CYTP_CMD_TIMEOUT) < 0) { 43 + error = ps2_sendbyte(ps2dev, value & 0xff, CYTP_CMD_TIMEOUT); 44 + if (error) { 43 45 psmouse_dbg(psmouse, 44 - "sending command 0x%02x failed, resp 0x%02x\n", 45 - value & 0xff, ps2dev->nak); 46 - if (ps2dev->nak == CYTP_PS2_RETRY) 47 - return CYTP_PS2_RETRY; 48 - else 49 - return CYTP_PS2_ERROR; 46 + "sending command 0x%02x failed, resp 0x%02x, error %d\n", 47 + value & 0xff, ps2dev->nak, error); 48 + return error; 50 49 } 51 50 52 51 #ifdef CYTP_DEBUG_VERBOSE ··· 72 73 * to make the device return to the ready state. 73 74 */ 74 75 rc = cypress_ps2_sendbyte(psmouse, cmd & 0xff); 75 - if (rc == CYTP_PS2_RETRY) { 76 + if (rc == -EAGAIN) { 76 77 rc = cypress_ps2_sendbyte(psmouse, 0x00); 77 - if (rc == CYTP_PS2_RETRY) 78 + if (rc == -EAGAIN) 78 79 rc = cypress_ps2_sendbyte(psmouse, 0x0a); 79 80 } 80 - if (rc == CYTP_PS2_ERROR) 81 - continue; 82 81 83 - rc = cypress_ps2_sendbyte(psmouse, data); 84 - if (rc == CYTP_PS2_RETRY) 82 + if (!rc) { 85 83 rc = cypress_ps2_sendbyte(psmouse, data); 86 - if (rc == CYTP_PS2_ERROR) 87 - continue; 88 - else 89 - break; 84 + if (rc == -EAGAIN) 85 + rc = cypress_ps2_sendbyte(psmouse, data); 86 + 87 + if (!rc) 88 + break; 89 + } 90 90 } while (--tries > 0); 91 91 92 92 ps2_end_command(ps2dev);
-6
drivers/input/mouse/cypress_ps2.h
··· 72 72 #define CYTP_DATA_TIMEOUT 30 73 73 74 74 #define CYTP_EXT_CMD 0xe8 75 - #define CYTP_PS2_RETRY 0xfe 76 - #define CYTP_PS2_ERROR 0xfc 77 - 78 - #define CYTP_RESP_RETRY 0x01 79 - #define CYTP_RESP_ERROR 0xfe 80 - 81 75 82 76 #define CYTP_105001_WIDTH 97 /* Dell XPS 13 */ 83 77 #define CYTP_105001_HIGH 59