Skip to content

Commit ecce235

Browse files
fabiobaltiericarlescufi
authored andcommittedDec 18, 2023
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>
1 parent ffbd039 commit ecce235

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed
 

‎drivers/input/input_kbd_matrix.c

+7
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,13 @@ static void input_kbd_matrix_polling_thread(void *arg1, void *unused2, void *unu
291291
input_kbd_matrix_drive_column(dev, INPUT_KBD_MATRIX_COLUMN_DRIVE_ALL);
292292
api->set_detect_mode(dev, true);
293293

294+
/* Check the rows again after enabling the interrupt to catch
295+
* any potential press since the last read.
296+
*/
297+
if (api->read_row(dev) != 0) {
298+
input_kbd_matrix_poll_start(dev);
299+
}
300+
294301
k_sem_take(&data->poll_lock, K_FOREVER);
295302
LOG_DBG("scan start");
296303

0 commit comments

Comments
 (0)
Please sign in to comment.