Skip to content

Commit 7d674f9

Browse files
committed
Input: libps2 - fix aborting PS/2 commands
When aborting PS/2 command the kernel should [re]set all flags before waking up waiters, otherwise waiting thread may read obsolete values of flags. Reported-by: Raul Rangel <[email protected]> Reviewed-by: Raul E Rangel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 1db0fd2 commit 7d674f9

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

drivers/input/serio/libps2.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -478,15 +478,22 @@ bool ps2_handle_response(struct ps2dev *ps2dev, u8 data)
478478
}
479479
EXPORT_SYMBOL(ps2_handle_response);
480480

481+
/*
482+
* Clears state of PS/2 device after communication error by resetting majority
483+
* of flags and waking up waiters, if any.
484+
*/
481485
void ps2_cmd_aborted(struct ps2dev *ps2dev)
482486
{
483-
if (ps2dev->flags & PS2_FLAG_ACK)
487+
unsigned long old_flags = ps2dev->flags;
488+
489+
/* reset all flags except last nak */
490+
ps2dev->flags &= PS2_FLAG_NAK;
491+
492+
if (old_flags & PS2_FLAG_ACK)
484493
ps2dev->nak = 1;
485494

486-
if (ps2dev->flags & (PS2_FLAG_ACK | PS2_FLAG_CMD))
495+
if (old_flags & (PS2_FLAG_ACK | PS2_FLAG_CMD))
487496
wake_up(&ps2dev->wait);
488497

489-
/* reset all flags except last nack */
490-
ps2dev->flags &= PS2_FLAG_NAK;
491498
}
492499
EXPORT_SYMBOL(ps2_cmd_aborted);

0 commit comments

Comments
 (0)