[PATCH] uml: console locking commentary and code cleanup
[safe/jmp/linux-2.6] / arch / um / drivers / ssl.c
index a2bac42..fc22b9b 100644 (file)
@@ -3,7 +3,6 @@
  * Licensed under the GPL
  */
 
-#include "linux/config.h"
 #include "linux/fs.h"
 #include "linux/tty.h"
 #include "linux/tty_driver.h"
@@ -22,9 +21,8 @@
 #include "init.h"
 #include "irq_user.h"
 #include "mconsole_kern.h"
-#include "2_5compat.h"
 
-static int ssl_version = 1;
+static const int ssl_version = 1;
 
 /* Referenced only by tty_driver below - presumably it's locked correctly
  * by the tty driver.
@@ -34,12 +32,13 @@ static struct tty_driver *ssl_driver;
 
 #define NR_PORTS 64
 
-void ssl_announce(char *dev_name, int dev)
+static void ssl_announce(char *dev_name, int dev)
 {
        printk(KERN_INFO "Serial line %d assigned device '%s'\n", dev,
               dev_name);
 }
 
+/* Almost const, except that xterm_title may be changed in an initcall */
 static struct chan_opts opts = {
        .announce       = ssl_announce,
        .xterm_title    = "Serial Line #%d",
@@ -48,14 +47,15 @@ static struct chan_opts opts = {
        .in_kernel      = 1,
 };
 
-static int ssl_config(char *str);
+static int ssl_config(char *str, char **error_out);
 static int ssl_get_config(char *dev, char *str, int size, char **error_out);
-static int ssl_remove(char *str);
+static int ssl_remove(int n, char **error_out);
 
+
+/* Const, except for .mc.list */
 static struct line_driver driver = {
        .name                   = "UML serial line",
        .device_name            = "ttyS",
-       .devfs_name             = "tts/",
        .major                  = TTY_MAJOR,
        .minor_start            = 64,
        .type                   = TTY_DRIVER_TYPE_SERIAL,
@@ -64,46 +64,43 @@ static struct line_driver driver = {
        .read_irq_name          = "ssl",
        .write_irq              = SSL_WRITE_IRQ,
        .write_irq_name         = "ssl-write",
-       .symlink_from           = "serial",
-       .symlink_to             = "tts",
        .mc  = {
+               .list           = LIST_HEAD_INIT(driver.mc.list),
                .name           = "ssl",
                .config         = ssl_config,
                .get_config     = ssl_get_config,
+               .id             = line_id,
                .remove         = ssl_remove,
        },
 };
 
-/* The array is initialized by line_init, which is an initcall.  The 
- * individual elements are protected by individual semaphores.
+/* 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 struct lines lines = LINES_INIT(NR_PORTS);
-
-static int ssl_config(char *str)
+static int ssl_config(char *str, char **error_out)
 {
-       return(line_config(serial_lines, 
-                          sizeof(serial_lines)/sizeof(serial_lines[0]), str));
+       return line_config(serial_lines, ARRAY_SIZE(serial_lines), str, &opts,
+                          error_out);
 }
 
 static int ssl_get_config(char *dev, char *str, int size, char **error_out)
 {
-       return(line_get_config(dev, serial_lines, 
-                              sizeof(serial_lines)/sizeof(serial_lines[0]), 
-                              str, size, error_out));
+       return line_get_config(dev, serial_lines, ARRAY_SIZE(serial_lines), str,
+                              size, error_out);
 }
 
-static int ssl_remove(char *str)
+static int ssl_remove(int n, char **error_out)
 {
-       return(line_remove(serial_lines, 
-                          sizeof(serial_lines)/sizeof(serial_lines[0]), str));
+       return line_remove(serial_lines, ARRAY_SIZE(serial_lines), n,
+                          error_out);
 }
 
-int ssl_open(struct tty_struct *tty, struct file *filp)
+static int ssl_open(struct tty_struct *tty, struct file *filp)
 {
-       return line_open(serial_lines, tty, &opts);
+       return line_open(serial_lines, tty);
 }
 
 #if 0
@@ -112,16 +109,6 @@ static void ssl_flush_buffer(struct tty_struct *tty)
        return;
 }
 
-static void ssl_throttle(struct tty_struct * tty)
-{
-       printk(KERN_ERR "Someone should implement ssl_throttle\n");
-}
-
-static void ssl_unthrottle(struct tty_struct * tty)
-{
-       printk(KERN_ERR "Someone should implement ssl_unthrottle\n");
-}
-
 static void ssl_stop(struct tty_struct *tty)
 {
        printk(KERN_ERR "Someone should implement ssl_stop\n");
@@ -137,7 +124,7 @@ void ssl_hangup(struct tty_struct *tty)
 }
 #endif
 
-static struct tty_operations ssl_ops = {
+static const struct tty_operations ssl_ops = {
        .open                   = ssl_open,
        .close                  = line_close,
        .write                  = line_write,
@@ -148,9 +135,9 @@ static struct tty_operations ssl_ops = {
        .flush_chars            = line_flush_chars,
        .set_termios            = line_set_termios,
        .ioctl                  = line_ioctl,
+       .throttle               = line_throttle,
+       .unthrottle             = line_unthrottle,
 #if 0
-       .throttle               = ssl_throttle,
-       .unthrottle             = ssl_unthrottle,
        .stop                   = ssl_stop,
        .start                  = ssl_start,
        .hangup                 = ssl_hangup,
@@ -183,9 +170,10 @@ static int ssl_console_setup(struct console *co, char *options)
 {
        struct line *line = &serial_lines[co->index];
 
-       return console_open_chan(line,co,&opts);
+       return console_open_chan(line, co);
 }
 
+/* No locking for register_console call - relies on single-threaded initcalls */
 static struct console ssl_cons = {
        .name           = "ttyS",
        .write          = ssl_console_write,
@@ -195,16 +183,16 @@ static struct console ssl_cons = {
        .index          = -1,
 };
 
-int ssl_init(void)
+static int ssl_init(void)
 {
        char *new_title;
 
-       printk(KERN_INFO "Initializing software serial port version %d\n", 
+       printk(KERN_INFO "Initializing software serial port version %d\n",
               ssl_version);
-       ssl_driver = line_register_devfs(&lines, &driver, &ssl_ops,
-                                        serial_lines, ARRAY_SIZE(serial_lines));
+       ssl_driver = register_lines(&driver, &ssl_ops, serial_lines,
+                                   ARRAY_SIZE(serial_lines));
 
-       lines_init(serial_lines, sizeof(serial_lines)/sizeof(serial_lines[0]));
+       lines_init(serial_lines, ARRAY_SIZE(serial_lines), &opts);
 
        new_title = add_xterm_umid(opts.xterm_title);
        if (new_title != NULL)
@@ -212,7 +200,7 @@ int ssl_init(void)
 
        ssl_init_done = 1;
        register_console(&ssl_cons);
-       return(0);
+       return 0;
 }
 late_initcall(ssl_init);
 
@@ -220,16 +208,21 @@ static void ssl_exit(void)
 {
        if (!ssl_init_done)
                return;
-       close_lines(serial_lines,
-                   sizeof(serial_lines)/sizeof(serial_lines[0]));
+       close_lines(serial_lines, ARRAY_SIZE(serial_lines));
 }
 __uml_exitcall(ssl_exit);
 
 static int ssl_chan_setup(char *str)
 {
-       return(line_setup(serial_lines,
-                         sizeof(serial_lines)/sizeof(serial_lines[0]),
-                         str, 1));
+       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);
+
+       return 1;
 }
 
 __setup("ssl", ssl_chan_setup);