[media] ati_remote: Put timeouts at the accel array
authorMauro Carvalho Chehab <mchehab@osg.samsung.com>
Sat, 27 Feb 2016 10:51:12 +0000 (07:51 -0300)
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>
Tue, 1 Mar 2016 15:02:32 +0000 (12:02 -0300)
Instead of having the timeouts hardcoded, and getting only the
accel value from the array, put everything in the same place.

That simplifies the logic.

As a side effect, it also cleans several smatch errors:
include/linux/jiffies.h:359:41: error: strange non-value function or array
include/linux/jiffies.h:361:42: error: strange non-value function or array
(one per time_after/time_before line)

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
drivers/media/rc/ati_remote.c

index a35631891cc00589cbaa1ef8d6ef90026cbe19d3..3f61d77d41470d488cd50871d766a8d9b57d4e0a 100644 (file)
@@ -443,6 +443,21 @@ static int ati_remote_sendpacket(struct ati_remote *ati_remote, u16 cmd,
        return retval;
 }
 
+struct accel_times {
+       const char      value;
+       unsigned int    msecs;
+};
+
+static const struct accel_times accel[] = {
+       {  1,  125 },
+       {  2,  250 },
+       {  4,  500 },
+       {  6, 1000 },
+       {  9, 1500 },
+       { 13, 2000 },
+       { 20,    0 },
+};
+
 /*
  * ati_remote_compute_accel
  *
@@ -454,30 +469,22 @@ static int ati_remote_sendpacket(struct ati_remote *ati_remote, u16 cmd,
  */
 static int ati_remote_compute_accel(struct ati_remote *ati_remote)
 {
-       static const char accel[] = { 1, 2, 4, 6, 9, 13, 20 };
-       unsigned long now = jiffies;
-       int acc;
+       unsigned long now = jiffies, reset_time;
+       int i;
+
+       reset_time = msecs_to_jiffies(250);
 
-       if (time_after(now, ati_remote->old_jiffies + msecs_to_jiffies(250))) {
-               acc = 1;
+       if (time_after(now, ati_remote->old_jiffies + reset_time)) {
                ati_remote->acc_jiffies = now;
+               return 1;
        }
-       else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(125)))
-               acc = accel[0];
-       else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(250)))
-               acc = accel[1];
-       else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(500)))
-               acc = accel[2];
-       else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(1000)))
-               acc = accel[3];
-       else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(1500)))
-               acc = accel[4];
-       else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(2000)))
-               acc = accel[5];
-       else
-               acc = accel[6];
+       for (i = 0; i < ARRAY_SIZE(accel) - 1; i++) {
+               unsigned long timeout = msecs_to_jiffies(accel[i].msecs);
 
-       return acc;
+               if (time_before(now, ati_remote->acc_jiffies + timeout))
+                       return accel[i].value;
+       }
+       return accel[i].value;
 }
 
 /*