TTY: pty, switch to tty_alloc_driver
authorJiri Slaby <jslaby@suse.cz>
Wed, 8 Aug 2012 20:26:41 +0000 (22:26 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 13 Aug 2012 23:45:38 +0000 (16:45 -0700)
Switch to the new driver allocation interface, as this is one of the
special call-sites. Here, we need TTY_DRIVER_DYNAMIC_ALLOC to not
allocate tty_driver->ports, cdevs and potentially other structures
because we reserve too many lines in pty. Instead, it provides the
tty_port<->tty_struct link in tty->ops->install already.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/pty.c
include/linux/tty_driver.h

index d9ea9e2c9ec5883448707e1aae68678da1b2042b..f5a27c66ff607f438327fcd412d1ed386c305f2f 100644 (file)
@@ -444,11 +444,17 @@ static void __init legacy_pty_init(void)
        if (legacy_count <= 0)
                return;
 
-       pty_driver = alloc_tty_driver(legacy_count);
+       pty_driver = tty_alloc_driver(legacy_count,
+                       TTY_DRIVER_RESET_TERMIOS |
+                       TTY_DRIVER_REAL_RAW |
+                       TTY_DRIVER_DYNAMIC_ALLOC);
        if (!pty_driver)
                panic("Couldn't allocate pty driver");
 
-       pty_slave_driver = alloc_tty_driver(legacy_count);
+       pty_slave_driver = tty_alloc_driver(legacy_count,
+                       TTY_DRIVER_RESET_TERMIOS |
+                       TTY_DRIVER_REAL_RAW |
+                       TTY_DRIVER_DYNAMIC_ALLOC);
        if (!pty_slave_driver)
                panic("Couldn't allocate pty slave driver");
 
@@ -465,7 +471,6 @@ static void __init legacy_pty_init(void)
        pty_driver->init_termios.c_lflag = 0;
        pty_driver->init_termios.c_ispeed = 38400;
        pty_driver->init_termios.c_ospeed = 38400;
-       pty_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW;
        pty_driver->other = pty_slave_driver;
        tty_set_operations(pty_driver, &master_pty_ops_bsd);
 
@@ -479,8 +484,6 @@ static void __init legacy_pty_init(void)
        pty_slave_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
        pty_slave_driver->init_termios.c_ispeed = 38400;
        pty_slave_driver->init_termios.c_ospeed = 38400;
-       pty_slave_driver->flags = TTY_DRIVER_RESET_TERMIOS |
-                                       TTY_DRIVER_REAL_RAW;
        pty_slave_driver->other = pty_driver;
        tty_set_operations(pty_slave_driver, &slave_pty_ops_bsd);
 
@@ -673,10 +676,20 @@ static struct file_operations ptmx_fops;
 
 static void __init unix98_pty_init(void)
 {
-       ptm_driver = alloc_tty_driver(NR_UNIX98_PTY_MAX);
+       ptm_driver = tty_alloc_driver(NR_UNIX98_PTY_MAX,
+                       TTY_DRIVER_RESET_TERMIOS |
+                       TTY_DRIVER_REAL_RAW |
+                       TTY_DRIVER_DYNAMIC_DEV |
+                       TTY_DRIVER_DEVPTS_MEM |
+                       TTY_DRIVER_DYNAMIC_ALLOC);
        if (!ptm_driver)
                panic("Couldn't allocate Unix98 ptm driver");
-       pts_driver = alloc_tty_driver(NR_UNIX98_PTY_MAX);
+       pts_driver = tty_alloc_driver(NR_UNIX98_PTY_MAX,
+                       TTY_DRIVER_RESET_TERMIOS |
+                       TTY_DRIVER_REAL_RAW |
+                       TTY_DRIVER_DYNAMIC_DEV |
+                       TTY_DRIVER_DEVPTS_MEM |
+                       TTY_DRIVER_DYNAMIC_ALLOC);
        if (!pts_driver)
                panic("Couldn't allocate Unix98 pts driver");
 
@@ -693,8 +706,6 @@ static void __init unix98_pty_init(void)
        ptm_driver->init_termios.c_lflag = 0;
        ptm_driver->init_termios.c_ispeed = 38400;
        ptm_driver->init_termios.c_ospeed = 38400;
-       ptm_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW |
-               TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_DEVPTS_MEM;
        ptm_driver->other = pts_driver;
        tty_set_operations(ptm_driver, &ptm_unix98_ops);
 
@@ -708,8 +719,6 @@ static void __init unix98_pty_init(void)
        pts_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
        pts_driver->init_termios.c_ispeed = 38400;
        pts_driver->init_termios.c_ospeed = 38400;
-       pts_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW |
-               TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_DEVPTS_MEM;
        pts_driver->other = ptm_driver;
        tty_set_operations(pts_driver, &pty_unix98_ops);
 
index 3adc362f0bd2bd8d886a10ae794cc6ce77284d9b..1a85f003d646086115235fdfc0d15e6fc919f097 100644 (file)
@@ -391,6 +391,9 @@ static inline struct tty_driver *tty_driver_kref_get(struct tty_driver *d)
  *     the requested timeout to the caller instead of using a simple
  *     on/off interface.
  *
+ * TTY_DRIVER_DYNAMIC_ALLOC -- do not allocate structures which are
+ *     needed per line for this driver as it would waste memory.
+ *     The driver will take care.
  */
 #define TTY_DRIVER_INSTALLED           0x0001
 #define TTY_DRIVER_RESET_TERMIOS       0x0002
@@ -398,6 +401,7 @@ static inline struct tty_driver *tty_driver_kref_get(struct tty_driver *d)
 #define TTY_DRIVER_DYNAMIC_DEV         0x0008
 #define TTY_DRIVER_DEVPTS_MEM          0x0010
 #define TTY_DRIVER_HARDWARE_BREAK      0x0020
+#define TTY_DRIVER_DYNAMIC_ALLOC       0x0040
 
 /* tty driver types */
 #define TTY_DRIVER_TYPE_SYSTEM         0x0001