Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tty: revert incorrectly applied lock patch

I sent GregKH this after the pre-requisites. He dropped the pre-requesites
for good reason and unfortunately then applied this patch. Without this
reverted you get random kernel memory corruption which will make bisecting
anything between it and the properly applied patches a complete sod.

Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Alan Cox and committed by
Greg Kroah-Hartman
6d31a88c 467a3ca5

+119 -188
+7 -7
drivers/tty/amiserial.c
··· 1033 1033 if (!retinfo) 1034 1034 return -EFAULT; 1035 1035 memset(&tmp, 0, sizeof(tmp)); 1036 - tty_lock(tty); 1036 + tty_lock(); 1037 1037 tmp.line = tty->index; 1038 1038 tmp.port = state->port; 1039 1039 tmp.flags = state->tport.flags; ··· 1042 1042 tmp.close_delay = state->tport.close_delay; 1043 1043 tmp.closing_wait = state->tport.closing_wait; 1044 1044 tmp.custom_divisor = state->custom_divisor; 1045 - tty_unlock(tty); 1045 + tty_unlock(); 1046 1046 if (copy_to_user(retinfo,&tmp,sizeof(*retinfo))) 1047 1047 return -EFAULT; 1048 1048 return 0; ··· 1059 1059 if (copy_from_user(&new_serial,new_info,sizeof(new_serial))) 1060 1060 return -EFAULT; 1061 1061 1062 - tty_lock(tty); 1062 + tty_lock(); 1063 1063 change_spd = ((new_serial.flags ^ port->flags) & ASYNC_SPD_MASK) || 1064 1064 new_serial.custom_divisor != state->custom_divisor; 1065 1065 if (new_serial.irq || new_serial.port != state->port || 1066 1066 new_serial.xmit_fifo_size != state->xmit_fifo_size) { 1067 - tty_unlock(tty); 1067 + tty_unlock(); 1068 1068 return -EINVAL; 1069 1069 } 1070 1070 ··· 1074 1074 (new_serial.xmit_fifo_size != state->xmit_fifo_size) || 1075 1075 ((new_serial.flags & ~ASYNC_USR_MASK) != 1076 1076 (port->flags & ~ASYNC_USR_MASK))) { 1077 - tty_unlock(tty); 1077 + tty_unlock(); 1078 1078 return -EPERM; 1079 1079 } 1080 1080 port->flags = ((port->flags & ~ASYNC_USR_MASK) | ··· 1084 1084 } 1085 1085 1086 1086 if (new_serial.baud_base < 9600) { 1087 - tty_unlock(tty); 1087 + tty_unlock(); 1088 1088 return -EINVAL; 1089 1089 } 1090 1090 ··· 1116 1116 } 1117 1117 } else 1118 1118 retval = startup(tty, state); 1119 - tty_unlock(tty); 1119 + tty_unlock(); 1120 1120 return retval; 1121 1121 } 1122 1122
+1 -1
drivers/tty/cyclades.c
··· 1599 1599 * If the port is the middle of closing, bail out now 1600 1600 */ 1601 1601 if (tty_hung_up_p(filp) || (info->port.flags & ASYNC_CLOSING)) { 1602 - wait_event_interruptible_tty(tty, info->port.close_wait, 1602 + wait_event_interruptible_tty(info->port.close_wait, 1603 1603 !(info->port.flags & ASYNC_CLOSING)); 1604 1604 return (info->port.flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS; 1605 1605 }
+5 -5
drivers/tty/n_r3964.c
··· 1065 1065 1066 1066 TRACE_L("read()"); 1067 1067 1068 - tty_lock(tty); 1068 + tty_lock(); 1069 1069 1070 1070 pClient = findClient(pInfo, task_pid(current)); 1071 1071 if (pClient) { ··· 1077 1077 goto unlock; 1078 1078 } 1079 1079 /* block until there is a message: */ 1080 - wait_event_interruptible_tty(tty, pInfo->read_wait, 1080 + wait_event_interruptible_tty(pInfo->read_wait, 1081 1081 (pMsg = remove_msg(pInfo, pClient))); 1082 1082 } 1083 1083 ··· 1107 1107 } 1108 1108 ret = -EPERM; 1109 1109 unlock: 1110 - tty_unlock(tty); 1110 + tty_unlock(); 1111 1111 return ret; 1112 1112 } 1113 1113 ··· 1156 1156 pHeader->locks = 0; 1157 1157 pHeader->owner = NULL; 1158 1158 1159 - tty_lock(tty); 1159 + tty_lock(); 1160 1160 1161 1161 pClient = findClient(pInfo, task_pid(current)); 1162 1162 if (pClient) { ··· 1175 1175 add_tx_queue(pInfo, pHeader); 1176 1176 trigger_transmit(pInfo); 1177 1177 1178 - tty_unlock(tty); 1178 + tty_unlock(); 1179 1179 1180 1180 return 0; 1181 1181 }
+11 -12
drivers/tty/pty.c
··· 47 47 wake_up_interruptible(&tty->read_wait); 48 48 wake_up_interruptible(&tty->write_wait); 49 49 tty->packet = 0; 50 - /* Review - krefs on tty_link ?? */ 51 50 if (!tty->link) 52 51 return; 53 52 tty->link->packet = 0; ··· 62 63 mutex_unlock(&devpts_mutex); 63 64 } 64 65 #endif 65 - tty_unlock(tty); 66 + tty_unlock(); 66 67 tty_vhangup(tty->link); 67 - tty_lock(tty); 68 + tty_lock(); 68 69 } 69 70 } 70 71 ··· 615 616 return retval; 616 617 617 618 /* find a device that is not in use. */ 618 - mutex_lock(&devpts_mutex); 619 + tty_lock(); 619 620 index = devpts_new_index(inode); 620 - mutex_unlock(&devpts_mutex); 621 + tty_unlock(); 621 622 if (index < 0) { 622 623 retval = index; 623 624 goto err_file; 624 625 } 625 626 626 627 mutex_lock(&tty_mutex); 628 + mutex_lock(&devpts_mutex); 627 629 tty = tty_init_dev(ptm_driver, index); 630 + mutex_unlock(&devpts_mutex); 631 + tty_lock(); 632 + mutex_unlock(&tty_mutex); 628 633 629 634 if (IS_ERR(tty)) { 630 635 retval = PTR_ERR(tty); 631 636 goto out; 632 637 } 633 - 634 - /* The tty returned here is locked so we can safely 635 - drop the mutex */ 636 - mutex_unlock(&tty_mutex); 637 638 638 639 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ 639 640 ··· 647 648 if (retval) 648 649 goto err_release; 649 650 650 - tty_unlock(tty); 651 + tty_unlock(); 651 652 return 0; 652 653 err_release: 653 - tty_unlock(tty); 654 + tty_unlock(); 654 655 tty_release(inode, filp); 655 656 return retval; 656 657 out: 657 - mutex_unlock(&tty_mutex); 658 658 devpts_kill_index(inode, index); 659 + tty_unlock(); 659 660 err_file: 660 661 tty_free_file(filp); 661 662 return retval;
+4 -4
drivers/tty/serial/crisv10.c
··· 3976 3976 */ 3977 3977 if (tty_hung_up_p(filp) || 3978 3978 (info->flags & ASYNC_CLOSING)) { 3979 - wait_event_interruptible_tty(tty, info->close_wait, 3979 + wait_event_interruptible_tty(info->close_wait, 3980 3980 !(info->flags & ASYNC_CLOSING)); 3981 3981 #ifdef SERIAL_DO_RESTART 3982 3982 if (info->flags & ASYNC_HUP_NOTIFY) ··· 4052 4052 printk("block_til_ready blocking: ttyS%d, count = %d\n", 4053 4053 info->line, info->count); 4054 4054 #endif 4055 - tty_unlock(tty); 4055 + tty_unlock(); 4056 4056 schedule(); 4057 - tty_lock(tty); 4057 + tty_lock(); 4058 4058 } 4059 4059 set_current_state(TASK_RUNNING); 4060 4060 remove_wait_queue(&info->open_wait, &wait); ··· 4115 4115 */ 4116 4116 if (tty_hung_up_p(filp) || 4117 4117 (info->flags & ASYNC_CLOSING)) { 4118 - wait_event_interruptible_tty(tty, info->close_wait, 4118 + wait_event_interruptible_tty(info->close_wait, 4119 4119 !(info->flags & ASYNC_CLOSING)); 4120 4120 #ifdef SERIAL_DO_RESTART 4121 4121 return ((info->flags & ASYNC_HUP_NOTIFY) ?
+2 -2
drivers/tty/synclink.c
··· 3338 3338 printk("%s(%d):block_til_ready blocking on %s count=%d\n", 3339 3339 __FILE__,__LINE__, tty->driver->name, port->count ); 3340 3340 3341 - tty_unlock(tty); 3341 + tty_unlock(); 3342 3342 schedule(); 3343 - tty_lock(tty); 3343 + tty_lock(); 3344 3344 } 3345 3345 3346 3346 set_current_state(TASK_RUNNING);
+2 -2
drivers/tty/synclinkmp.c
··· 3357 3357 printk("%s(%d):%s block_til_ready() count=%d\n", 3358 3358 __FILE__,__LINE__, tty->driver->name, port->count ); 3359 3359 3360 - tty_unlock(tty); 3360 + tty_unlock(); 3361 3361 schedule(); 3362 - tty_lock(tty); 3362 + tty_lock(); 3363 3363 } 3364 3364 3365 3365 set_current_state(TASK_RUNNING);
+27 -40
drivers/tty/tty_io.c
··· 185 185 put_device(tty->dev); 186 186 kfree(tty->write_buf); 187 187 tty_buffer_free_all(tty); 188 - tty->magic = 0xDEADDEAD; 189 188 kfree(tty); 190 189 } 191 190 ··· 573 574 } 574 575 spin_unlock(&redirect_lock); 575 576 576 - tty_lock(tty); 577 + tty_lock(); 577 578 578 579 /* some functions below drop BTM, so we need this bit */ 579 580 set_bit(TTY_HUPPING, &tty->flags); ··· 666 667 clear_bit(TTY_HUPPING, &tty->flags); 667 668 tty_ldisc_enable(tty); 668 669 669 - tty_unlock(tty); 670 + tty_unlock(); 670 671 671 672 if (f) 672 673 fput(f); ··· 1103 1104 { 1104 1105 if (tty) { 1105 1106 mutex_lock(&tty->atomic_write_lock); 1106 - tty_lock(tty); 1107 + tty_lock(); 1107 1108 if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags)) { 1108 - tty_unlock(tty); 1109 + tty_unlock(); 1109 1110 tty->ops->write(tty, msg, strlen(msg)); 1110 1111 } else 1111 - tty_unlock(tty); 1112 + tty_unlock(); 1112 1113 tty_write_unlock(tty); 1113 1114 } 1114 1115 return; ··· 1403 1404 } 1404 1405 initialize_tty_struct(tty, driver, idx); 1405 1406 1406 - tty_lock(tty); 1407 1407 retval = tty_driver_install_tty(driver, tty); 1408 1408 if (retval < 0) 1409 1409 goto err_deinit_tty; ··· 1418 1420 retval = tty_ldisc_setup(tty, tty->link); 1419 1421 if (retval) 1420 1422 goto err_release_tty; 1421 - /* Return the tty locked so that it cannot vanish under the caller */ 1422 1423 return tty; 1423 1424 1424 1425 err_deinit_tty: 1425 - tty_unlock(tty); 1426 1426 deinitialize_tty_struct(tty); 1427 1427 free_tty_struct(tty); 1428 1428 err_module_put: ··· 1429 1433 1430 1434 /* call the tty release_tty routine to clean out this slot */ 1431 1435 err_release_tty: 1432 - tty_unlock(tty); 1433 1436 printk_ratelimited(KERN_INFO "tty_init_dev: ldisc open failed, " 1434 1437 "clearing slot %d\n", idx); 1435 1438 release_tty(tty, idx); ··· 1631 1636 if (tty_paranoia_check(tty, inode, __func__)) 1632 1637 return 0; 1633 1638 1634 - tty_lock(tty); 1639 + tty_lock(); 1635 1640 check_tty_count(tty, __func__); 1636 1641 1637 1642 __tty_fasync(-1, filp, 0); ··· 1640 1645 pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY && 1641 1646 tty->driver->subtype == PTY_TYPE_MASTER); 1642 1647 devpts = (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM) != 0; 1643 - /* Review: parallel close */ 1644 1648 o_tty = tty->link; 1645 1649 1646 1650 if (tty_release_checks(tty, o_tty, idx)) { 1647 - tty_unlock(tty); 1651 + tty_unlock(); 1648 1652 return 0; 1649 1653 } 1650 1654 ··· 1655 1661 if (tty->ops->close) 1656 1662 tty->ops->close(tty, filp); 1657 1663 1658 - tty_unlock(tty); 1664 + tty_unlock(); 1659 1665 /* 1660 1666 * Sanity check: if tty->count is going to zero, there shouldn't be 1661 1667 * any waiters on tty->read_wait or tty->write_wait. We test the ··· 1678 1684 opens on /dev/tty */ 1679 1685 1680 1686 mutex_lock(&tty_mutex); 1681 - tty_lock_pair(tty, o_tty); 1687 + tty_lock(); 1682 1688 tty_closing = tty->count <= 1; 1683 1689 o_tty_closing = o_tty && 1684 1690 (o_tty->count <= (pty_master ? 1 : 0)); ··· 1709 1715 1710 1716 printk(KERN_WARNING "%s: %s: read/write wait queue active!\n", 1711 1717 __func__, tty_name(tty, buf)); 1712 - tty_unlock_pair(tty, o_tty); 1718 + tty_unlock(); 1713 1719 mutex_unlock(&tty_mutex); 1714 1720 schedule(); 1715 1721 } ··· 1772 1778 1773 1779 /* check whether both sides are closing ... */ 1774 1780 if (!tty_closing || (o_tty && !o_tty_closing)) { 1775 - tty_unlock_pair(tty, o_tty); 1781 + tty_unlock(); 1776 1782 return 0; 1777 1783 } 1778 1784 ··· 1785 1791 tty_ldisc_release(tty, o_tty); 1786 1792 /* 1787 1793 * The release_tty function takes care of the details of clearing 1788 - * the slots and preserving the termios structure. The tty_unlock_pair 1789 - * should be safe as we keep a kref while the tty is locked (so the 1790 - * unlock never unlocks a freed tty). 1794 + * the slots and preserving the termios structure. 1791 1795 */ 1792 1796 release_tty(tty, idx); 1793 - tty_unlock_pair(tty, o_tty); 1794 1797 1795 1798 /* Make this pty number available for reallocation */ 1796 1799 if (devpts) 1797 1800 devpts_kill_index(inode, idx); 1801 + tty_unlock(); 1798 1802 return 0; 1799 1803 } 1800 1804 ··· 1896 1904 * Locking: tty_mutex protects tty, tty_lookup_driver and tty_init_dev. 1897 1905 * tty->count should protect the rest. 1898 1906 * ->siglock protects ->signal/->sighand 1899 - * 1900 - * Note: the tty_unlock/lock cases without a ref are only safe due to 1901 - * tty_mutex 1902 1907 */ 1903 1908 1904 1909 static int tty_open(struct inode *inode, struct file *filp) ··· 1919 1930 retval = 0; 1920 1931 1921 1932 mutex_lock(&tty_mutex); 1922 - /* This is protected by the tty_mutex */ 1933 + tty_lock(); 1934 + 1923 1935 tty = tty_open_current_tty(device, filp); 1924 1936 if (IS_ERR(tty)) { 1925 1937 retval = PTR_ERR(tty); ··· 1941 1951 } 1942 1952 1943 1953 if (tty) { 1944 - tty_lock(tty); 1945 1954 retval = tty_reopen(tty); 1946 - if (retval < 0) { 1947 - tty_unlock(tty); 1955 + if (retval) 1948 1956 tty = ERR_PTR(retval); 1949 - } 1950 - } else /* Returns with the tty_lock held for now */ 1957 + } else 1951 1958 tty = tty_init_dev(driver, index); 1952 1959 1953 1960 mutex_unlock(&tty_mutex); 1954 1961 if (driver) 1955 1962 tty_driver_kref_put(driver); 1956 1963 if (IS_ERR(tty)) { 1964 + tty_unlock(); 1957 1965 retval = PTR_ERR(tty); 1958 1966 goto err_file; 1959 1967 } ··· 1980 1992 printk(KERN_DEBUG "%s: error %d in opening %s...\n", __func__, 1981 1993 retval, tty->name); 1982 1994 #endif 1983 - tty_unlock(tty); /* need to call tty_release without BTM */ 1995 + tty_unlock(); /* need to call tty_release without BTM */ 1984 1996 tty_release(inode, filp); 1985 1997 if (retval != -ERESTARTSYS) 1986 1998 return retval; ··· 1992 2004 /* 1993 2005 * Need to reset f_op in case a hangup happened. 1994 2006 */ 2007 + tty_lock(); 1995 2008 if (filp->f_op == &hung_up_tty_fops) 1996 2009 filp->f_op = &tty_fops; 2010 + tty_unlock(); 1997 2011 goto retry_open; 1998 2012 } 1999 - tty_unlock(tty); 2013 + tty_unlock(); 2000 2014 2001 2015 2002 2016 mutex_lock(&tty_mutex); 2003 - tty_lock(tty); 2017 + tty_lock(); 2004 2018 spin_lock_irq(&current->sighand->siglock); 2005 2019 if (!noctty && 2006 2020 current->signal->leader && ··· 2010 2020 tty->session == NULL) 2011 2021 __proc_set_tty(current, tty); 2012 2022 spin_unlock_irq(&current->sighand->siglock); 2013 - tty_unlock(tty); 2023 + tty_unlock(); 2014 2024 mutex_unlock(&tty_mutex); 2015 2025 return 0; 2016 2026 err_unlock: 2027 + tty_unlock(); 2017 2028 mutex_unlock(&tty_mutex); 2018 2029 /* after locks to avoid deadlock */ 2019 2030 if (!IS_ERR_OR_NULL(driver)) ··· 2097 2106 2098 2107 static int tty_fasync(int fd, struct file *filp, int on) 2099 2108 { 2100 - struct tty_struct *tty = file_tty(filp); 2101 2109 int retval; 2102 - 2103 - tty_lock(tty); 2110 + tty_lock(); 2104 2111 retval = __tty_fasync(fd, filp, on); 2105 - tty_unlock(tty); 2106 - 2112 + tty_unlock(); 2107 2113 return retval; 2108 2114 } 2109 2115 ··· 2937 2949 tty->pgrp = NULL; 2938 2950 tty->overrun_time = jiffies; 2939 2951 tty_buffer_init(tty); 2940 - mutex_init(&tty->legacy_mutex); 2941 2952 mutex_init(&tty->termios_mutex); 2942 2953 mutex_init(&tty->ldisc_mutex); 2943 2954 init_waitqueue_head(&tty->write_wait);
+29 -38
drivers/tty/tty_ldisc.c
··· 568 568 if (IS_ERR(new_ldisc)) 569 569 return PTR_ERR(new_ldisc); 570 570 571 - tty_lock(tty); 571 + tty_lock(); 572 572 /* 573 573 * We need to look at the tty locking here for pty/tty pairs 574 574 * when both sides try to change in parallel. ··· 582 582 */ 583 583 584 584 if (tty->ldisc->ops->num == ldisc) { 585 - tty_unlock(tty); 585 + tty_unlock(); 586 586 tty_ldisc_put(new_ldisc); 587 587 return 0; 588 588 } 589 589 590 - tty_unlock(tty); 590 + tty_unlock(); 591 591 /* 592 592 * Problem: What do we do if this blocks ? 593 593 * We could deadlock here ··· 595 595 596 596 tty_wait_until_sent(tty, 0); 597 597 598 - tty_lock(tty); 598 + tty_lock(); 599 599 mutex_lock(&tty->ldisc_mutex); 600 600 601 601 /* ··· 605 605 606 606 while (test_bit(TTY_LDISC_CHANGING, &tty->flags)) { 607 607 mutex_unlock(&tty->ldisc_mutex); 608 - tty_unlock(tty); 608 + tty_unlock(); 609 609 wait_event(tty_ldisc_wait, 610 610 test_bit(TTY_LDISC_CHANGING, &tty->flags) == 0); 611 - tty_lock(tty); 611 + tty_lock(); 612 612 mutex_lock(&tty->ldisc_mutex); 613 613 } 614 614 ··· 623 623 624 624 o_ldisc = tty->ldisc; 625 625 626 - tty_unlock(tty); 626 + tty_unlock(); 627 627 /* 628 628 * Make sure we don't change while someone holds a 629 629 * reference to the line discipline. The TTY_LDISC bit ··· 650 650 651 651 retval = tty_ldisc_wait_idle(tty, 5 * HZ); 652 652 653 - tty_lock(tty); 653 + tty_lock(); 654 654 mutex_lock(&tty->ldisc_mutex); 655 655 656 656 /* handle wait idle failure locked */ ··· 665 665 clear_bit(TTY_LDISC_CHANGING, &tty->flags); 666 666 mutex_unlock(&tty->ldisc_mutex); 667 667 tty_ldisc_put(new_ldisc); 668 - tty_unlock(tty); 668 + tty_unlock(); 669 669 return -EIO; 670 670 } 671 671 ··· 708 708 if (o_work) 709 709 schedule_work(&o_tty->buf.work); 710 710 mutex_unlock(&tty->ldisc_mutex); 711 - tty_unlock(tty); 711 + tty_unlock(); 712 712 return retval; 713 713 } 714 714 ··· 816 816 * need to wait for another function taking the BTM 817 817 */ 818 818 clear_bit(TTY_LDISC, &tty->flags); 819 - tty_unlock(tty); 819 + tty_unlock(); 820 820 cancel_work_sync(&tty->buf.work); 821 821 mutex_unlock(&tty->ldisc_mutex); 822 822 retry: 823 - tty_lock(tty); 823 + tty_lock(); 824 824 mutex_lock(&tty->ldisc_mutex); 825 825 826 826 /* At this point we have a closed ldisc and we want to ··· 831 831 if (atomic_read(&tty->ldisc->users) != 1) { 832 832 char cur_n[TASK_COMM_LEN], tty_n[64]; 833 833 long timeout = 3 * HZ; 834 - tty_unlock(tty); 834 + tty_unlock(); 835 835 836 836 while (tty_ldisc_wait_idle(tty, timeout) == -EBUSY) { 837 837 timeout = MAX_SCHEDULE_TIMEOUT; ··· 894 894 tty_ldisc_enable(tty); 895 895 return 0; 896 896 } 897 - 898 - static void tty_ldisc_kill(struct tty_struct *tty) 899 - { 900 - mutex_lock(&tty->ldisc_mutex); 901 - /* 902 - * Now kill off the ldisc 903 - */ 904 - tty_ldisc_close(tty, tty->ldisc); 905 - tty_ldisc_put(tty->ldisc); 906 - /* Force an oops if we mess this up */ 907 - tty->ldisc = NULL; 908 - 909 - /* Ensure the next open requests the N_TTY ldisc */ 910 - tty_set_termios_ldisc(tty, N_TTY); 911 - mutex_unlock(&tty->ldisc_mutex); 912 - } 913 - 914 897 /** 915 898 * tty_ldisc_release - release line discipline 916 899 * @tty: tty being shut down ··· 912 929 * race with the set_ldisc code path. 913 930 */ 914 931 915 - tty_unlock_pair(tty, o_tty); 932 + tty_unlock(); 916 933 tty_ldisc_halt(tty); 917 934 tty_ldisc_flush_works(tty); 918 - if (o_tty) { 919 - tty_ldisc_halt(o_tty); 920 - tty_ldisc_flush_works(o_tty); 921 - } 922 - tty_lock_pair(tty, o_tty); 935 + tty_lock(); 923 936 937 + mutex_lock(&tty->ldisc_mutex); 938 + /* 939 + * Now kill off the ldisc 940 + */ 941 + tty_ldisc_close(tty, tty->ldisc); 942 + tty_ldisc_put(tty->ldisc); 943 + /* Force an oops if we mess this up */ 944 + tty->ldisc = NULL; 924 945 925 - tty_ldisc_kill(tty); 946 + /* Ensure the next open requests the N_TTY ldisc */ 947 + tty_set_termios_ldisc(tty, N_TTY); 948 + mutex_unlock(&tty->ldisc_mutex); 949 + 950 + /* This will need doing differently if we need to lock */ 926 951 if (o_tty) 927 - tty_ldisc_kill(o_tty); 952 + tty_ldisc_release(o_tty, NULL); 928 953 929 954 /* And the memory resources remaining (buffers, termios) will be 930 955 disposed of when the kref hits zero */
+15 -56
drivers/tty/tty_mutex.c
··· 4 4 #include <linux/semaphore.h> 5 5 #include <linux/sched.h> 6 6 7 - /* Legacy tty mutex glue */ 8 - 9 - enum { 10 - TTY_MUTEX_NORMAL, 11 - TTY_MUTEX_NESTED, 12 - }; 7 + /* 8 + * The 'big tty mutex' 9 + * 10 + * This mutex is taken and released by tty_lock() and tty_unlock(), 11 + * replacing the older big kernel lock. 12 + * It can no longer be taken recursively, and does not get 13 + * released implicitly while sleeping. 14 + * 15 + * Don't use in new code. 16 + */ 17 + static DEFINE_MUTEX(big_tty_mutex); 13 18 14 19 /* 15 20 * Getting the big tty mutex. 16 21 */ 17 - 18 - static void __lockfunc tty_lock_nested(struct tty_struct *tty, 19 - unsigned int subclass) 22 + void __lockfunc tty_lock(void) 20 23 { 21 - if (tty->magic != TTY_MAGIC) { 22 - printk(KERN_ERR "L Bad %p\n", tty); 23 - WARN_ON(1); 24 - return; 25 - } 26 - tty_kref_get(tty); 27 - mutex_lock_nested(&tty->legacy_mutex, subclass); 28 - } 29 - 30 - void __lockfunc tty_lock(struct tty_struct *tty) 31 - { 32 - return tty_lock_nested(tty, TTY_MUTEX_NORMAL); 24 + mutex_lock(&big_tty_mutex); 33 25 } 34 26 EXPORT_SYMBOL(tty_lock); 35 27 36 - void __lockfunc tty_unlock(struct tty_struct *tty) 28 + void __lockfunc tty_unlock(void) 37 29 { 38 - if (tty->magic != TTY_MAGIC) { 39 - printk(KERN_ERR "U Bad %p\n", tty); 40 - WARN_ON(1); 41 - return; 42 - } 43 - mutex_unlock(&tty->legacy_mutex); 44 - tty_kref_put(tty); 30 + mutex_unlock(&big_tty_mutex); 45 31 } 46 32 EXPORT_SYMBOL(tty_unlock); 47 - 48 - /* 49 - * Getting the big tty mutex for a pair of ttys with lock ordering 50 - * On a non pty/tty pair tty2 can be NULL which is just fine. 51 - */ 52 - void __lockfunc tty_lock_pair(struct tty_struct *tty, 53 - struct tty_struct *tty2) 54 - { 55 - if (tty < tty2) { 56 - tty_lock(tty); 57 - tty_lock_nested(tty2, TTY_MUTEX_NESTED); 58 - } else { 59 - if (tty2 && tty2 != tty) 60 - tty_lock(tty2); 61 - tty_lock_nested(tty, TTY_MUTEX_NESTED); 62 - } 63 - } 64 - EXPORT_SYMBOL(tty_lock_pair); 65 - 66 - void __lockfunc tty_unlock_pair(struct tty_struct *tty, 67 - struct tty_struct *tty2) 68 - { 69 - tty_unlock(tty); 70 - if (tty2 && tty2 != tty) 71 - tty_unlock(tty2); 72 - } 73 - EXPORT_SYMBOL(tty_unlock_pair);
+3 -3
drivers/tty/tty_port.c
··· 239 239 240 240 /* block if port is in the process of being closed */ 241 241 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { 242 - wait_event_interruptible_tty(tty, port->close_wait, 242 + wait_event_interruptible_tty(port->close_wait, 243 243 !(port->flags & ASYNC_CLOSING)); 244 244 if (port->flags & ASYNC_HUP_NOTIFY) 245 245 return -EAGAIN; ··· 305 305 retval = -ERESTARTSYS; 306 306 break; 307 307 } 308 - tty_unlock(tty); 308 + tty_unlock(); 309 309 schedule(); 310 - tty_lock(tty); 310 + tty_lock(); 311 311 } 312 312 finish_wait(&port->open_wait, &wait); 313 313
+9 -14
include/linux/tty.h
··· 268 268 struct mutex ldisc_mutex; 269 269 struct tty_ldisc *ldisc; 270 270 271 - struct mutex legacy_mutex; 272 271 struct mutex termios_mutex; 273 272 spinlock_t ctrl_lock; 274 273 /* Termios values are protected by the termios mutex */ ··· 610 611 611 612 /* tty_mutex.c */ 612 613 /* functions for preparation of BKL removal */ 613 - extern void __lockfunc tty_lock(struct tty_struct *tty); 614 - extern void __lockfunc tty_unlock(struct tty_struct *tty); 615 - extern void __lockfunc tty_lock_pair(struct tty_struct *tty, 616 - struct tty_struct *tty2); 617 - extern void __lockfunc tty_unlock_pair(struct tty_struct *tty, 618 - struct tty_struct *tty2); 614 + extern void __lockfunc tty_lock(void) __acquires(tty_lock); 615 + extern void __lockfunc tty_unlock(void) __releases(tty_lock); 619 616 620 617 /* 621 618 * this shall be called only from where BTM is held (like close) ··· 626 631 static inline void tty_wait_until_sent_from_close(struct tty_struct *tty, 627 632 long timeout) 628 633 { 629 - tty_unlock(tty); /* tty->ops->close holds the BTM, drop it while waiting */ 634 + tty_unlock(); /* tty->ops->close holds the BTM, drop it while waiting */ 630 635 tty_wait_until_sent(tty, timeout); 631 - tty_lock(tty); 636 + tty_lock(); 632 637 } 633 638 634 639 /* ··· 643 648 * 644 649 * Do not use in new code. 645 650 */ 646 - #define wait_event_interruptible_tty(tty, wq, condition) \ 651 + #define wait_event_interruptible_tty(wq, condition) \ 647 652 ({ \ 648 653 int __ret = 0; \ 649 654 if (!(condition)) { \ 650 - __wait_event_interruptible_tty(tty, wq, condition, __ret); \ 655 + __wait_event_interruptible_tty(wq, condition, __ret); \ 651 656 } \ 652 657 __ret; \ 653 658 }) 654 659 655 - #define __wait_event_interruptible_tty(tty, wq, condition, ret) \ 660 + #define __wait_event_interruptible_tty(wq, condition, ret) \ 656 661 do { \ 657 662 DEFINE_WAIT(__wait); \ 658 663 \ ··· 661 666 if (condition) \ 662 667 break; \ 663 668 if (!signal_pending(current)) { \ 664 - tty_unlock(tty); \ 669 + tty_unlock(); \ 665 670 schedule(); \ 666 - tty_lock(tty); \ 671 + tty_lock(); \ 667 672 continue; \ 668 673 } \ 669 674 ret = -ERESTARTSYS; \
+2 -2
net/bluetooth/rfcomm/tty.c
··· 710 710 break; 711 711 } 712 712 713 - tty_unlock(tty); 713 + tty_unlock(); 714 714 schedule(); 715 - tty_lock(tty); 715 + tty_lock(); 716 716 } 717 717 set_current_state(TASK_RUNNING); 718 718 remove_wait_queue(&dev->wait, &wait);