locking/static_keys: Add static_key_{en,dis}able() helpers
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / kernel / timer.c
index 20f45ea6f5a4a791c7bd0ba598d490192548f775..be22e45dc36f308c47d24c71d4344d900a259c27 100644 (file)
@@ -923,13 +923,26 @@ EXPORT_SYMBOL(add_timer);
  */
 void add_timer_on(struct timer_list *timer, int cpu)
 {
-       struct tvec_base *base = per_cpu(tvec_bases, cpu);
+       struct tvec_base *new_base = per_cpu(tvec_bases, cpu);
+       struct tvec_base *base;
        unsigned long flags;
 
        timer_stats_timer_set_start_info(timer);
        BUG_ON(timer_pending(timer) || !timer->function);
-       spin_lock_irqsave(&base->lock, flags);
-       timer_set_base(timer, base);
+
+       /*
+        * If @timer was on a different CPU, it should be migrated with the
+        * old base locked to prevent other operations proceeding with the
+        * wrong base locked.  See lock_timer_base().
+        */
+       base = lock_timer_base(timer, &flags);
+       if (base != new_base) {
+               timer_set_base(timer, NULL);
+               spin_unlock(&base->lock);
+               base = new_base;
+               spin_lock(&base->lock);
+               timer_set_base(timer, base);
+       }
        debug_activate(timer, timer->expires);
        internal_add_timer(base, timer);
        /*