Re: [PATCH 1/2] input: evdev: Always terminate SYN_DROPPED with SYN_REPORT

From: Kornel Dulęba

Date: Wed Nov 04 2026 - 05:00:12 EST


Hey,

On Tue, Nov 3, 2026 at 4:33 AM Dmitry Torokhov
<dmitry.torokhov@xxxxxxxxx> wrote:
>
> Hi Kornel,
>
> On Thu, Oct 22, 2026 at 01:39:12PM +0000, Kornel Dulęba wrote:
> > 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.
>
> I do not think that injecting synthetic SYN_REPORT is a good idea: we do
> not know at what point the clock change will arrive, it may arrive in a
> middle of transmitting a packet, and if we discard only half of such
> packet it will result in incomplete state being presented as complete
> one.

I don't think it's possible to flush the queue in the middle of
receiving a packet from the input framework. The only callback evdev
implements for parsing incoming packets is "events," which I believe
is called only for full, SYN_REPORT-terminated frames.

The only possible scenario for flushing a partial packet is when
userspace has read a part of a packet from the queue. In such a
situation, userspace will only see a single SYN_REPORT, though:

1. A full packet is written; userspace might have already read a part
of it. Let's say that the remaining part is: [foo, bar, SYN_REPORT].
2. An ioctl to change the clock is received. The queue is flushed and
replaced with: [SYN_DROPPED, SYN_REPORT].
3. Userspace now sees the part of the packet it managed to read, plus
the [SYN_DROPPED, SYN_REPORT].

> Compliant userspace should not only discard events until the next
> SYN_REPORT, but also query state via EVIOCG* to reconstruct full
> picture. Is it not happening?

Heh, good point. In my case, userspace called EVIOCGKEY(0) and
EVIOCGSW(0), but it didn't parse the results correctly. I actually
fixed that too, but for some reason, I didn't realize that it meant
the kernel patches are no longer needed.
I'm not sure if this patch is relevant anymore; sorry for the noise.
BTW, the second patch in this series is only relevant if this one is
applied. Because of that, I didn't respond to your comments there.