Skip to content

Commit bf5f18d

Browse files
Aniroop Mathurdtor
authored andcommitted
Input: evdev - fix bug in checking duplicate clock change request
clk_type and clkid stores different predefined clock identification values so they cannot be compared for checking duplicate clock change request. Therefore, lets fix it to avoid unexpected results. Signed-off-by: Aniroop Mathur <a.mathur@samsung.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 5523662 commit bf5f18d

1 file changed

Lines changed: 19 additions & 17 deletions

File tree

‎drivers/input/evdev.c‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct evdev_client {
5656
struct fasync_struct *fasync;
5757
struct evdev *evdev;
5858
struct list_head node;
59-
int clk_type;
59+
unsigned int clk_type;
6060
bool revoked;
6161
unsigned long *evmasks[EV_CNT];
6262
unsigned int bufsize;
@@ -191,37 +191,39 @@ static void evdev_queue_syn_dropped(struct evdev_client *client)
191191
static int evdev_set_clk_type(struct evdev_client *client, unsigned int clkid)
192192
{
193193
unsigned long flags;
194-
195-
if (client->clk_type == clkid)
196-
return 0;
194+
unsigned int clk_type;
197195

198196
switch (clkid) {
199197

200198
case CLOCK_REALTIME:
201-
client->clk_type = EV_CLK_REAL;
199+
clk_type = EV_CLK_REAL;
202200
break;
203201
case CLOCK_MONOTONIC:
204-
client->clk_type = EV_CLK_MONO;
202+
clk_type = EV_CLK_MONO;
205203
break;
206204
case CLOCK_BOOTTIME:
207-
client->clk_type = EV_CLK_BOOT;
205+
clk_type = EV_CLK_BOOT;
208206
break;
209207
default:
210208
return -EINVAL;
211209
}
212210

213-
/*
214-
* Flush pending events and queue SYN_DROPPED event,
215-
* but only if the queue is not empty.
216-
*/
217-
spin_lock_irqsave(&client->buffer_lock, flags);
211+
if (client->clk_type != clk_type) {
212+
client->clk_type = clk_type;
218213

219-
if (client->head != client->tail) {
220-
client->packet_head = client->head = client->tail;
221-
__evdev_queue_syn_dropped(client);
222-
}
214+
/*
215+
* Flush pending events and queue SYN_DROPPED event,
216+
* but only if the queue is not empty.
217+
*/
218+
spin_lock_irqsave(&client->buffer_lock, flags);
223219

224-
spin_unlock_irqrestore(&client->buffer_lock, flags);
220+
if (client->head != client->tail) {
221+
client->packet_head = client->head = client->tail;
222+
__evdev_queue_syn_dropped(client);
223+
}
224+
225+
spin_unlock_irqrestore(&client->buffer_lock, flags);
226+
}
225227

226228
return 0;
227229
}

0 commit comments

Comments
 (0)