Skip to content

Commit e8688b9

Browse files
committed
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>
1 parent c1a3390 commit e8688b9

2 files changed

Lines changed: 15 additions & 23 deletions

File tree

drivers/input/mouse/cypress_ps2.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,14 @@ static const unsigned char cytp_resolution[] = {0x00, 0x01, 0x02, 0x03};
3838
static int cypress_ps2_sendbyte(struct psmouse *psmouse, int value)
3939
{
4040
struct ps2dev *ps2dev = &psmouse->ps2dev;
41+
int error;
4142

42-
if (ps2_sendbyte(ps2dev, value & 0xff, CYTP_CMD_TIMEOUT) < 0) {
43+
error = ps2_sendbyte(ps2dev, value & 0xff, CYTP_CMD_TIMEOUT);
44+
if (error) {
4345
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;
5049
}
5150

5251
#ifdef CYTP_DEBUG_VERBOSE
@@ -73,21 +72,20 @@ static int cypress_ps2_ext_cmd(struct psmouse *psmouse, unsigned short cmd,
7372
* to make the device return to the ready state.
7473
*/
7574
rc = cypress_ps2_sendbyte(psmouse, cmd & 0xff);
76-
if (rc == CYTP_PS2_RETRY) {
75+
if (rc == -EAGAIN) {
7776
rc = cypress_ps2_sendbyte(psmouse, 0x00);
78-
if (rc == CYTP_PS2_RETRY)
77+
if (rc == -EAGAIN)
7978
rc = cypress_ps2_sendbyte(psmouse, 0x0a);
8079
}
81-
if (rc == CYTP_PS2_ERROR)
82-
continue;
8380

84-
rc = cypress_ps2_sendbyte(psmouse, data);
85-
if (rc == CYTP_PS2_RETRY)
81+
if (!rc) {
8682
rc = cypress_ps2_sendbyte(psmouse, data);
87-
if (rc == CYTP_PS2_ERROR)
88-
continue;
89-
else
90-
break;
83+
if (rc == -EAGAIN)
84+
rc = cypress_ps2_sendbyte(psmouse, data);
85+
86+
if (!rc)
87+
break;
88+
}
9189
} while (--tries > 0);
9290

9391
ps2_end_command(ps2dev);

drivers/input/mouse/cypress_ps2.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@
7272
#define CYTP_DATA_TIMEOUT 30
7373

7474
#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-
8175

8276
#define CYTP_105001_WIDTH 97 /* Dell XPS 13 */
8377
#define CYTP_105001_HIGH 59

0 commit comments

Comments
 (0)