Skip to content

Commit df9fe0e

Browse files
committed
Input: libps2 - rework handling of command response
It is not entirely correct that libps2 sets PS2_FLAG_CMD1 after the device acknowledges each byte sent to the device by the host. Rework the code so that PS2_FLAG_CMD1 and PS2_FLAG_CMD are set only once, at the beginning of PS/2 command execution. Reviewed-by: Raul E Rangel <rrangel@chromium.org> Link: https://lore.kernel.org/r/20230511185252.386941-4-dmitry.torokhov@gmail.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent fc522f3 commit df9fe0e

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

drivers/input/serio/libps2.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,19 @@ int __ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command)
247247

248248
serio_pause_rx(ps2dev->serio);
249249

250+
/* Some mice do not ACK the "get ID" command, prepare to handle this. */
250251
ps2dev->flags = command == PS2_CMD_GETID ? PS2_FLAG_WAITID : 0;
251252
ps2dev->cmdcnt = receive;
252-
if (receive && param)
253-
for (i = 0; i < receive; i++)
254-
ps2dev->cmdbuf[(receive - 1) - i] = param[i];
253+
if (receive) {
254+
/* Indicate that we expect response to the command. */
255+
ps2dev->flags |= PS2_FLAG_CMD | PS2_FLAG_CMD1;
256+
if (param)
257+
for (i = 0; i < receive; i++)
258+
ps2dev->cmdbuf[(receive - 1) - i] = param[i];
259+
}
255260

256261
/*
257-
* Some devices (Synaptics) peform the reset before
262+
* Some devices (Synaptics) perform the reset before
258263
* ACKing the reset command, and so it can take a long
259264
* time before the ACK arrives.
260265
*/
@@ -434,11 +439,8 @@ bool ps2_handle_ack(struct ps2dev *ps2dev, u8 data)
434439
return true;
435440
}
436441

437-
if (!ps2dev->nak) {
442+
if (!ps2dev->nak)
438443
ps2dev->flags &= ~PS2_FLAG_NAK;
439-
if (ps2dev->cmdcnt)
440-
ps2dev->flags |= PS2_FLAG_CMD | PS2_FLAG_CMD1;
441-
}
442444

443445
ps2dev->flags &= ~PS2_FLAG_ACK;
444446
wake_up(&ps2dev->wait);

0 commit comments

Comments
 (0)