From: "Kornel Dulęba" <korneld@google.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
"Kornel Dulęba" <korneld@google.com>
Subject: [PATCH 1/2] input: evdev: Always terminate SYN_DROPPED with SYN_REPORT
Date: Thu, 22 Oct 2026 13:39:12 +0000 [thread overview]
Message-ID: <20261022-evdev_syndropped_fix-v1-1-b5400740e1f7@google.com> (raw)
In-Reply-To: <20261022-evdev_syndropped_fix-v1-0-b5400740e1f7@google.com>
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@google.com>
---
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
next prev parent reply other threads:[~2026-10-22 13:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 13:39 [PATCH 0/2] input: evdev: Fix how SYN_DROPPED is generated Kornel Dulęba
2026-10-22 13:39 ` Kornel Dulęba [this message]
2026-10-22 13:39 ` [PATCH 2/2] input: evdev: Read clock directly in __evdev_queue_syn_dropped() Kornel Dulęba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261022-evdev_syndropped_fix-v1-1-b5400740e1f7@google.com \
--to=korneld@google.com \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®