sched/core: Fix a race between try_to_wake_up() and a woken up task
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / kernel / timer.c
index 15ffdb3f1948b9468c2c04527beb8190b0d79d45..20f45ea6f5a4a791c7bd0ba598d490192548f775 100644 (file)
@@ -149,9 +149,11 @@ static unsigned long round_jiffies_common(unsigned long j, int cpu,
        /* now that we have rounded, subtract the extra skew again */
        j -= cpu * 3;
 
-       if (j <= jiffies) /* rounding ate our timeout entirely; */
-               return original;
-       return j;
+       /*
+        * Make sure j is still in the future. Otherwise return the
+        * unmodified value.
+        */
+       return time_is_after_jiffies(j) ? j : original;
 }
 
 /**
@@ -820,7 +822,7 @@ unsigned long apply_slack(struct timer_list *timer, unsigned long expires)
 
        bit = find_last_bit(&mask, BITS_PER_LONG);
 
-       mask = (1 << bit) - 1;
+       mask = (1UL << bit) - 1;
 
        expires_limit = expires_limit & ~(mask);