input: kbd_matrix: fix possible race condition

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>
This commit is contained in:
Fabio Baltieri 2023-12-15 16:19:57 +00:00 committed by Carles Cufí
commit ecce235322

View file

@ -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");