Skip to content

Commit c627589

Browse files
bentissJiri Kosina
authored andcommitted
Input - mt: Fix input_mt_get_slot_by_key
The case occurred recently with a touchscreen using twice a slot during a single EV_SYN event: E: 0.288415 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- E: 0.296207 0003 002f 0000 # EV_ABS / ABS_MT_SLOT 0 E: 0.296207 0003 0039 -001 # EV_ABS / ABS_MT_TRACKING_ID -1 E: 0.296207 0003 002f 0001 # EV_ABS / ABS_MT_SLOT 1 E: 0.296207 0003 0035 0908 # EV_ABS / ABS_MT_POSITION_X 908 E: 0.296207 0003 0036 1062 # EV_ABS / ABS_MT_POSITION_Y 1062 E: 0.296207 0003 002f 0000 # EV_ABS / ABS_MT_SLOT 0 E: 0.296207 0003 0039 8787 # EV_ABS / ABS_MT_TRACKING_ID 8787 E: 0.296207 0003 0035 1566 # EV_ABS / ABS_MT_POSITION_X 1566 E: 0.296207 0003 0036 0861 # EV_ABS / ABS_MT_POSITION_Y 861 E: 0.296207 0003 0000 0908 # EV_ABS / ABS_X 908 E: 0.296207 0003 0001 1062 # EV_ABS / ABS_Y 1062 E: 0.296207 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- This occurred because while having already slots 0 and 1 assigned, the touchscreen sent: 0.293377 Tip Switch: 0 | Contact Id: 0 | X: 539 | Y: 1960 | Contact Count: 3 0.294783 Tip Switch: 1 | Contact Id: 1 | X: 908 | Y: 1062 | Contact Count: 0 0.296187 Tip Switch: 1 | Contact Id: 2 | X: 1566 | Y: 861 | Contact Count: 0 Slot 0 is released correclty, but when we look for Contact ID 2, the slot 0 is then picked up again because it is marked as inactive (trackingID < 0). This is wrong, and we should not reuse a slot in the same frame. The test should also check for input_mt_is_used(). In addition, we need to initialize mt->frame to an other value than 0. With mt->frame being 0, all slots are tags as currently used, and so input_mt_get_slot_by_key() would return -1 for all requests. Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=88903 Signed-off-by: Benjamin Tissoires <[email protected]> Acked-by: Dmitry Torokhov <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent b9e9cd3 commit c627589

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

drivers/input/input-mt.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,13 @@ int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots,
8888
goto err_mem;
8989
}
9090

91-
/* Mark slots as 'unused' */
91+
/* Mark slots as 'inactive' */
9292
for (i = 0; i < num_slots; i++)
9393
input_mt_set_value(&mt->slots[i], ABS_MT_TRACKING_ID, -1);
9494

95+
/* Mark slots as 'unused' */
96+
mt->frame = 1;
97+
9598
dev->mt = mt;
9699
return 0;
97100
err_mem:
@@ -430,6 +433,8 @@ EXPORT_SYMBOL(input_mt_assign_slots);
430433
* set the key on the first unused slot and return.
431434
*
432435
* If no available slot can be found, -1 is returned.
436+
* Note that for this function to work properly, input_mt_sync_frame() has
437+
* to be called at each frame.
433438
*/
434439
int input_mt_get_slot_by_key(struct input_dev *dev, int key)
435440
{
@@ -444,7 +449,7 @@ int input_mt_get_slot_by_key(struct input_dev *dev, int key)
444449
return s - mt->slots;
445450

446451
for (s = mt->slots; s != mt->slots + mt->num_slots; s++)
447-
if (!input_mt_is_active(s)) {
452+
if (!input_mt_is_active(s) && !input_mt_is_used(mt, s)) {
448453
s->key = key;
449454
return s - mt->slots;
450455
}

0 commit comments

Comments
 (0)