tty_io.c (dc6802a771e91050fb686dfeeb9de4c6c9cadb79) tty_io.c (89c8d91e31f267703e365593f6bfebb9f6d2ad01)
1/*
2 * Copyright (C) 1991, 1992 Linus Torvalds
3 */
4
5/*
6 * 'tty_io.c' gives an orthogonal feeling to tty's, be they consoles
7 * or rs-channels. It also implements echoing, cooked mode etc.
8 *

--- 173 unchanged lines hidden (view full) ---

182void free_tty_struct(struct tty_struct *tty)
183{
184 if (!tty)
185 return;
186 if (tty->dev)
187 put_device(tty->dev);
188 kfree(tty->write_buf);
189 tty_buffer_free_all(tty);
1/*
2 * Copyright (C) 1991, 1992 Linus Torvalds
3 */
4
5/*
6 * 'tty_io.c' gives an orthogonal feeling to tty's, be they consoles
7 * or rs-channels. It also implements echoing, cooked mode etc.
8 *

--- 173 unchanged lines hidden (view full) ---

182void free_tty_struct(struct tty_struct *tty)
183{
184 if (!tty)
185 return;
186 if (tty->dev)
187 put_device(tty->dev);
188 kfree(tty->write_buf);
189 tty_buffer_free_all(tty);
190 tty->magic = 0xDEADDEAD;
190 kfree(tty);
191}
192
193static inline struct tty_struct *file_tty(struct file *file)
194{
195 return ((struct tty_file_private *)file->private_data)->tty;
196}
197

--- 372 unchanged lines hidden (view full) ---

570
571 spin_lock(&redirect_lock);
572 if (redirect && file_tty(redirect) == tty) {
573 f = redirect;
574 redirect = NULL;
575 }
576 spin_unlock(&redirect_lock);
577
191 kfree(tty);
192}
193
194static inline struct tty_struct *file_tty(struct file *file)
195{
196 return ((struct tty_file_private *)file->private_data)->tty;
197}
198

--- 372 unchanged lines hidden (view full) ---

571
572 spin_lock(&redirect_lock);
573 if (redirect && file_tty(redirect) == tty) {
574 f = redirect;
575 redirect = NULL;
576 }
577 spin_unlock(&redirect_lock);
578
578 tty_lock();
579 tty_lock(tty);
579
580 /* some functions below drop BTM, so we need this bit */
581 set_bit(TTY_HUPPING, &tty->flags);
582
583 /* inuse_filps is protected by the single tty lock,
584 this really needs to change if we want to flush the
585 workqueue with the lock held */
586 check_tty_count(tty, "tty_hangup");

--- 76 unchanged lines hidden (view full) ---

663 * the ones we did here. The driver layer expects no
664 * calls after ->hangup() from the ldisc side. However we
665 * can't yet guarantee all that.
666 */
667 set_bit(TTY_HUPPED, &tty->flags);
668 clear_bit(TTY_HUPPING, &tty->flags);
669 tty_ldisc_enable(tty);
670
580
581 /* some functions below drop BTM, so we need this bit */
582 set_bit(TTY_HUPPING, &tty->flags);
583
584 /* inuse_filps is protected by the single tty lock,
585 this really needs to change if we want to flush the
586 workqueue with the lock held */
587 check_tty_count(tty, "tty_hangup");

--- 76 unchanged lines hidden (view full) ---

664 * the ones we did here. The driver layer expects no
665 * calls after ->hangup() from the ldisc side. However we
666 * can't yet guarantee all that.
667 */
668 set_bit(TTY_HUPPED, &tty->flags);
669 clear_bit(TTY_HUPPING, &tty->flags);
670 tty_ldisc_enable(tty);
671
671 tty_unlock();
672 tty_unlock(tty);
672
673 if (f)
674 fput(f);
675}
676
677static void do_tty_hangup(struct work_struct *work)
678{
679 struct tty_struct *tty =

--- 420 unchanged lines hidden (view full) ---

1100 *
1101 * We must still hold the BTM and test the CLOSING flag for the moment.
1102 */
1103
1104void tty_write_message(struct tty_struct *tty, char *msg)
1105{
1106 if (tty) {
1107 mutex_lock(&tty->atomic_write_lock);
673
674 if (f)
675 fput(f);
676}
677
678static void do_tty_hangup(struct work_struct *work)
679{
680 struct tty_struct *tty =

--- 420 unchanged lines hidden (view full) ---

1101 *
1102 * We must still hold the BTM and test the CLOSING flag for the moment.
1103 */
1104
1105void tty_write_message(struct tty_struct *tty, char *msg)
1106{
1107 if (tty) {
1108 mutex_lock(&tty->atomic_write_lock);
1108 tty_lock();
1109 tty_lock(tty);
1109 if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags)) {
1110 if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags)) {
1110 tty_unlock();
1111 tty_unlock(tty);
1111 tty->ops->write(tty, msg, strlen(msg));
1112 } else
1112 tty->ops->write(tty, msg, strlen(msg));
1113 } else
1113 tty_unlock();
1114 tty_unlock(tty);
1114 tty_write_unlock(tty);
1115 }
1116 return;
1117}
1118
1119
1120/**
1121 * tty_write - write method for tty device file

--- 276 unchanged lines hidden (view full) ---

1398
1399 tty = alloc_tty_struct();
1400 if (!tty) {
1401 retval = -ENOMEM;
1402 goto err_module_put;
1403 }
1404 initialize_tty_struct(tty, driver, idx);
1405
1115 tty_write_unlock(tty);
1116 }
1117 return;
1118}
1119
1120
1121/**
1122 * tty_write - write method for tty device file

--- 276 unchanged lines hidden (view full) ---

1399
1400 tty = alloc_tty_struct();
1401 if (!tty) {
1402 retval = -ENOMEM;
1403 goto err_module_put;
1404 }
1405 initialize_tty_struct(tty, driver, idx);
1406
1407 tty_lock(tty);
1406 retval = tty_driver_install_tty(driver, tty);
1407 if (retval < 0)
1408 goto err_deinit_tty;
1409
1410 if (!tty->port)
1411 tty->port = driver->ports[idx];
1412
1413 /*
1414 * Structures all installed ... call the ldisc open routines.
1415 * If we fail here just call release_tty to clean up. No need
1416 * to decrement the use counts, as release_tty doesn't care.
1417 */
1418 retval = tty_ldisc_setup(tty, tty->link);
1419 if (retval)
1420 goto err_release_tty;
1408 retval = tty_driver_install_tty(driver, tty);
1409 if (retval < 0)
1410 goto err_deinit_tty;
1411
1412 if (!tty->port)
1413 tty->port = driver->ports[idx];
1414
1415 /*
1416 * Structures all installed ... call the ldisc open routines.
1417 * If we fail here just call release_tty to clean up. No need
1418 * to decrement the use counts, as release_tty doesn't care.
1419 */
1420 retval = tty_ldisc_setup(tty, tty->link);
1421 if (retval)
1422 goto err_release_tty;
1423 /* Return the tty locked so that it cannot vanish under the caller */
1421 return tty;
1422
1423err_deinit_tty:
1424 return tty;
1425
1426err_deinit_tty:
1427 tty_unlock(tty);
1424 deinitialize_tty_struct(tty);
1425 free_tty_struct(tty);
1426err_module_put:
1427 module_put(driver->owner);
1428 return ERR_PTR(retval);
1429
1430 /* call the tty release_tty routine to clean out this slot */
1431err_release_tty:
1428 deinitialize_tty_struct(tty);
1429 free_tty_struct(tty);
1430err_module_put:
1431 module_put(driver->owner);
1432 return ERR_PTR(retval);
1433
1434 /* call the tty release_tty routine to clean out this slot */
1435err_release_tty:
1436 tty_unlock(tty);
1432 printk_ratelimited(KERN_INFO "tty_init_dev: ldisc open failed, "
1433 "clearing slot %d\n", idx);
1434 release_tty(tty, idx);
1435 return ERR_PTR(retval);
1436}
1437
1438void tty_free_termios(struct tty_struct *tty)
1439{

--- 177 unchanged lines hidden (view full) ---

1617 int pty_master, tty_closing, o_tty_closing, do_sleep;
1618 int devpts;
1619 int idx;
1620 char buf[64];
1621
1622 if (tty_paranoia_check(tty, inode, __func__))
1623 return 0;
1624
1437 printk_ratelimited(KERN_INFO "tty_init_dev: ldisc open failed, "
1438 "clearing slot %d\n", idx);
1439 release_tty(tty, idx);
1440 return ERR_PTR(retval);
1441}
1442
1443void tty_free_termios(struct tty_struct *tty)
1444{

--- 177 unchanged lines hidden (view full) ---

1622 int pty_master, tty_closing, o_tty_closing, do_sleep;
1623 int devpts;
1624 int idx;
1625 char buf[64];
1626
1627 if (tty_paranoia_check(tty, inode, __func__))
1628 return 0;
1629
1625 tty_lock();
1630 tty_lock(tty);
1626 check_tty_count(tty, __func__);
1627
1628 __tty_fasync(-1, filp, 0);
1629
1630 idx = tty->index;
1631 pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
1632 tty->driver->subtype == PTY_TYPE_MASTER);
1633 devpts = (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM) != 0;
1631 check_tty_count(tty, __func__);
1632
1633 __tty_fasync(-1, filp, 0);
1634
1635 idx = tty->index;
1636 pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
1637 tty->driver->subtype == PTY_TYPE_MASTER);
1638 devpts = (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM) != 0;
1639 /* Review: parallel close */
1634 o_tty = tty->link;
1635
1636 if (tty_release_checks(tty, o_tty, idx)) {
1640 o_tty = tty->link;
1641
1642 if (tty_release_checks(tty, o_tty, idx)) {
1637 tty_unlock();
1643 tty_unlock(tty);
1638 return 0;
1639 }
1640
1641#ifdef TTY_DEBUG_HANGUP
1642 printk(KERN_DEBUG "%s: %s (tty count=%d)...\n", __func__,
1643 tty_name(tty, buf), tty->count);
1644#endif
1645
1646 if (tty->ops->close)
1647 tty->ops->close(tty, filp);
1648
1644 return 0;
1645 }
1646
1647#ifdef TTY_DEBUG_HANGUP
1648 printk(KERN_DEBUG "%s: %s (tty count=%d)...\n", __func__,
1649 tty_name(tty, buf), tty->count);
1650#endif
1651
1652 if (tty->ops->close)
1653 tty->ops->close(tty, filp);
1654
1649 tty_unlock();
1655 tty_unlock(tty);
1650 /*
1651 * Sanity check: if tty->count is going to zero, there shouldn't be
1652 * any waiters on tty->read_wait or tty->write_wait. We test the
1653 * wait queues and kick everyone out _before_ actually starting to
1654 * close. This ensures that we won't block while releasing the tty
1655 * structure.
1656 *
1657 * The test for the o_tty closing is necessary, since the master and

--- 6 unchanged lines hidden (view full) ---

1664 * flushing out waiters. By recalculating the closing flags before
1665 * each iteration we avoid any problems.
1666 */
1667 while (1) {
1668 /* Guard against races with tty->count changes elsewhere and
1669 opens on /dev/tty */
1670
1671 mutex_lock(&tty_mutex);
1656 /*
1657 * Sanity check: if tty->count is going to zero, there shouldn't be
1658 * any waiters on tty->read_wait or tty->write_wait. We test the
1659 * wait queues and kick everyone out _before_ actually starting to
1660 * close. This ensures that we won't block while releasing the tty
1661 * structure.
1662 *
1663 * The test for the o_tty closing is necessary, since the master and

--- 6 unchanged lines hidden (view full) ---

1670 * flushing out waiters. By recalculating the closing flags before
1671 * each iteration we avoid any problems.
1672 */
1673 while (1) {
1674 /* Guard against races with tty->count changes elsewhere and
1675 opens on /dev/tty */
1676
1677 mutex_lock(&tty_mutex);
1672 tty_lock();
1678 tty_lock_pair(tty, o_tty);
1673 tty_closing = tty->count <= 1;
1674 o_tty_closing = o_tty &&
1675 (o_tty->count <= (pty_master ? 1 : 0));
1676 do_sleep = 0;
1677
1678 if (tty_closing) {
1679 if (waitqueue_active(&tty->read_wait)) {
1680 wake_up_poll(&tty->read_wait, POLLIN);

--- 14 unchanged lines hidden (view full) ---

1695 do_sleep++;
1696 }
1697 }
1698 if (!do_sleep)
1699 break;
1700
1701 printk(KERN_WARNING "%s: %s: read/write wait queue active!\n",
1702 __func__, tty_name(tty, buf));
1679 tty_closing = tty->count <= 1;
1680 o_tty_closing = o_tty &&
1681 (o_tty->count <= (pty_master ? 1 : 0));
1682 do_sleep = 0;
1683
1684 if (tty_closing) {
1685 if (waitqueue_active(&tty->read_wait)) {
1686 wake_up_poll(&tty->read_wait, POLLIN);

--- 14 unchanged lines hidden (view full) ---

1701 do_sleep++;
1702 }
1703 }
1704 if (!do_sleep)
1705 break;
1706
1707 printk(KERN_WARNING "%s: %s: read/write wait queue active!\n",
1708 __func__, tty_name(tty, buf));
1703 tty_unlock();
1709 tty_unlock_pair(tty, o_tty);
1704 mutex_unlock(&tty_mutex);
1705 schedule();
1706 }
1707
1708 /*
1709 * The closing flags are now consistent with the open counts on
1710 * both sides, and we've completed the last operation that could
1711 * block, so it's safe to proceed with closing.

--- 46 unchanged lines hidden (view full) ---

1758 read_lock(&tasklist_lock);
1759 session_clear_tty(tty->session);
1760 if (o_tty)
1761 session_clear_tty(o_tty->session);
1762 read_unlock(&tasklist_lock);
1763 }
1764
1765 mutex_unlock(&tty_mutex);
1710 mutex_unlock(&tty_mutex);
1711 schedule();
1712 }
1713
1714 /*
1715 * The closing flags are now consistent with the open counts on
1716 * both sides, and we've completed the last operation that could
1717 * block, so it's safe to proceed with closing.

--- 46 unchanged lines hidden (view full) ---

1764 read_lock(&tasklist_lock);
1765 session_clear_tty(tty->session);
1766 if (o_tty)
1767 session_clear_tty(o_tty->session);
1768 read_unlock(&tasklist_lock);
1769 }
1770
1771 mutex_unlock(&tty_mutex);
1766 tty_unlock();
1772 tty_unlock_pair(tty, o_tty);
1767 /* At this point the TTY_CLOSING flag should ensure a dead tty
1768 cannot be re-opened by a racing opener */
1769
1770 /* check whether both sides are closing ... */
1771 if (!tty_closing || (o_tty && !o_tty_closing))
1772 return 0;
1773
1774#ifdef TTY_DEBUG_HANGUP
1775 printk(KERN_DEBUG "%s: freeing tty structure...\n", __func__);
1776#endif
1777 /*
1778 * Ask the line discipline code to release its structures
1779 */
1780 tty_ldisc_release(tty, o_tty);
1781 /*
1782 * The release_tty function takes care of the details of clearing
1773 /* At this point the TTY_CLOSING flag should ensure a dead tty
1774 cannot be re-opened by a racing opener */
1775
1776 /* check whether both sides are closing ... */
1777 if (!tty_closing || (o_tty && !o_tty_closing))
1778 return 0;
1779
1780#ifdef TTY_DEBUG_HANGUP
1781 printk(KERN_DEBUG "%s: freeing tty structure...\n", __func__);
1782#endif
1783 /*
1784 * Ask the line discipline code to release its structures
1785 */
1786 tty_ldisc_release(tty, o_tty);
1787 /*
1788 * The release_tty function takes care of the details of clearing
1783 * the slots and preserving the termios structure.
1789 * the slots and preserving the termios structure. The tty_unlock_pair
1790 * should be safe as we keep a kref while the tty is locked (so the
1791 * unlock never unlocks a freed tty).
1784 */
1785 mutex_lock(&tty_mutex);
1786 release_tty(tty, idx);
1787 mutex_unlock(&tty_mutex);
1788
1789 /* Make this pty number available for reallocation */
1790 if (devpts)
1791 devpts_kill_index(inode, idx);
1792 */
1793 mutex_lock(&tty_mutex);
1794 release_tty(tty, idx);
1795 mutex_unlock(&tty_mutex);
1796
1797 /* Make this pty number available for reallocation */
1798 if (devpts)
1799 devpts_kill_index(inode, idx);
1792
1793 return 0;
1794}
1795
1796/**
1797 * tty_open_current_tty - get tty of current task for open
1798 * @device: device number
1799 * @filp: file pointer to tty
1800 * @return: tty of the current task iff @device is /dev/tty

--- 87 unchanged lines hidden (view full) ---

1888 * (This is not done solely through tty->count, now. - Ted 1/27/92)
1889 *
1890 * The termios state of a pty is reset on first open so that
1891 * settings don't persist across reuse.
1892 *
1893 * Locking: tty_mutex protects tty, tty_lookup_driver and tty_init_dev.
1894 * tty->count should protect the rest.
1895 * ->siglock protects ->signal/->sighand
1800 return 0;
1801}
1802
1803/**
1804 * tty_open_current_tty - get tty of current task for open
1805 * @device: device number
1806 * @filp: file pointer to tty
1807 * @return: tty of the current task iff @device is /dev/tty

--- 87 unchanged lines hidden (view full) ---

1895 * (This is not done solely through tty->count, now. - Ted 1/27/92)
1896 *
1897 * The termios state of a pty is reset on first open so that
1898 * settings don't persist across reuse.
1899 *
1900 * Locking: tty_mutex protects tty, tty_lookup_driver and tty_init_dev.
1901 * tty->count should protect the rest.
1902 * ->siglock protects ->signal/->sighand
1903 *
1904 * Note: the tty_unlock/lock cases without a ref are only safe due to
1905 * tty_mutex
1896 */
1897
1898static int tty_open(struct inode *inode, struct file *filp)
1899{
1900 struct tty_struct *tty;
1901 int noctty, retval;
1902 struct tty_driver *driver = NULL;
1903 int index;

--- 7 unchanged lines hidden (view full) ---

1911 if (retval)
1912 return -ENOMEM;
1913
1914 noctty = filp->f_flags & O_NOCTTY;
1915 index = -1;
1916 retval = 0;
1917
1918 mutex_lock(&tty_mutex);
1906 */
1907
1908static int tty_open(struct inode *inode, struct file *filp)
1909{
1910 struct tty_struct *tty;
1911 int noctty, retval;
1912 struct tty_driver *driver = NULL;
1913 int index;

--- 7 unchanged lines hidden (view full) ---

1921 if (retval)
1922 return -ENOMEM;
1923
1924 noctty = filp->f_flags & O_NOCTTY;
1925 index = -1;
1926 retval = 0;
1927
1928 mutex_lock(&tty_mutex);
1919 tty_lock();
1920
1929 /* This is protected by the tty_mutex */
1921 tty = tty_open_current_tty(device, filp);
1922 if (IS_ERR(tty)) {
1923 retval = PTR_ERR(tty);
1924 goto err_unlock;
1925 } else if (!tty) {
1926 driver = tty_lookup_driver(device, filp, &noctty, &index);
1927 if (IS_ERR(driver)) {
1928 retval = PTR_ERR(driver);

--- 4 unchanged lines hidden (view full) ---

1933 tty = tty_driver_lookup_tty(driver, inode, index);
1934 if (IS_ERR(tty)) {
1935 retval = PTR_ERR(tty);
1936 goto err_unlock;
1937 }
1938 }
1939
1940 if (tty) {
1930 tty = tty_open_current_tty(device, filp);
1931 if (IS_ERR(tty)) {
1932 retval = PTR_ERR(tty);
1933 goto err_unlock;
1934 } else if (!tty) {
1935 driver = tty_lookup_driver(device, filp, &noctty, &index);
1936 if (IS_ERR(driver)) {
1937 retval = PTR_ERR(driver);

--- 4 unchanged lines hidden (view full) ---

1942 tty = tty_driver_lookup_tty(driver, inode, index);
1943 if (IS_ERR(tty)) {
1944 retval = PTR_ERR(tty);
1945 goto err_unlock;
1946 }
1947 }
1948
1949 if (tty) {
1950 tty_lock(tty);
1941 retval = tty_reopen(tty);
1951 retval = tty_reopen(tty);
1942 if (retval)
1952 if (retval < 0) {
1953 tty_unlock(tty);
1943 tty = ERR_PTR(retval);
1954 tty = ERR_PTR(retval);
1944 } else
1955 }
1956 } else /* Returns with the tty_lock held for now */
1945 tty = tty_init_dev(driver, index);
1946
1947 mutex_unlock(&tty_mutex);
1948 if (driver)
1949 tty_driver_kref_put(driver);
1950 if (IS_ERR(tty)) {
1957 tty = tty_init_dev(driver, index);
1958
1959 mutex_unlock(&tty_mutex);
1960 if (driver)
1961 tty_driver_kref_put(driver);
1962 if (IS_ERR(tty)) {
1951 tty_unlock();
1952 retval = PTR_ERR(tty);
1953 goto err_file;
1954 }
1955
1956 tty_add_file(tty, filp);
1957
1958 check_tty_count(tty, __func__);
1959 if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&

--- 12 unchanged lines hidden (view full) ---

1972 !capable(CAP_SYS_ADMIN))
1973 retval = -EBUSY;
1974
1975 if (retval) {
1976#ifdef TTY_DEBUG_HANGUP
1977 printk(KERN_DEBUG "%s: error %d in opening %s...\n", __func__,
1978 retval, tty->name);
1979#endif
1963 retval = PTR_ERR(tty);
1964 goto err_file;
1965 }
1966
1967 tty_add_file(tty, filp);
1968
1969 check_tty_count(tty, __func__);
1970 if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&

--- 12 unchanged lines hidden (view full) ---

1983 !capable(CAP_SYS_ADMIN))
1984 retval = -EBUSY;
1985
1986 if (retval) {
1987#ifdef TTY_DEBUG_HANGUP
1988 printk(KERN_DEBUG "%s: error %d in opening %s...\n", __func__,
1989 retval, tty->name);
1990#endif
1980 tty_unlock(); /* need to call tty_release without BTM */
1991 tty_unlock(tty); /* need to call tty_release without BTM */
1981 tty_release(inode, filp);
1982 if (retval != -ERESTARTSYS)
1983 return retval;
1984
1985 if (signal_pending(current))
1986 return retval;
1987
1988 schedule();
1989 /*
1990 * Need to reset f_op in case a hangup happened.
1991 */
1992 tty_release(inode, filp);
1993 if (retval != -ERESTARTSYS)
1994 return retval;
1995
1996 if (signal_pending(current))
1997 return retval;
1998
1999 schedule();
2000 /*
2001 * Need to reset f_op in case a hangup happened.
2002 */
1992 tty_lock();
1993 if (filp->f_op == &hung_up_tty_fops)
1994 filp->f_op = &tty_fops;
2003 if (filp->f_op == &hung_up_tty_fops)
2004 filp->f_op = &tty_fops;
1995 tty_unlock();
1996 goto retry_open;
1997 }
2005 goto retry_open;
2006 }
1998 tty_unlock();
2007 tty_unlock(tty);
1999
2000
2001 mutex_lock(&tty_mutex);
2008
2009
2010 mutex_lock(&tty_mutex);
2002 tty_lock();
2011 tty_lock(tty);
2003 spin_lock_irq(&current->sighand->siglock);
2004 if (!noctty &&
2005 current->signal->leader &&
2006 !current->signal->tty &&
2007 tty->session == NULL)
2008 __proc_set_tty(current, tty);
2009 spin_unlock_irq(&current->sighand->siglock);
2012 spin_lock_irq(&current->sighand->siglock);
2013 if (!noctty &&
2014 current->signal->leader &&
2015 !current->signal->tty &&
2016 tty->session == NULL)
2017 __proc_set_tty(current, tty);
2018 spin_unlock_irq(&current->sighand->siglock);
2010 tty_unlock();
2019 tty_unlock(tty);
2011 mutex_unlock(&tty_mutex);
2012 return 0;
2013err_unlock:
2020 mutex_unlock(&tty_mutex);
2021 return 0;
2022err_unlock:
2014 tty_unlock();
2015 mutex_unlock(&tty_mutex);
2016 /* after locks to avoid deadlock */
2017 if (!IS_ERR_OR_NULL(driver))
2018 tty_driver_kref_put(driver);
2019err_file:
2020 tty_free_file(filp);
2021 return retval;
2022}

--- 66 unchanged lines hidden (view full) ---

2089 }
2090 retval = 0;
2091out:
2092 return retval;
2093}
2094
2095static int tty_fasync(int fd, struct file *filp, int on)
2096{
2023 mutex_unlock(&tty_mutex);
2024 /* after locks to avoid deadlock */
2025 if (!IS_ERR_OR_NULL(driver))
2026 tty_driver_kref_put(driver);
2027err_file:
2028 tty_free_file(filp);
2029 return retval;
2030}

--- 66 unchanged lines hidden (view full) ---

2097 }
2098 retval = 0;
2099out:
2100 return retval;
2101}
2102
2103static int tty_fasync(int fd, struct file *filp, int on)
2104{
2105 struct tty_struct *tty = file_tty(filp);
2097 int retval;
2106 int retval;
2098 tty_lock();
2107
2108 tty_lock(tty);
2099 retval = __tty_fasync(fd, filp, on);
2109 retval = __tty_fasync(fd, filp, on);
2100 tty_unlock();
2110 tty_unlock(tty);
2111
2101 return retval;
2102}
2103
2104/**
2105 * tiocsti - fake input character
2106 * @tty: tty to fake input into
2107 * @p: pointer to character
2108 *

--- 820 unchanged lines hidden (view full) ---

2929 memset(tty, 0, sizeof(struct tty_struct));
2930 kref_init(&tty->kref);
2931 tty->magic = TTY_MAGIC;
2932 tty_ldisc_init(tty);
2933 tty->session = NULL;
2934 tty->pgrp = NULL;
2935 tty->overrun_time = jiffies;
2936 tty_buffer_init(tty);
2112 return retval;
2113}
2114
2115/**
2116 * tiocsti - fake input character
2117 * @tty: tty to fake input into
2118 * @p: pointer to character
2119 *

--- 820 unchanged lines hidden (view full) ---

2940 memset(tty, 0, sizeof(struct tty_struct));
2941 kref_init(&tty->kref);
2942 tty->magic = TTY_MAGIC;
2943 tty_ldisc_init(tty);
2944 tty->session = NULL;
2945 tty->pgrp = NULL;
2946 tty->overrun_time = jiffies;
2947 tty_buffer_init(tty);
2948 mutex_init(&tty->legacy_mutex);
2937 mutex_init(&tty->termios_mutex);
2938 mutex_init(&tty->ldisc_mutex);
2939 init_waitqueue_head(&tty->write_wait);
2940 init_waitqueue_head(&tty->read_wait);
2941 INIT_WORK(&tty->hangup_work, do_tty_hangup);
2942 mutex_init(&tty->atomic_read_lock);
2943 mutex_init(&tty->atomic_write_lock);
2944 mutex_init(&tty->output_lock);

--- 465 unchanged lines hidden ---
2949 mutex_init(&tty->termios_mutex);
2950 mutex_init(&tty->ldisc_mutex);
2951 init_waitqueue_head(&tty->write_wait);
2952 init_waitqueue_head(&tty->read_wait);
2953 INIT_WORK(&tty->hangup_work, do_tty_hangup);
2954 mutex_init(&tty->atomic_read_lock);
2955 mutex_init(&tty->atomic_write_lock);
2956 mutex_init(&tty->output_lock);

--- 465 unchanged lines hidden ---