Skip to content

Commit b881d53

Browse files
committed
Input: evdev - do not queue SYN_DROPPED if queue is empty
There is no point in queueing EV_SYN/SYN_DROPPED on clock type change when there are no events in the client's queue and doing so confuses tests in libinput package, so let's not do that. Reported-and-tested-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 6c8afa8 commit b881d53

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

drivers/input/evdev.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,8 @@ static void __evdev_flush_queue(struct evdev_client *client, unsigned int type)
108108
client->head = head;
109109
}
110110

111-
/* queue SYN_DROPPED event and flush queue if flush parameter is true */
112-
static void evdev_queue_syn_dropped(struct evdev_client *client, bool flush)
111+
static void __evdev_queue_syn_dropped(struct evdev_client *client)
113112
{
114-
unsigned long flags;
115113
struct input_event ev;
116114
ktime_t time;
117115

@@ -126,11 +124,6 @@ static void evdev_queue_syn_dropped(struct evdev_client *client, bool flush)
126124
ev.code = SYN_DROPPED;
127125
ev.value = 0;
128126

129-
spin_lock_irqsave(&client->buffer_lock, flags);
130-
131-
if (flush)
132-
client->packet_head = client->head = client->tail;
133-
134127
client->buffer[client->head++] = ev;
135128
client->head &= client->bufsize - 1;
136129

@@ -139,12 +132,21 @@ static void evdev_queue_syn_dropped(struct evdev_client *client, bool flush)
139132
client->tail = (client->head - 1) & (client->bufsize - 1);
140133
client->packet_head = client->tail;
141134
}
135+
}
136+
137+
static void evdev_queue_syn_dropped(struct evdev_client *client)
138+
{
139+
unsigned long flags;
142140

141+
spin_lock_irqsave(&client->buffer_lock, flags);
142+
__evdev_queue_syn_dropped(client);
143143
spin_unlock_irqrestore(&client->buffer_lock, flags);
144144
}
145145

146146
static int evdev_set_clk_type(struct evdev_client *client, unsigned int clkid)
147147
{
148+
unsigned long flags;
149+
148150
if (client->clk_type == clkid)
149151
return 0;
150152

@@ -163,8 +165,18 @@ static int evdev_set_clk_type(struct evdev_client *client, unsigned int clkid)
163165
return -EINVAL;
164166
}
165167

166-
/* Flush pending events and queue SYN_DROPPED event.*/
167-
evdev_queue_syn_dropped(client, true);
168+
/*
169+
* Flush pending events and queue SYN_DROPPED event,
170+
* but only if the queue is not empty.
171+
*/
172+
spin_lock_irqsave(&client->buffer_lock, flags);
173+
174+
if (client->head != client->tail) {
175+
client->packet_head = client->head = client->tail;
176+
__evdev_queue_syn_dropped(client);
177+
}
178+
179+
spin_unlock_irqrestore(&client->buffer_lock, flags);
168180

169181
return 0;
170182
}
@@ -803,7 +815,7 @@ static int evdev_handle_get_val(struct evdev_client *client,
803815

804816
ret = bits_to_user(mem, maxbit, maxlen, p, compat);
805817
if (ret < 0)
806-
evdev_queue_syn_dropped(client, false);
818+
evdev_queue_syn_dropped(client);
807819

808820
kfree(mem);
809821

0 commit comments

Comments
 (0)