Revert "ARM: tegra: tegratab: dummy change"
[linux-2.6.git] / drivers / tty / pty.c
index 923a485..cf9a191 100644 (file)
@@ -1,6 +1,4 @@
 /*
- *  linux/drivers/char/pty.c
- *
  *  Copyright (C) 1991, 1992  Linus Torvalds
  *
  *  Added support for a Unix98-style ptmx device.
 #include <linux/major.h>
 #include <linux/mm.h>
 #include <linux/init.h>
-#include <linux/smp_lock.h>
-#include <linux/sysctl.h>
 #include <linux/device.h>
 #include <linux/uaccess.h>
 #include <linux/bitops.h>
 #include <linux/devpts_fs.h>
 #include <linux/slab.h>
 
-#include <asm/system.h>
 
 #ifdef CONFIG_UNIX98_PTYS
 static struct tty_driver *ptm_driver;
@@ -52,7 +47,6 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
        tty->packet = 0;
        if (!tty->link)
                return;
-       tty->link->packet = 0;
        set_bit(TTY_OTHER_CLOSED, &tty->link->flags);
        wake_up_interruptible(&tty->link->read_wait);
        wake_up_interruptible(&tty->link->write_wait);
@@ -296,8 +290,8 @@ static int pty_install(struct tty_driver *driver, struct tty_struct *tty)
                return -ENOMEM;
        if (!try_module_get(driver->other->owner)) {
                /* This cannot in fact currently happen */
-               free_tty_struct(o_tty);
-               return -ENOMEM;
+               retval = -ENOMEM;
+               goto err_free_tty;
        }
        initialize_tty_struct(o_tty, driver->other, idx);
 
@@ -305,13 +299,11 @@ static int pty_install(struct tty_driver *driver, struct tty_struct *tty)
           the easy way .. */
        retval = tty_init_termios(tty);
        if (retval)
-               goto free_mem_out;
+               goto err_deinit_tty;
 
        retval = tty_init_termios(o_tty);
-       if (retval) {
-               tty_free_termios(tty);
-               goto free_mem_out;
-       }
+       if (retval)
+               goto err_free_termios;
 
        /*
         * Everything allocated ... set up the o_tty structure.
@@ -328,13 +320,17 @@ static int pty_install(struct tty_driver *driver, struct tty_struct *tty)
        tty->count++;
        driver->ttys[idx] = tty;
        return 0;
-free_mem_out:
+err_free_termios:
+       tty_free_termios(tty);
+err_deinit_tty:
+       deinitialize_tty_struct(o_tty);
        module_put(o_tty->driver->owner);
+err_free_tty:
        free_tty_struct(o_tty);
-       return -ENOMEM;
+       return retval;
 }
 
-static int pty_bsd_ioctl(struct tty_struct *tty, struct file *file,
+static int pty_bsd_ioctl(struct tty_struct *tty,
                         unsigned int cmd, unsigned long arg)
 {
        switch (cmd) {
@@ -395,7 +391,6 @@ static void __init legacy_pty_init(void)
        if (!pty_slave_driver)
                panic("Couldn't allocate pty slave driver");
 
-       pty_driver->owner = THIS_MODULE;
        pty_driver->driver_name = "pty_master";
        pty_driver->name = "pty";
        pty_driver->major = PTY_MASTER_MAJOR;
@@ -413,7 +408,6 @@ static void __init legacy_pty_init(void)
        pty_driver->other = pty_slave_driver;
        tty_set_operations(pty_driver, &master_pty_ops_bsd);
 
-       pty_slave_driver->owner = THIS_MODULE;
        pty_slave_driver->driver_name = "pty_slave";
        pty_slave_driver->name = "ttyp";
        pty_slave_driver->major = PTY_SLAVE_MAJOR;
@@ -440,56 +434,10 @@ static inline void legacy_pty_init(void) { }
 
 /* Unix98 devices */
 #ifdef CONFIG_UNIX98_PTYS
-/*
- * sysctl support for setting limits on the number of Unix98 ptys allocated.
- * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
- */
-int pty_limit = NR_UNIX98_PTY_DEFAULT;
-static int pty_limit_min;
-static int pty_limit_max = NR_UNIX98_PTY_MAX;
-static int pty_count;
 
 static struct cdev ptmx_cdev;
 
-static struct ctl_table pty_table[] = {
-       {
-               .procname       = "max",
-               .maxlen         = sizeof(int),
-               .mode           = 0644,
-               .data           = &pty_limit,
-               .proc_handler   = proc_dointvec_minmax,
-               .extra1         = &pty_limit_min,
-               .extra2         = &pty_limit_max,
-       }, {
-               .procname       = "nr",
-               .maxlen         = sizeof(int),
-               .mode           = 0444,
-               .data           = &pty_count,
-               .proc_handler   = proc_dointvec,
-       }, 
-       {}
-};
-
-static struct ctl_table pty_kern_table[] = {
-       {
-               .procname       = "pty",
-               .mode           = 0555,
-               .child          = pty_table,
-       },
-       {}
-};
-
-static struct ctl_table pty_root_table[] = {
-       {
-               .procname       = "kernel",
-               .mode           = 0555,
-               .child          = pty_kern_table,
-       },
-       {}
-};
-
-
-static int pty_unix98_ioctl(struct tty_struct *tty, struct file *file,
+static int pty_unix98_ioctl(struct tty_struct *tty,
                            unsigned int cmd, unsigned long arg)
 {
        switch (cmd) {
@@ -516,10 +464,8 @@ static int pty_unix98_ioctl(struct tty_struct *tty, struct file *file,
 static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver,
                struct inode *ptm_inode, int idx)
 {
-       struct tty_struct *tty = devpts_get_tty(ptm_inode, idx);
-       if (tty)
-               tty = tty->link;
-       return tty;
+       /* Master must be open via /dev/ptmx */
+       return ERR_PTR(-EIO);
 }
 
 /**
@@ -543,6 +489,7 @@ static struct tty_struct *pts_unix98_lookup(struct tty_driver *driver,
 
 static void pty_unix98_shutdown(struct tty_struct *tty)
 {
+       tty_driver_remove_tty(tty->driver, tty);
        /* We have our own method as we don't use the tty index */
        kfree(tty->termios);
 }
@@ -560,20 +507,19 @@ static int pty_unix98_install(struct tty_driver *driver, struct tty_struct *tty)
                return -ENOMEM;
        if (!try_module_get(driver->other->owner)) {
                /* This cannot in fact currently happen */
-               free_tty_struct(o_tty);
-               return -ENOMEM;
+               goto err_free_tty;
        }
        initialize_tty_struct(o_tty, driver->other, idx);
 
        tty->termios = kzalloc(sizeof(struct ktermios[2]), GFP_KERNEL);
        if (tty->termios == NULL)
-               goto free_mem_out;
+               goto err_free_mem;
        *tty->termios = driver->init_termios;
        tty->termios_locked = tty->termios + 1;
 
        o_tty->termios = kzalloc(sizeof(struct ktermios[2]), GFP_KERNEL);
        if (o_tty->termios == NULL)
-               goto free_mem_out;
+               goto err_free_mem;
        *o_tty->termios = driver->other->init_termios;
        o_tty->termios_locked = o_tty->termios + 1;
 
@@ -590,25 +536,29 @@ static int pty_unix98_install(struct tty_driver *driver, struct tty_struct *tty)
         */
        tty_driver_kref_get(driver);
        tty->count++;
-       pty_count++;
        return 0;
-free_mem_out:
+err_free_mem:
+       deinitialize_tty_struct(o_tty);
        kfree(o_tty->termios);
+       kfree(tty->termios);
        module_put(o_tty->driver->owner);
+err_free_tty:
        free_tty_struct(o_tty);
-       kfree(tty->termios);
        return -ENOMEM;
 }
 
-static void pty_unix98_remove(struct tty_driver *driver, struct tty_struct *tty)
+static void ptm_unix98_remove(struct tty_driver *driver, struct tty_struct *tty)
+{
+}
+
+static void pts_unix98_remove(struct tty_driver *driver, struct tty_struct *tty)
 {
-       pty_count--;
 }
 
 static const struct tty_operations ptm_unix98_ops = {
        .lookup = ptm_unix98_lookup,
        .install = pty_unix98_install,
-       .remove = pty_unix98_remove,
+       .remove = ptm_unix98_remove,
        .open = pty_open,
        .close = pty_close,
        .write = pty_write,
@@ -625,7 +575,7 @@ static const struct tty_operations ptm_unix98_ops = {
 static const struct tty_operations pty_unix98_ops = {
        .lookup = pts_unix98_lookup,
        .install = pty_unix98_install,
-       .remove = pty_unix98_remove,
+       .remove = pts_unix98_remove,
        .open = pty_open,
        .close = pty_close,
        .write = pty_write,
@@ -657,16 +607,25 @@ static int ptmx_open(struct inode *inode, struct file *filp)
 
        nonseekable_open(inode, filp);
 
+       /* We refuse fsnotify events on ptmx, since it's a shared resource */
+       filp->f_mode |= FMODE_NONOTIFY;
+
+       retval = tty_alloc_file(filp);
+       if (retval)
+               return retval;
+
        /* find a device that is not in use. */
        tty_lock();
        index = devpts_new_index(inode);
        tty_unlock();
-       if (index < 0)
-               return index;
+       if (index < 0) {
+               retval = index;
+               goto err_file;
+       }
 
        mutex_lock(&tty_mutex);
        tty_lock();
-       tty = tty_init_dev(ptm_driver, index, 1);
+       tty = tty_init_dev(ptm_driver, index);
        mutex_unlock(&tty_mutex);
 
        if (IS_ERR(tty)) {
@@ -676,27 +635,27 @@ static int ptmx_open(struct inode *inode, struct file *filp)
 
        set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
 
-       retval = tty_add_file(tty, filp);
-       if (retval)
-               goto out;
+       tty_add_file(tty, filp);
 
        retval = devpts_pty_new(inode, tty->link);
        if (retval)
-               goto out1;
+               goto err_release;
 
        retval = ptm_driver->ops->open(tty, filp);
        if (retval)
-               goto out2;
-out1:
+               goto err_release;
+
        tty_unlock();
-       return retval;
-out2:
+       return 0;
+err_release:
        tty_unlock();
        tty_release(inode, filp);
        return retval;
 out:
        devpts_kill_index(inode, index);
        tty_unlock();
+err_file:
+       tty_free_file(filp);
        return retval;
 }
 
@@ -711,7 +670,6 @@ static void __init unix98_pty_init(void)
        if (!pts_driver)
                panic("Couldn't allocate Unix98 pts driver");
 
-       ptm_driver->owner = THIS_MODULE;
        ptm_driver->driver_name = "pty_master";
        ptm_driver->name = "ptm";
        ptm_driver->major = UNIX98_PTY_MASTER_MAJOR;
@@ -730,7 +688,6 @@ static void __init unix98_pty_init(void)
        ptm_driver->other = pts_driver;
        tty_set_operations(ptm_driver, &ptm_unix98_ops);
 
-       pts_driver->owner = THIS_MODULE;
        pts_driver->driver_name = "pty_slave";
        pts_driver->name = "pts";
        pts_driver->major = UNIX98_PTY_SLAVE_MAJOR;
@@ -751,8 +708,6 @@ static void __init unix98_pty_init(void)
        if (tty_register_driver(pts_driver))
                panic("Couldn't register Unix98 pts driver");
 
-       register_sysctl_table(pty_root_table);
-
        /* Now create the /dev/ptmx special device */
        tty_default_fops(&ptmx_fops);
        ptmx_fops.open = ptmx_open;