[PATCH 1/2] input: evdev: Always terminate SYN_DROPPED with SYN_REPORT
From: Kornel Dulęba
Date: Thu Oct 22 2026 - 09:45:49 EST
Per Documentation/input/event-codes.rst, on SYN_DROPPED:
"Client should ignore all events up to and including next SYN_REPORT
event and query the device (using EVIOCG* ioctls) to obtain its
current state."
Currently, __evdev_queue_syn_dropped() queues a standalone SYN_DROPPED
event without a terminating SYN_REPORT. This causes two issues:
1. The queued SYN_DROPPED event remains unreadable until the next
hardware event frame arrives and finishes with SYN_REPORT.
2. When the next hardware event frame arrives, SYN_DROPPED is prepended
to it in the same packet. Compliant userspace clients then discard
the entire hardware event frame up to its SYN_REPORT.
This was discovered on an Android system with a gpio-keys backed device:
1. gpio_keys_open() reports the initial state on open().
2. Android follows open() with EVIOCSCLOCKID.
3. This creates an unterminated SYN_DROPPED, causing the subsequent
event to be discarded by userspace.
Fix this by appending SYN_REPORT after SYN_DROPPED in
__evdev_queue_syn_dropped() and updating client->packet_head
accordingly.
Signed-off-by: Kornel Dulęba <korneld@xxxxxxxxxx>
---
drivers/input/evdev.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 8bfaaa45e0b9..c6da2601480f 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -147,6 +147,7 @@ static void __evdev_queue_syn_dropped(struct evdev_client *client)
{
ktime_t *ev_time = input_get_timestamp(client->evdev->handle.dev);
struct timespec64 ts = ktime_to_timespec64(ev_time[client->clk_type]);
+ unsigned int buf_mask = client->bufsize - 1;
struct input_event ev;
memset(&ev, 0, sizeof(ev));
@@ -156,13 +157,24 @@ static void __evdev_queue_syn_dropped(struct evdev_client *client)
ev.code = SYN_DROPPED;
client->buffer[client->head++] = ev;
- client->head &= client->bufsize - 1;
+ client->head &= buf_mask;
if (unlikely(client->head == client->tail)) {
/* drop queue but keep our SYN_DROPPED event */
- client->tail = (client->head - 1) & (client->bufsize - 1);
- client->packet_head = client->tail;
+ client->tail = (client->head - 1) & buf_mask;
}
+
+ ev.code = SYN_REPORT;
+
+ client->buffer[client->head++] = ev;
+ client->head &= buf_mask;
+
+ if (unlikely(client->head == client->tail)) {
+ /* drop queue but keep our SYN_DROPPED and SYN_REPORT events */
+ client->tail = (client->head - 2) & buf_mask;
+ }
+
+ client->packet_head = client->head;
}
static void evdev_queue_syn_dropped(struct evdev_client *client)
--
2.56.0.307.g5fe7bd680c-goog