/*
  * Can we actually use the console at this time on this cpu?
  *
- * Console drivers may assume that per-cpu resources have
- * been allocated. So unless they're explicitly marked as
- * being able to cope (CON_ANYTIME) don't call them until
- * this CPU is officially up.
+ * Console drivers may assume that per-cpu resources have been allocated. So
+ * unless they're explicitly marked as being able to cope (CON_ANYTIME) don't
+ * call them until this CPU is officially up.
  */
 static inline int can_use_console(unsigned int cpu)
 {
  * console_lock held, and 'console_locked' set) if it
  * is successful, false otherwise.
  */
-static int console_trylock_for_printk(unsigned int cpu)
+static int console_trylock_for_printk(void)
 {
+       unsigned int cpu = smp_processor_id();
+
        if (!console_trylock())
                return 0;
        /*
                 */
                if (!oops_in_progress && !lockdep_recursing(current)) {
                        recursion_bug = 1;
-                       goto out_restore_irqs;
+                       local_irq_restore(flags);
+                       return 0;
                }
                zap_locks();
        }
 
        logbuf_cpu = UINT_MAX;
        raw_spin_unlock(&logbuf_lock);
+       lockdep_on();
+       local_irq_restore(flags);
+
+       /*
+        * Disable preemption to avoid being preempted while holding
+        * console_sem which would prevent anyone from printing to console
+        */
+       preempt_disable();
        /*
         * Try to acquire and then immediately release the console semaphore.
         * The release will print out buffers and wake up /dev/kmsg and syslog()
         * users.
         */
-       if (console_trylock_for_printk(this_cpu))
+       if (console_trylock_for_printk())
                console_unlock();
-
-       lockdep_on();
-out_restore_irqs:
-       local_irq_restore(flags);
+       preempt_enable();
 
        return printed_len;
 }