Merge tag 'regmap-v3.15-nodev' of git://git.kernel.org/pub/scm/linux/kernel/git/broon...
[firefly-linux-kernel-4.4.55.git] / drivers / tty / hvc / hvc_console.c
index 50b46881b6ca7bf648fe2f8b73b6782b8c1306cd..94f9e3a38412f3071d63b4964925b375abec4283 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/list.h>
 #include <linux/module.h>
 #include <linux/major.h>
+#include <linux/atomic.h>
 #include <linux/sysrq.h>
 #include <linux/tty.h>
 #include <linux/tty_flip.h>
@@ -70,6 +71,9 @@ static struct task_struct *hvc_task;
 /* Picks up late kicks after list walk but before schedule() */
 static int hvc_kicked;
 
+/* hvc_init is triggered from hvc_alloc, i.e. only when actually used */
+static atomic_t hvc_needs_init __read_mostly = ATOMIC_INIT(-1);
+
 static int hvc_init(void);
 
 #ifdef CONFIG_MAGIC_SYSRQ
@@ -851,7 +855,7 @@ struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,
        int i;
 
        /* We wait until a driver actually comes along */
-       if (!hvc_driver) {
+       if (atomic_inc_not_zero(&hvc_needs_init)) {
                int err = hvc_init();
                if (err)
                        return ERR_PTR(err);