drivers/tty/hvc: don't free hvc_console_setup after init
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / tty / hvc / hvc_console.c
index eb255e807c0662250887beea86a2fb73081a6deb..f179033eaa3ec7c70819a4123815bd43296857bc 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
@@ -186,7 +190,7 @@ static struct tty_driver *hvc_console_device(struct console *c, int *index)
        return hvc_driver;
 }
 
-static int __init hvc_console_setup(struct console *co, char *options)
+static int hvc_console_setup(struct console *co, char *options)
 {      
        if (co->index < 0 || co->index >= MAX_NR_HVC_CONSOLES)
                return -ENODEV;
@@ -842,7 +846,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);