Skip to content

Commit

Permalink
input: kbd_matrix: fix possible race condition
Browse files Browse the repository at this point in the history
Fix a possible race condition in the keyboard matrix library where a key
would get pressed between the last read and reenabling the (edge
sensitive) interrupt and the even would be lost.

The window for this to happen is very narrow and had to artificially add
a sleep to reproduce it.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
  • Loading branch information
fabiobaltieri authored and carlescufi committed Dec 18, 2023
1 parent ffbd039 commit ecce235
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions drivers/input/input_kbd_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,13 @@ static void input_kbd_matrix_polling_thread(void *arg1, void *unused2, void *unu
input_kbd_matrix_drive_column(dev, INPUT_KBD_MATRIX_COLUMN_DRIVE_ALL);
api->set_detect_mode(dev, true);

/* Check the rows again after enabling the interrupt to catch
* any potential press since the last read.
*/
if (api->read_row(dev) != 0) {
input_kbd_matrix_poll_start(dev);
}

k_sem_take(&data->poll_lock, K_FOREVER);
LOG_DBG("scan start");

Expand Down

0 comments on commit ecce235

Please sign in to comment.