um: switch line.c tty drivers to dynamic device creation
[firefly-linux-kernel-4.4.55.git] / arch / um / drivers / ssl.c
index 9d8c20af6f80dac061641ce61de33975c176b892..6398a47d035bab6e6a920d2e9111153e6a4be6f3 100644 (file)
 
 static const int ssl_version = 1;
 
-/* Referenced only by tty_driver below - presumably it's locked correctly
- * by the tty driver.
- */
-
-static struct tty_driver *ssl_driver;
-
 #define NR_PORTS 64
 
 static void ssl_announce(char *dev_name, int dev)
@@ -71,8 +65,9 @@ static struct line_driver driver = {
 /* The array is initialized by line_init, at initcall time.  The
  * elements are locked individually as needed.
  */
-static struct line serial_lines[NR_PORTS] =
-       { [0 ... NR_PORTS - 1] = LINE_INIT(CONFIG_SSL_CHAN, &driver) };
+static char *conf[NR_PORTS];
+static char *def_conf = CONFIG_SSL_CHAN;
+static struct line serial_lines[NR_PORTS];
 
 static int ssl_config(char *str, char **error_out)
 {
@@ -163,7 +158,7 @@ static void ssl_console_write(struct console *c, const char *string,
 static struct tty_driver *ssl_console_device(struct console *c, int *index)
 {
        *index = c->index;
-       return ssl_driver;
+       return driver.driver;
 }
 
 static int ssl_console_setup(struct console *co, char *options)
@@ -186,11 +181,26 @@ static struct console ssl_cons = {
 static int ssl_init(void)
 {
        char *new_title;
+       int err;
+       int i;
 
        printk(KERN_INFO "Initializing software serial port version %d\n",
               ssl_version);
-       ssl_driver = register_lines(&driver, &ssl_ops, serial_lines,
+
+       for (i = 0; i < NR_PORTS; i++) {
+               char *s = conf[i];
+               if (!s)
+                       s = def_conf;
+               if (s && strcmp(s, "none") != 0)
+                       serial_lines[i].init_str = s;
+               spin_lock_init(&serial_lines[i].lock);
+               mutex_init(&serial_lines[i].count_lock);
+               serial_lines[i].driver = &driver;
+       }
+       err = register_lines(&driver, &ssl_ops, serial_lines,
                                    ARRAY_SIZE(serial_lines));
+       if (err)
+               return err;
 
        new_title = add_xterm_umid(opts.xterm_title);
        if (new_title != NULL)
@@ -214,14 +224,7 @@ __uml_exitcall(ssl_exit);
 
 static int ssl_chan_setup(char *str)
 {
-       char *error;
-       int ret;
-
-       ret = line_setup(serial_lines, ARRAY_SIZE(serial_lines), str, &error);
-       if(ret < 0)
-               printk(KERN_ERR "Failed to set up serial line with "
-                      "configuration string \"%s\" : %s\n", str, error);
-
+       line_setup(conf, NR_PORTS, &def_conf, str, "serial line");
        return 1;
 }