Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[sfrench/cifs-2.6.git] / drivers / input / input-mt.c
index cb150a1dbaff9c9e788885747113e83e8f1dbe52..54fce56c80236808d5a6eb02fa6c8d17ebb76415 100644 (file)
@@ -88,10 +88,13 @@ int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots,
                        goto err_mem;
        }
 
-       /* Mark slots as 'unused' */
+       /* Mark slots as 'inactive' */
        for (i = 0; i < num_slots; i++)
                input_mt_set_value(&mt->slots[i], ABS_MT_TRACKING_ID, -1);
 
+       /* Mark slots as 'unused' */
+       mt->frame = 1;
+
        dev->mt = mt;
        return 0;
 err_mem:
@@ -365,27 +368,35 @@ static void input_mt_set_slots(struct input_mt *mt,
                               int *slots, int num_pos)
 {
        struct input_mt_slot *s;
-       int *w = mt->red, *p;
+       int *w = mt->red, j;
 
-       for (p = slots; p != slots + num_pos; p++)
-               *p = -1;
+       for (j = 0; j != num_pos; j++)
+               slots[j] = -1;
 
        for (s = mt->slots; s != mt->slots + mt->num_slots; s++) {
                if (!input_mt_is_active(s))
                        continue;
-               for (p = slots; p != slots + num_pos; p++)
-                       if (*w++ < 0)
-                               *p = s - mt->slots;
+
+               for (j = 0; j != num_pos; j++) {
+                       if (w[j] < 0) {
+                               slots[j] = s - mt->slots;
+                               break;
+                       }
+               }
+
+               w += num_pos;
        }
 
        for (s = mt->slots; s != mt->slots + mt->num_slots; s++) {
                if (input_mt_is_active(s))
                        continue;
-               for (p = slots; p != slots + num_pos; p++)
-                       if (*p < 0) {
-                               *p = s - mt->slots;
+
+               for (j = 0; j != num_pos; j++) {
+                       if (slots[j] < 0) {
+                               slots[j] = s - mt->slots;
                                break;
                        }
+               }
        }
 }
 
@@ -439,6 +450,8 @@ EXPORT_SYMBOL(input_mt_assign_slots);
  * set the key on the first unused slot and return.
  *
  * If no available slot can be found, -1 is returned.
+ * Note that for this function to work properly, input_mt_sync_frame() has
+ * to be called at each frame.
  */
 int input_mt_get_slot_by_key(struct input_dev *dev, int key)
 {
@@ -453,7 +466,7 @@ int input_mt_get_slot_by_key(struct input_dev *dev, int key)
                        return s - mt->slots;
 
        for (s = mt->slots; s != mt->slots + mt->num_slots; s++)
-               if (!input_mt_is_active(s)) {
+               if (!input_mt_is_active(s) && !input_mt_is_used(mt, s)) {
                        s->key = key;
                        return s - mt->slots;
                }