]> git.hungrycats.org Git - linux/commitdiff
[PATCH] tty_driver refcounting
authorAlexander Viro <viro@www.linux.org.uk>
Wed, 11 Jun 2003 14:47:44 +0000 (07:47 -0700)
committerLinus Torvalds <torvalds@home.transmeta.com>
Wed, 11 Jun 2003 14:47:44 +0000 (07:47 -0700)
drivers/char/vt.c converted to dynamic allocation

drivers/char/tty_io.c
drivers/char/vt.c
drivers/char/vt_ioctl.c

index a1b068564c85cf82a0e9530059f0f5082eccf980..75acb3a8716739683ed01be1108f5ac75573112e 100644 (file)
@@ -1322,8 +1322,8 @@ retry_open:
 #ifdef CONFIG_VT
        if (IS_CONSOLE_DEV(device)) {
                extern int fg_console;
-               extern struct tty_driver console_driver;
-               driver = &console_driver;
+               extern struct tty_driver *console_driver;
+               driver = console_driver;
                index = fg_console;
                noctty = 1;
                goto got_driver;
index 5f274650bb0e56e0816ff88bf4ff44923a70eae4..ca5ad249ab8ce24c60a38a85d72add60457c8adb 100644 (file)
@@ -2185,12 +2185,12 @@ quit:
        clear_bit(0, &printing);
 }
 
-struct tty_driver console_driver;
+struct tty_driver *console_driver;
 
 static struct tty_driver *vt_console_device(struct console *c, int *index)
 {
        *index = c->index ? c->index-1 : fg_console;
-       return &console_driver;
+       return console_driver;
 }
 
 struct console vt_console_driver = {
@@ -2522,35 +2522,37 @@ static int __init con_init(void)
 }
 console_initcall(con_init);
 
+static struct tty_operations con_ops = {
+       .open = con_open,
+       .close = con_close,
+       .write = con_write,
+       .write_room = con_write_room,
+       .put_char = con_put_char,
+       .flush_chars = con_flush_chars,
+       .chars_in_buffer = con_chars_in_buffer,
+       .ioctl = vt_ioctl,
+       .stop = con_stop,
+       .start = con_start,
+       .throttle = con_throttle,
+       .unthrottle = con_unthrottle,
+};
+
 int __init vty_init(void)
 {
-       memset(&console_driver, 0, sizeof(struct tty_driver));
-       console_driver.magic = TTY_DRIVER_MAGIC;
-       console_driver.owner = THIS_MODULE;
-       console_driver.devfs_name = "vc/";
-       console_driver.name = "tty";
-       console_driver.name_base = 1;
-       console_driver.major = TTY_MAJOR;
-       console_driver.minor_start = 1;
-       console_driver.num = MAX_NR_CONSOLES;
-       console_driver.type = TTY_DRIVER_TYPE_CONSOLE;
-       console_driver.init_termios = tty_std_termios;
-       console_driver.flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_RESET_TERMIOS;
-
-       console_driver.open = con_open;
-       console_driver.close = con_close;
-       console_driver.write = con_write;
-       console_driver.write_room = con_write_room;
-       console_driver.put_char = con_put_char;
-       console_driver.flush_chars = con_flush_chars;
-       console_driver.chars_in_buffer = con_chars_in_buffer;
-       console_driver.ioctl = vt_ioctl;
-       console_driver.stop = con_stop;
-       console_driver.start = con_start;
-       console_driver.throttle = con_throttle;
-       console_driver.unthrottle = con_unthrottle;
-
-       if (tty_register_driver(&console_driver))
+       console_driver = alloc_tty_driver(MAX_NR_CONSOLES);
+       if (!console_driver)
+               panic("Couldn't allocate console driver\n");
+       console_driver->owner = THIS_MODULE;
+       console_driver->devfs_name = "vc/";
+       console_driver->name = "tty";
+       console_driver->name_base = 1;
+       console_driver->major = TTY_MAJOR;
+       console_driver->minor_start = 1;
+       console_driver->type = TTY_DRIVER_TYPE_CONSOLE;
+       console_driver->init_termios = tty_std_termios;
+       console_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_RESET_TERMIOS;
+       tty_set_operations(console_driver, &con_ops);
+       if (tty_register_driver(console_driver))
                panic("Couldn't register console driver\n");
 
        kbd_init();
index 681dc7e5cfb3b67310db7a50981cd07216eef580..6975e7542bae5abdb652e67ea510dc6f28032313 100644 (file)
@@ -34,9 +34,9 @@
 #include <linux/selection.h>
 
 char vt_dont_switch;
-extern struct tty_driver console_driver;
+extern struct tty_driver *console_driver;
 
-#define VT_IS_IN_USE(i)        (console_driver.ttys[i] && console_driver.ttys[i]->count)
+#define VT_IS_IN_USE(i)        (console_driver->ttys[i] && console_driver->ttys[i]->count)
 #define VT_BUSY(i)     (VT_IS_IN_USE(i) || i == fg_console || i == sel_cons)
 
 /*