[PATCH 2/2] input: evdev: Read clock directly in __evdev_queue_syn_dropped()

From: Kornel Dulęba

Date: Thu Oct 22 2026 - 09:45:20 EST


Currently, __evdev_queue_syn_dropped() calls input_get_timestamp() on
the underlying input_dev to obtain the event timestamp. If no timestamp
is set, input_get_timestamp() caches the current time and returns it;
otherwise, it returns the cached value.

There are two problems with this approach:

1. Locking. The timestamp is obtained in the same way in
evdev_events(), which is called with dev->event_lock held. Calls to
__evdev_queue_syn_dropped() are only serialized with
client->buffer_lock. This makes both accesses likely racy.
2. If no timestamp is cached yet, the subsequent hardware event
generated after __evdev_queue_syn_dropped() is called will receive
the stale cached timestamp.

Fix this by reading the current time directly based on the value of
client->clk_type. Open-coding this is not the prettiest solution, but I
couldn't figure out anything better.

I initially thought about fixing this by resetting the input timestamp
in this function instead, similarly to how INPUT_FLUSH handles it.
However, I decided against it, as that would require non-trivial
locking changes.

Signed-off-by: Kornel Dulęba <korneld@xxxxxxxxxx>
---
drivers/input/evdev.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index c6da2601480f..da7396c19188 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -145,11 +145,18 @@ static void __evdev_flush_queue(struct evdev_client *client, unsigned int type)

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;
+ ktime_t time;
+ struct timespec64 ts;
+
+ time = client->clk_type == INPUT_CLK_REAL ?
+ ktime_get_real() :
+ client->clk_type == INPUT_CLK_MONO ?
+ ktime_get() :
+ ktime_get_boottime();

+ ts = ktime_to_timespec64(time);
memset(&ev, 0, sizeof(ev));
ev.input_event_sec = ts.tv_sec;
ev.input_event_usec = ts.tv_nsec / NSEC_PER_USEC;

--
2.56.0.307.g5fe7bd680c-goog