diff options
Diffstat (limited to 'drivers/tty/tty_io.c')
-rw-r--r-- | drivers/tty/tty_io.c | 67 |
1 files changed, 27 insertions, 40 deletions
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 9e930c009bf2..b425c79675ad 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c | |||
@@ -185,7 +185,6 @@ void free_tty_struct(struct tty_struct *tty) | |||
185 | put_device(tty->dev); | 185 | put_device(tty->dev); |
186 | kfree(tty->write_buf); | 186 | kfree(tty->write_buf); |
187 | tty_buffer_free_all(tty); | 187 | tty_buffer_free_all(tty); |
188 | tty->magic = 0xDEADDEAD; | ||
189 | kfree(tty); | 188 | kfree(tty); |
190 | } | 189 | } |
191 | 190 | ||
@@ -574,7 +573,7 @@ void __tty_hangup(struct tty_struct *tty) | |||
574 | } | 573 | } |
575 | spin_unlock(&redirect_lock); | 574 | spin_unlock(&redirect_lock); |
576 | 575 | ||
577 | tty_lock(tty); | 576 | tty_lock(); |
578 | 577 | ||
579 | /* some functions below drop BTM, so we need this bit */ | 578 | /* some functions below drop BTM, so we need this bit */ |
580 | set_bit(TTY_HUPPING, &tty->flags); | 579 | set_bit(TTY_HUPPING, &tty->flags); |
@@ -667,7 +666,7 @@ void __tty_hangup(struct tty_struct *tty) | |||
667 | clear_bit(TTY_HUPPING, &tty->flags); | 666 | clear_bit(TTY_HUPPING, &tty->flags); |
668 | tty_ldisc_enable(tty); | 667 | tty_ldisc_enable(tty); |
669 | 668 | ||
670 | tty_unlock(tty); | 669 | tty_unlock(); |
671 | 670 | ||
672 | if (f) | 671 | if (f) |
673 | fput(f); | 672 | fput(f); |
@@ -1104,12 +1103,12 @@ void tty_write_message(struct tty_struct *tty, char *msg) | |||
1104 | { | 1103 | { |
1105 | if (tty) { | 1104 | if (tty) { |
1106 | mutex_lock(&tty->atomic_write_lock); | 1105 | mutex_lock(&tty->atomic_write_lock); |
1107 | tty_lock(tty); | 1106 | tty_lock(); |
1108 | if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags)) { | 1107 | if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags)) { |
1109 | tty_unlock(tty); | 1108 | tty_unlock(); |
1110 | tty->ops->write(tty, msg, strlen(msg)); | 1109 | tty->ops->write(tty, msg, strlen(msg)); |
1111 | } else | 1110 | } else |
1112 | tty_unlock(tty); | 1111 | tty_unlock(); |
1113 | tty_write_unlock(tty); | 1112 | tty_write_unlock(tty); |
1114 | } | 1113 | } |
1115 | return; | 1114 | return; |
@@ -1404,7 +1403,6 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx) | |||
1404 | } | 1403 | } |
1405 | initialize_tty_struct(tty, driver, idx); | 1404 | initialize_tty_struct(tty, driver, idx); |
1406 | 1405 | ||
1407 | tty_lock(tty); | ||
1408 | retval = tty_driver_install_tty(driver, tty); | 1406 | retval = tty_driver_install_tty(driver, tty); |
1409 | if (retval < 0) | 1407 | if (retval < 0) |
1410 | goto err_deinit_tty; | 1408 | goto err_deinit_tty; |
@@ -1417,11 +1415,9 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx) | |||
1417 | retval = tty_ldisc_setup(tty, tty->link); | 1415 | retval = tty_ldisc_setup(tty, tty->link); |
1418 | if (retval) | 1416 | if (retval) |
1419 | goto err_release_tty; | 1417 | goto err_release_tty; |
1420 | /* Return the tty locked so that it cannot vanish under the caller */ | ||
1421 | return tty; | 1418 | return tty; |
1422 | 1419 | ||
1423 | err_deinit_tty: | 1420 | err_deinit_tty: |
1424 | tty_unlock(tty); | ||
1425 | deinitialize_tty_struct(tty); | 1421 | deinitialize_tty_struct(tty); |
1426 | free_tty_struct(tty); | 1422 | free_tty_struct(tty); |
1427 | err_module_put: | 1423 | err_module_put: |
@@ -1430,7 +1426,6 @@ err_module_put: | |||
1430 | 1426 | ||
1431 | /* call the tty release_tty routine to clean out this slot */ | 1427 | /* call the tty release_tty routine to clean out this slot */ |
1432 | err_release_tty: | 1428 | err_release_tty: |
1433 | tty_unlock(tty); | ||
1434 | printk_ratelimited(KERN_INFO "tty_init_dev: ldisc open failed, " | 1429 | printk_ratelimited(KERN_INFO "tty_init_dev: ldisc open failed, " |
1435 | "clearing slot %d\n", idx); | 1430 | "clearing slot %d\n", idx); |
1436 | release_tty(tty, idx); | 1431 | release_tty(tty, idx); |
@@ -1633,7 +1628,7 @@ int tty_release(struct inode *inode, struct file *filp) | |||
1633 | if (tty_paranoia_check(tty, inode, __func__)) | 1628 | if (tty_paranoia_check(tty, inode, __func__)) |
1634 | return 0; | 1629 | return 0; |
1635 | 1630 | ||
1636 | tty_lock(tty); | 1631 | tty_lock(); |
1637 | check_tty_count(tty, __func__); | 1632 | check_tty_count(tty, __func__); |
1638 | 1633 | ||
1639 | __tty_fasync(-1, filp, 0); | 1634 | __tty_fasync(-1, filp, 0); |
@@ -1642,11 +1637,10 @@ int tty_release(struct inode *inode, struct file *filp) | |||
1642 | pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY && | 1637 | pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY && |
1643 | tty->driver->subtype == PTY_TYPE_MASTER); | 1638 | tty->driver->subtype == PTY_TYPE_MASTER); |
1644 | devpts = (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM) != 0; | 1639 | devpts = (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM) != 0; |
1645 | /* Review: parallel close */ | ||
1646 | o_tty = tty->link; | 1640 | o_tty = tty->link; |
1647 | 1641 | ||
1648 | if (tty_release_checks(tty, o_tty, idx)) { | 1642 | if (tty_release_checks(tty, o_tty, idx)) { |
1649 | tty_unlock(tty); | 1643 | tty_unlock(); |
1650 | return 0; | 1644 | return 0; |
1651 | } | 1645 | } |
1652 | 1646 | ||
@@ -1658,7 +1652,7 @@ int tty_release(struct inode *inode, struct file *filp) | |||
1658 | if (tty->ops->close) | 1652 | if (tty->ops->close) |
1659 | tty->ops->close(tty, filp); | 1653 | tty->ops->close(tty, filp); |
1660 | 1654 | ||
1661 | tty_unlock(tty); | 1655 | tty_unlock(); |
1662 | /* | 1656 | /* |
1663 | * Sanity check: if tty->count is going to zero, there shouldn't be | 1657 | * Sanity check: if tty->count is going to zero, there shouldn't be |
1664 | * any waiters on tty->read_wait or tty->write_wait. We test the | 1658 | * any waiters on tty->read_wait or tty->write_wait. We test the |
@@ -1681,7 +1675,7 @@ int tty_release(struct inode *inode, struct file *filp) | |||
1681 | opens on /dev/tty */ | 1675 | opens on /dev/tty */ |
1682 | 1676 | ||
1683 | mutex_lock(&tty_mutex); | 1677 | mutex_lock(&tty_mutex); |
1684 | tty_lock_pair(tty, o_tty); | 1678 | tty_lock(); |
1685 | tty_closing = tty->count <= 1; | 1679 | tty_closing = tty->count <= 1; |
1686 | o_tty_closing = o_tty && | 1680 | o_tty_closing = o_tty && |
1687 | (o_tty->count <= (pty_master ? 1 : 0)); | 1681 | (o_tty->count <= (pty_master ? 1 : 0)); |
@@ -1712,7 +1706,7 @@ int tty_release(struct inode *inode, struct file *filp) | |||
1712 | 1706 | ||
1713 | printk(KERN_WARNING "%s: %s: read/write wait queue active!\n", | 1707 | printk(KERN_WARNING "%s: %s: read/write wait queue active!\n", |
1714 | __func__, tty_name(tty, buf)); | 1708 | __func__, tty_name(tty, buf)); |
1715 | tty_unlock_pair(tty, o_tty); | 1709 | tty_unlock(); |
1716 | mutex_unlock(&tty_mutex); | 1710 | mutex_unlock(&tty_mutex); |
1717 | schedule(); | 1711 | schedule(); |
1718 | } | 1712 | } |
@@ -1775,7 +1769,7 @@ int tty_release(struct inode *inode, struct file *filp) | |||
1775 | 1769 | ||
1776 | /* check whether both sides are closing ... */ | 1770 | /* check whether both sides are closing ... */ |
1777 | if (!tty_closing || (o_tty && !o_tty_closing)) { | 1771 | if (!tty_closing || (o_tty && !o_tty_closing)) { |
1778 | tty_unlock_pair(tty, o_tty); | 1772 | tty_unlock(); |
1779 | return 0; | 1773 | return 0; |
1780 | } | 1774 | } |
1781 | 1775 | ||
@@ -1788,16 +1782,14 @@ int tty_release(struct inode *inode, struct file *filp) | |||
1788 | tty_ldisc_release(tty, o_tty); | 1782 | tty_ldisc_release(tty, o_tty); |
1789 | /* | 1783 | /* |
1790 | * The release_tty function takes care of the details of clearing | 1784 | * The release_tty function takes care of the details of clearing |
1791 | * the slots and preserving the termios structure. The tty_unlock_pair | 1785 | * the slots and preserving the termios structure. |
1792 | * should be safe as we keep a kref while the tty is locked (so the | ||
1793 | * unlock never unlocks a freed tty). | ||
1794 | */ | 1786 | */ |
1795 | release_tty(tty, idx); | 1787 | release_tty(tty, idx); |
1796 | tty_unlock_pair(tty, o_tty); | ||
1797 | 1788 | ||
1798 | /* Make this pty number available for reallocation */ | 1789 | /* Make this pty number available for reallocation */ |
1799 | if (devpts) | 1790 | if (devpts) |
1800 | devpts_kill_index(inode, idx); | 1791 | devpts_kill_index(inode, idx); |
1792 | tty_unlock(); | ||
1801 | return 0; | 1793 | return 0; |
1802 | } | 1794 | } |
1803 | 1795 | ||
@@ -1901,9 +1893,6 @@ static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp, | |||
1901 | * Locking: tty_mutex protects tty, tty_lookup_driver and tty_init_dev. | 1893 | * Locking: tty_mutex protects tty, tty_lookup_driver and tty_init_dev. |
1902 | * tty->count should protect the rest. | 1894 | * tty->count should protect the rest. |
1903 | * ->siglock protects ->signal/->sighand | 1895 | * ->siglock protects ->signal/->sighand |
1904 | * | ||
1905 | * Note: the tty_unlock/lock cases without a ref are only safe due to | ||
1906 | * tty_mutex | ||
1907 | */ | 1896 | */ |
1908 | 1897 | ||
1909 | static int tty_open(struct inode *inode, struct file *filp) | 1898 | static int tty_open(struct inode *inode, struct file *filp) |
@@ -1927,7 +1916,8 @@ retry_open: | |||
1927 | retval = 0; | 1916 | retval = 0; |
1928 | 1917 | ||
1929 | mutex_lock(&tty_mutex); | 1918 | mutex_lock(&tty_mutex); |
1930 | /* This is protected by the tty_mutex */ | 1919 | tty_lock(); |
1920 | |||
1931 | tty = tty_open_current_tty(device, filp); | 1921 | tty = tty_open_current_tty(device, filp); |
1932 | if (IS_ERR(tty)) { | 1922 | if (IS_ERR(tty)) { |
1933 | retval = PTR_ERR(tty); | 1923 | retval = PTR_ERR(tty); |
@@ -1948,19 +1938,17 @@ retry_open: | |||
1948 | } | 1938 | } |
1949 | 1939 | ||
1950 | if (tty) { | 1940 | if (tty) { |
1951 | tty_lock(tty); | ||
1952 | retval = tty_reopen(tty); | 1941 | retval = tty_reopen(tty); |
1953 | if (retval < 0) { | 1942 | if (retval) |
1954 | tty_unlock(tty); | ||
1955 | tty = ERR_PTR(retval); | 1943 | tty = ERR_PTR(retval); |
1956 | } | 1944 | } else |
1957 | } else /* Returns with the tty_lock held for now */ | ||
1958 | tty = tty_init_dev(driver, index); | 1945 | tty = tty_init_dev(driver, index); |
1959 | 1946 | ||
1960 | mutex_unlock(&tty_mutex); | 1947 | mutex_unlock(&tty_mutex); |
1961 | if (driver) | 1948 | if (driver) |
1962 | tty_driver_kref_put(driver); | 1949 | tty_driver_kref_put(driver); |
1963 | if (IS_ERR(tty)) { | 1950 | if (IS_ERR(tty)) { |
1951 | tty_unlock(); | ||
1964 | retval = PTR_ERR(tty); | 1952 | retval = PTR_ERR(tty); |
1965 | goto err_file; | 1953 | goto err_file; |
1966 | } | 1954 | } |
@@ -1989,7 +1977,7 @@ retry_open: | |||
1989 | printk(KERN_DEBUG "%s: error %d in opening %s...\n", __func__, | 1977 | printk(KERN_DEBUG "%s: error %d in opening %s...\n", __func__, |
1990 | retval, tty->name); | 1978 | retval, tty->name); |
1991 | #endif | 1979 | #endif |
1992 | tty_unlock(tty); /* need to call tty_release without BTM */ | 1980 | tty_unlock(); /* need to call tty_release without BTM */ |
1993 | tty_release(inode, filp); | 1981 | tty_release(inode, filp); |
1994 | if (retval != -ERESTARTSYS) | 1982 | if (retval != -ERESTARTSYS) |
1995 | return retval; | 1983 | return retval; |
@@ -2001,15 +1989,17 @@ retry_open: | |||
2001 | /* | 1989 | /* |
2002 | * Need to reset f_op in case a hangup happened. | 1990 | * Need to reset f_op in case a hangup happened. |
2003 | */ | 1991 | */ |
1992 | tty_lock(); | ||
2004 | if (filp->f_op == &hung_up_tty_fops) | 1993 | if (filp->f_op == &hung_up_tty_fops) |
2005 | filp->f_op = &tty_fops; | 1994 | filp->f_op = &tty_fops; |
1995 | tty_unlock(); | ||
2006 | goto retry_open; | 1996 | goto retry_open; |
2007 | } | 1997 | } |
2008 | tty_unlock(tty); | 1998 | tty_unlock(); |
2009 | 1999 | ||
2010 | 2000 | ||
2011 | mutex_lock(&tty_mutex); | 2001 | mutex_lock(&tty_mutex); |
2012 | tty_lock(tty); | 2002 | tty_lock(); |
2013 | spin_lock_irq(¤t->sighand->siglock); | 2003 | spin_lock_irq(¤t->sighand->siglock); |
2014 | if (!noctty && | 2004 | if (!noctty && |
2015 | current->signal->leader && | 2005 | current->signal->leader && |
@@ -2017,10 +2007,11 @@ retry_open: | |||
2017 | tty->session == NULL) | 2007 | tty->session == NULL) |
2018 | __proc_set_tty(current, tty); | 2008 | __proc_set_tty(current, tty); |
2019 | spin_unlock_irq(¤t->sighand->siglock); | 2009 | spin_unlock_irq(¤t->sighand->siglock); |
2020 | tty_unlock(tty); | 2010 | tty_unlock(); |
2021 | mutex_unlock(&tty_mutex); | 2011 | mutex_unlock(&tty_mutex); |
2022 | return 0; | 2012 | return 0; |
2023 | err_unlock: | 2013 | err_unlock: |
2014 | tty_unlock(); | ||
2024 | mutex_unlock(&tty_mutex); | 2015 | mutex_unlock(&tty_mutex); |
2025 | /* after locks to avoid deadlock */ | 2016 | /* after locks to avoid deadlock */ |
2026 | if (!IS_ERR_OR_NULL(driver)) | 2017 | if (!IS_ERR_OR_NULL(driver)) |
@@ -2103,13 +2094,10 @@ out: | |||
2103 | 2094 | ||
2104 | static int tty_fasync(int fd, struct file *filp, int on) | 2095 | static int tty_fasync(int fd, struct file *filp, int on) |
2105 | { | 2096 | { |
2106 | struct tty_struct *tty = file_tty(filp); | ||
2107 | int retval; | 2097 | int retval; |
2108 | 2098 | tty_lock(); | |
2109 | tty_lock(tty); | ||
2110 | retval = __tty_fasync(fd, filp, on); | 2099 | retval = __tty_fasync(fd, filp, on); |
2111 | tty_unlock(tty); | 2100 | tty_unlock(); |
2112 | |||
2113 | return retval; | 2101 | return retval; |
2114 | } | 2102 | } |
2115 | 2103 | ||
@@ -2946,7 +2934,6 @@ void initialize_tty_struct(struct tty_struct *tty, | |||
2946 | tty->pgrp = NULL; | 2934 | tty->pgrp = NULL; |
2947 | tty->overrun_time = jiffies; | 2935 | tty->overrun_time = jiffies; |
2948 | tty_buffer_init(tty); | 2936 | tty_buffer_init(tty); |
2949 | mutex_init(&tty->legacy_mutex); | ||
2950 | mutex_init(&tty->termios_mutex); | 2937 | mutex_init(&tty->termios_mutex); |
2951 | mutex_init(&tty->ldisc_mutex); | 2938 | mutex_init(&tty->ldisc_mutex); |
2952 | init_waitqueue_head(&tty->write_wait); | 2939 | init_waitqueue_head(&tty->write_wait); |