diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-06-02 18:21:43 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-06-02 18:21:43 -0400 |
commit | f309532bf3e1cc1b787403d84e3039812a7dbe50 (patch) | |
tree | 6508ac81e94bfc137d1d9a55b973a2e0e0ac007b | |
parent | 233e562eac549f4f719176bbddeb50c3f17a9c8d (diff) |
tty: Revert the tty locking series, it needs more work
This reverts the tty layer change to use per-tty locking, because it's
not correct yet, and fixing it will require some more deep surgery.
The main revert is d29f3ef39be4 ("tty_lock: Localise the lock"), but
there are several smaller commits that built upon it, they also get
reverted here. The list of reverted commits is:
fde86d310886 - tty: add lockdep annotations
8f6576ad476b - tty: fix ldisc lock inversion trace
d3ca8b64b97e - pty: Fix lock inversion
b1d679afd766 - tty: drop the pty lock during hangup
abcefe5fc357 - tty/amiserial: Add missing argument for tty_unlock()
fd11b42e3598 - cris: fix missing tty arg in wait_event_interruptible_tty call
d29f3ef39be4 - tty_lock: Localise the lock
The revert had a trivial conflict in the 68360serial.c staging driver
that got removed in the meantime.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | drivers/tty/amiserial.c | 14 | ||||
-rw-r--r-- | drivers/tty/cyclades.c | 2 | ||||
-rw-r--r-- | drivers/tty/n_r3964.c | 11 | ||||
-rw-r--r-- | drivers/tty/pty.c | 25 | ||||
-rw-r--r-- | drivers/tty/serial/crisv10.c | 8 | ||||
-rw-r--r-- | drivers/tty/synclink.c | 4 | ||||
-rw-r--r-- | drivers/tty/synclink_gt.c | 4 | ||||
-rw-r--r-- | drivers/tty/synclinkmp.c | 4 | ||||
-rw-r--r-- | drivers/tty/tty_io.c | 67 | ||||
-rw-r--r-- | drivers/tty/tty_ldisc.c | 67 | ||||
-rw-r--r-- | drivers/tty/tty_mutex.c | 71 | ||||
-rw-r--r-- | drivers/tty/tty_port.c | 6 | ||||
-rw-r--r-- | include/linux/tty.h | 23 | ||||
-rw-r--r-- | net/bluetooth/rfcomm/tty.c | 4 |
14 files changed, 119 insertions, 191 deletions
diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c index 35819e312624..6cc4358f68c1 100644 --- a/drivers/tty/amiserial.c +++ b/drivers/tty/amiserial.c | |||
@@ -1033,7 +1033,7 @@ static int get_serial_info(struct tty_struct *tty, struct serial_state *state, | |||
1033 | if (!retinfo) | 1033 | if (!retinfo) |
1034 | return -EFAULT; | 1034 | return -EFAULT; |
1035 | memset(&tmp, 0, sizeof(tmp)); | 1035 | memset(&tmp, 0, sizeof(tmp)); |
1036 | tty_lock(tty); | 1036 | tty_lock(); |
1037 | tmp.line = tty->index; | 1037 | tmp.line = tty->index; |
1038 | tmp.port = state->port; | 1038 | tmp.port = state->port; |
1039 | tmp.flags = state->tport.flags; | 1039 | tmp.flags = state->tport.flags; |
@@ -1042,7 +1042,7 @@ static int get_serial_info(struct tty_struct *tty, struct serial_state *state, | |||
1042 | tmp.close_delay = state->tport.close_delay; | 1042 | tmp.close_delay = state->tport.close_delay; |
1043 | tmp.closing_wait = state->tport.closing_wait; | 1043 | tmp.closing_wait = state->tport.closing_wait; |
1044 | tmp.custom_divisor = state->custom_divisor; | 1044 | tmp.custom_divisor = state->custom_divisor; |
1045 | tty_unlock(tty); | 1045 | tty_unlock(); |
1046 | if (copy_to_user(retinfo,&tmp,sizeof(*retinfo))) | 1046 | if (copy_to_user(retinfo,&tmp,sizeof(*retinfo))) |
1047 | return -EFAULT; | 1047 | return -EFAULT; |
1048 | return 0; | 1048 | return 0; |
@@ -1059,12 +1059,12 @@ static int set_serial_info(struct tty_struct *tty, struct serial_state *state, | |||
1059 | if (copy_from_user(&new_serial,new_info,sizeof(new_serial))) | 1059 | if (copy_from_user(&new_serial,new_info,sizeof(new_serial))) |
1060 | return -EFAULT; | 1060 | return -EFAULT; |
1061 | 1061 | ||
1062 | tty_lock(tty); | 1062 | tty_lock(); |
1063 | change_spd = ((new_serial.flags ^ port->flags) & ASYNC_SPD_MASK) || | 1063 | change_spd = ((new_serial.flags ^ port->flags) & ASYNC_SPD_MASK) || |
1064 | new_serial.custom_divisor != state->custom_divisor; | 1064 | new_serial.custom_divisor != state->custom_divisor; |
1065 | if (new_serial.irq || new_serial.port != state->port || | 1065 | if (new_serial.irq || new_serial.port != state->port || |
1066 | new_serial.xmit_fifo_size != state->xmit_fifo_size) { | 1066 | new_serial.xmit_fifo_size != state->xmit_fifo_size) { |
1067 | tty_unlock(tty); | 1067 | tty_unlock(); |
1068 | return -EINVAL; | 1068 | return -EINVAL; |
1069 | } | 1069 | } |
1070 | 1070 | ||
@@ -1074,7 +1074,7 @@ static int set_serial_info(struct tty_struct *tty, struct serial_state *state, | |||
1074 | (new_serial.xmit_fifo_size != state->xmit_fifo_size) || | 1074 | (new_serial.xmit_fifo_size != state->xmit_fifo_size) || |
1075 | ((new_serial.flags & ~ASYNC_USR_MASK) != | 1075 | ((new_serial.flags & ~ASYNC_USR_MASK) != |
1076 | (port->flags & ~ASYNC_USR_MASK))) { | 1076 | (port->flags & ~ASYNC_USR_MASK))) { |
1077 | tty_unlock(tty); | 1077 | tty_unlock(); |
1078 | return -EPERM; | 1078 | return -EPERM; |
1079 | } | 1079 | } |
1080 | port->flags = ((port->flags & ~ASYNC_USR_MASK) | | 1080 | port->flags = ((port->flags & ~ASYNC_USR_MASK) | |
@@ -1084,7 +1084,7 @@ static int set_serial_info(struct tty_struct *tty, struct serial_state *state, | |||
1084 | } | 1084 | } |
1085 | 1085 | ||
1086 | if (new_serial.baud_base < 9600) { | 1086 | if (new_serial.baud_base < 9600) { |
1087 | tty_unlock(tty); | 1087 | tty_unlock(); |
1088 | return -EINVAL; | 1088 | return -EINVAL; |
1089 | } | 1089 | } |
1090 | 1090 | ||
@@ -1116,7 +1116,7 @@ check_and_exit: | |||
1116 | } | 1116 | } |
1117 | } else | 1117 | } else |
1118 | retval = startup(tty, state); | 1118 | retval = startup(tty, state); |
1119 | tty_unlock(tty); | 1119 | tty_unlock(); |
1120 | return retval; | 1120 | return retval; |
1121 | } | 1121 | } |
1122 | 1122 | ||
diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c index 6984e1a2686a..e61cabdd69df 100644 --- a/drivers/tty/cyclades.c +++ b/drivers/tty/cyclades.c | |||
@@ -1599,7 +1599,7 @@ static int cy_open(struct tty_struct *tty, struct file *filp) | |||
1599 | * If the port is the middle of closing, bail out now | 1599 | * If the port is the middle of closing, bail out now |
1600 | */ | 1600 | */ |
1601 | if (tty_hung_up_p(filp) || (info->port.flags & ASYNC_CLOSING)) { | 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 | !(info->port.flags & ASYNC_CLOSING)); | 1603 | !(info->port.flags & ASYNC_CLOSING)); |
1604 | return (info->port.flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS; | 1604 | return (info->port.flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS; |
1605 | } | 1605 | } |
diff --git a/drivers/tty/n_r3964.c b/drivers/tty/n_r3964.c index 656ad93bbc96..5c6c31459a2f 100644 --- a/drivers/tty/n_r3964.c +++ b/drivers/tty/n_r3964.c | |||
@@ -1065,8 +1065,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file, | |||
1065 | 1065 | ||
1066 | TRACE_L("read()"); | 1066 | TRACE_L("read()"); |
1067 | 1067 | ||
1068 | /* FIXME: should use a private lock */ | 1068 | tty_lock(); |
1069 | tty_lock(tty); | ||
1070 | 1069 | ||
1071 | pClient = findClient(pInfo, task_pid(current)); | 1070 | pClient = findClient(pInfo, task_pid(current)); |
1072 | if (pClient) { | 1071 | if (pClient) { |
@@ -1078,7 +1077,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file, | |||
1078 | goto unlock; | 1077 | goto unlock; |
1079 | } | 1078 | } |
1080 | /* block until there is a message: */ | 1079 | /* block until there is a message: */ |
1081 | wait_event_interruptible_tty(tty, pInfo->read_wait, | 1080 | wait_event_interruptible_tty(pInfo->read_wait, |
1082 | (pMsg = remove_msg(pInfo, pClient))); | 1081 | (pMsg = remove_msg(pInfo, pClient))); |
1083 | } | 1082 | } |
1084 | 1083 | ||
@@ -1108,7 +1107,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file, | |||
1108 | } | 1107 | } |
1109 | ret = -EPERM; | 1108 | ret = -EPERM; |
1110 | unlock: | 1109 | unlock: |
1111 | tty_unlock(tty); | 1110 | tty_unlock(); |
1112 | return ret; | 1111 | return ret; |
1113 | } | 1112 | } |
1114 | 1113 | ||
@@ -1157,7 +1156,7 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file, | |||
1157 | pHeader->locks = 0; | 1156 | pHeader->locks = 0; |
1158 | pHeader->owner = NULL; | 1157 | pHeader->owner = NULL; |
1159 | 1158 | ||
1160 | tty_lock(tty); | 1159 | tty_lock(); |
1161 | 1160 | ||
1162 | pClient = findClient(pInfo, task_pid(current)); | 1161 | pClient = findClient(pInfo, task_pid(current)); |
1163 | if (pClient) { | 1162 | if (pClient) { |
@@ -1176,7 +1175,7 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file, | |||
1176 | add_tx_queue(pInfo, pHeader); | 1175 | add_tx_queue(pInfo, pHeader); |
1177 | trigger_transmit(pInfo); | 1176 | trigger_transmit(pInfo); |
1178 | 1177 | ||
1179 | tty_unlock(tty); | 1178 | tty_unlock(); |
1180 | 1179 | ||
1181 | return 0; | 1180 | return 0; |
1182 | } | 1181 | } |
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c index 65c7c62c7aae..5505ffc91da4 100644 --- a/drivers/tty/pty.c +++ b/drivers/tty/pty.c | |||
@@ -47,7 +47,6 @@ static void pty_close(struct tty_struct *tty, struct file *filp) | |||
47 | wake_up_interruptible(&tty->read_wait); | 47 | wake_up_interruptible(&tty->read_wait); |
48 | wake_up_interruptible(&tty->write_wait); | 48 | wake_up_interruptible(&tty->write_wait); |
49 | tty->packet = 0; | 49 | tty->packet = 0; |
50 | /* Review - krefs on tty_link ?? */ | ||
51 | if (!tty->link) | 50 | if (!tty->link) |
52 | return; | 51 | return; |
53 | tty->link->packet = 0; | 52 | tty->link->packet = 0; |
@@ -63,9 +62,9 @@ static void pty_close(struct tty_struct *tty, struct file *filp) | |||
63 | mutex_unlock(&devpts_mutex); | 62 | mutex_unlock(&devpts_mutex); |
64 | } | 63 | } |
65 | #endif | 64 | #endif |
66 | tty_unlock(tty); | 65 | tty_unlock(); |
67 | tty_vhangup(tty->link); | 66 | tty_vhangup(tty->link); |
68 | tty_lock(tty); | 67 | tty_lock(); |
69 | } | 68 | } |
70 | } | 69 | } |
71 | 70 | ||
@@ -623,27 +622,26 @@ static int ptmx_open(struct inode *inode, struct file *filp) | |||
623 | return retval; | 622 | return retval; |
624 | 623 | ||
625 | /* find a device that is not in use. */ | 624 | /* find a device that is not in use. */ |
626 | mutex_lock(&devpts_mutex); | 625 | tty_lock(); |
627 | index = devpts_new_index(inode); | 626 | index = devpts_new_index(inode); |
627 | tty_unlock(); | ||
628 | if (index < 0) { | 628 | if (index < 0) { |
629 | retval = index; | 629 | retval = index; |
630 | goto err_file; | 630 | goto err_file; |
631 | } | 631 | } |
632 | 632 | ||
633 | mutex_unlock(&devpts_mutex); | ||
634 | |||
635 | mutex_lock(&tty_mutex); | 633 | mutex_lock(&tty_mutex); |
634 | mutex_lock(&devpts_mutex); | ||
636 | tty = tty_init_dev(ptm_driver, index); | 635 | tty = tty_init_dev(ptm_driver, index); |
636 | mutex_unlock(&devpts_mutex); | ||
637 | tty_lock(); | ||
638 | mutex_unlock(&tty_mutex); | ||
637 | 639 | ||
638 | if (IS_ERR(tty)) { | 640 | if (IS_ERR(tty)) { |
639 | retval = PTR_ERR(tty); | 641 | retval = PTR_ERR(tty); |
640 | goto out; | 642 | goto out; |
641 | } | 643 | } |
642 | 644 | ||
643 | /* The tty returned here is locked so we can safely | ||
644 | drop the mutex */ | ||
645 | mutex_unlock(&tty_mutex); | ||
646 | |||
647 | set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ | 645 | set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ |
648 | 646 | ||
649 | tty_add_file(tty, filp); | 647 | tty_add_file(tty, filp); |
@@ -656,17 +654,16 @@ static int ptmx_open(struct inode *inode, struct file *filp) | |||
656 | if (retval) | 654 | if (retval) |
657 | goto err_release; | 655 | goto err_release; |
658 | 656 | ||
659 | tty_unlock(tty); | 657 | tty_unlock(); |
660 | return 0; | 658 | return 0; |
661 | err_release: | 659 | err_release: |
662 | tty_unlock(tty); | 660 | tty_unlock(); |
663 | tty_release(inode, filp); | 661 | tty_release(inode, filp); |
664 | return retval; | 662 | return retval; |
665 | out: | 663 | out: |
666 | mutex_unlock(&tty_mutex); | ||
667 | devpts_kill_index(inode, index); | 664 | devpts_kill_index(inode, index); |
665 | tty_unlock(); | ||
668 | err_file: | 666 | err_file: |
669 | mutex_unlock(&devpts_mutex); | ||
670 | tty_free_file(filp); | 667 | tty_free_file(filp); |
671 | return retval; | 668 | return retval; |
672 | } | 669 | } |
diff --git a/drivers/tty/serial/crisv10.c b/drivers/tty/serial/crisv10.c index 7264d4d26717..80b6b1b1f725 100644 --- a/drivers/tty/serial/crisv10.c +++ b/drivers/tty/serial/crisv10.c | |||
@@ -3976,7 +3976,7 @@ block_til_ready(struct tty_struct *tty, struct file * filp, | |||
3976 | */ | 3976 | */ |
3977 | if (tty_hung_up_p(filp) || | 3977 | if (tty_hung_up_p(filp) || |
3978 | (info->flags & ASYNC_CLOSING)) { | 3978 | (info->flags & ASYNC_CLOSING)) { |
3979 | wait_event_interruptible_tty(tty, info->close_wait, | 3979 | wait_event_interruptible_tty(info->close_wait, |
3980 | !(info->flags & ASYNC_CLOSING)); | 3980 | !(info->flags & ASYNC_CLOSING)); |
3981 | #ifdef SERIAL_DO_RESTART | 3981 | #ifdef SERIAL_DO_RESTART |
3982 | if (info->flags & ASYNC_HUP_NOTIFY) | 3982 | if (info->flags & ASYNC_HUP_NOTIFY) |
@@ -4052,9 +4052,9 @@ block_til_ready(struct tty_struct *tty, struct file * filp, | |||
4052 | printk("block_til_ready blocking: ttyS%d, count = %d\n", | 4052 | printk("block_til_ready blocking: ttyS%d, count = %d\n", |
4053 | info->line, info->count); | 4053 | info->line, info->count); |
4054 | #endif | 4054 | #endif |
4055 | tty_unlock(tty); | 4055 | tty_unlock(); |
4056 | schedule(); | 4056 | schedule(); |
4057 | tty_lock(tty); | 4057 | tty_lock(); |
4058 | } | 4058 | } |
4059 | set_current_state(TASK_RUNNING); | 4059 | set_current_state(TASK_RUNNING); |
4060 | remove_wait_queue(&info->open_wait, &wait); | 4060 | remove_wait_queue(&info->open_wait, &wait); |
@@ -4115,7 +4115,7 @@ rs_open(struct tty_struct *tty, struct file * filp) | |||
4115 | */ | 4115 | */ |
4116 | if (tty_hung_up_p(filp) || | 4116 | if (tty_hung_up_p(filp) || |
4117 | (info->flags & ASYNC_CLOSING)) { | 4117 | (info->flags & ASYNC_CLOSING)) { |
4118 | wait_event_interruptible_tty(tty, info->close_wait, | 4118 | wait_event_interruptible_tty(info->close_wait, |
4119 | !(info->flags & ASYNC_CLOSING)); | 4119 | !(info->flags & ASYNC_CLOSING)); |
4120 | #ifdef SERIAL_DO_RESTART | 4120 | #ifdef SERIAL_DO_RESTART |
4121 | return ((info->flags & ASYNC_HUP_NOTIFY) ? | 4121 | return ((info->flags & ASYNC_HUP_NOTIFY) ? |
diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c index 5ed0daae6564..593d40ad0a6b 100644 --- a/drivers/tty/synclink.c +++ b/drivers/tty/synclink.c | |||
@@ -3338,9 +3338,9 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp, | |||
3338 | printk("%s(%d):block_til_ready blocking on %s count=%d\n", | 3338 | printk("%s(%d):block_til_ready blocking on %s count=%d\n", |
3339 | __FILE__,__LINE__, tty->driver->name, port->count ); | 3339 | __FILE__,__LINE__, tty->driver->name, port->count ); |
3340 | 3340 | ||
3341 | tty_unlock(tty); | 3341 | tty_unlock(); |
3342 | schedule(); | 3342 | schedule(); |
3343 | tty_lock(tty); | 3343 | tty_lock(); |
3344 | } | 3344 | } |
3345 | 3345 | ||
3346 | set_current_state(TASK_RUNNING); | 3346 | set_current_state(TASK_RUNNING); |
diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c index 45b43f11ca39..aa1debf97cc7 100644 --- a/drivers/tty/synclink_gt.c +++ b/drivers/tty/synclink_gt.c | |||
@@ -3336,9 +3336,9 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, | |||
3336 | } | 3336 | } |
3337 | 3337 | ||
3338 | DBGINFO(("%s block_til_ready wait\n", tty->driver->name)); | 3338 | DBGINFO(("%s block_til_ready wait\n", tty->driver->name)); |
3339 | tty_unlock(tty); | 3339 | tty_unlock(); |
3340 | schedule(); | 3340 | schedule(); |
3341 | tty_lock(tty); | 3341 | tty_lock(); |
3342 | } | 3342 | } |
3343 | 3343 | ||
3344 | set_current_state(TASK_RUNNING); | 3344 | set_current_state(TASK_RUNNING); |
diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c index 4a1e4f07765b..a3dddc12d2fe 100644 --- a/drivers/tty/synclinkmp.c +++ b/drivers/tty/synclinkmp.c | |||
@@ -3357,9 +3357,9 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, | |||
3357 | printk("%s(%d):%s block_til_ready() count=%d\n", | 3357 | printk("%s(%d):%s block_til_ready() count=%d\n", |
3358 | __FILE__,__LINE__, tty->driver->name, port->count ); | 3358 | __FILE__,__LINE__, tty->driver->name, port->count ); |
3359 | 3359 | ||
3360 | tty_unlock(tty); | 3360 | tty_unlock(); |
3361 | schedule(); | 3361 | schedule(); |
3362 | tty_lock(tty); | 3362 | tty_lock(); |
3363 | } | 3363 | } |
3364 | 3364 | ||
3365 | set_current_state(TASK_RUNNING); | 3365 | set_current_state(TASK_RUNNING); |
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); |
diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c index ba8be396a621..9911eb6b34cd 100644 --- a/drivers/tty/tty_ldisc.c +++ b/drivers/tty/tty_ldisc.c | |||
@@ -568,7 +568,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) | |||
568 | if (IS_ERR(new_ldisc)) | 568 | if (IS_ERR(new_ldisc)) |
569 | return PTR_ERR(new_ldisc); | 569 | return PTR_ERR(new_ldisc); |
570 | 570 | ||
571 | tty_lock(tty); | 571 | tty_lock(); |
572 | /* | 572 | /* |
573 | * We need to look at the tty locking here for pty/tty pairs | 573 | * We need to look at the tty locking here for pty/tty pairs |
574 | * when both sides try to change in parallel. | 574 | * when both sides try to change in parallel. |
@@ -582,12 +582,12 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) | |||
582 | */ | 582 | */ |
583 | 583 | ||
584 | if (tty->ldisc->ops->num == ldisc) { | 584 | if (tty->ldisc->ops->num == ldisc) { |
585 | tty_unlock(tty); | 585 | tty_unlock(); |
586 | tty_ldisc_put(new_ldisc); | 586 | tty_ldisc_put(new_ldisc); |
587 | return 0; | 587 | return 0; |
588 | } | 588 | } |
589 | 589 | ||
590 | tty_unlock(tty); | 590 | tty_unlock(); |
591 | /* | 591 | /* |
592 | * Problem: What do we do if this blocks ? | 592 | * Problem: What do we do if this blocks ? |
593 | * We could deadlock here | 593 | * We could deadlock here |
@@ -595,7 +595,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) | |||
595 | 595 | ||
596 | tty_wait_until_sent(tty, 0); | 596 | tty_wait_until_sent(tty, 0); |
597 | 597 | ||
598 | tty_lock(tty); | 598 | tty_lock(); |
599 | mutex_lock(&tty->ldisc_mutex); | 599 | mutex_lock(&tty->ldisc_mutex); |
600 | 600 | ||
601 | /* | 601 | /* |
@@ -605,10 +605,10 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) | |||
605 | 605 | ||
606 | while (test_bit(TTY_LDISC_CHANGING, &tty->flags)) { | 606 | while (test_bit(TTY_LDISC_CHANGING, &tty->flags)) { |
607 | mutex_unlock(&tty->ldisc_mutex); | 607 | mutex_unlock(&tty->ldisc_mutex); |
608 | tty_unlock(tty); | 608 | tty_unlock(); |
609 | wait_event(tty_ldisc_wait, | 609 | wait_event(tty_ldisc_wait, |
610 | test_bit(TTY_LDISC_CHANGING, &tty->flags) == 0); | 610 | test_bit(TTY_LDISC_CHANGING, &tty->flags) == 0); |
611 | tty_lock(tty); | 611 | tty_lock(); |
612 | mutex_lock(&tty->ldisc_mutex); | 612 | mutex_lock(&tty->ldisc_mutex); |
613 | } | 613 | } |
614 | 614 | ||
@@ -623,7 +623,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) | |||
623 | 623 | ||
624 | o_ldisc = tty->ldisc; | 624 | o_ldisc = tty->ldisc; |
625 | 625 | ||
626 | tty_unlock(tty); | 626 | tty_unlock(); |
627 | /* | 627 | /* |
628 | * Make sure we don't change while someone holds a | 628 | * Make sure we don't change while someone holds a |
629 | * reference to the line discipline. The TTY_LDISC bit | 629 | * reference to the line discipline. The TTY_LDISC bit |
@@ -650,7 +650,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) | |||
650 | 650 | ||
651 | retval = tty_ldisc_wait_idle(tty, 5 * HZ); | 651 | retval = tty_ldisc_wait_idle(tty, 5 * HZ); |
652 | 652 | ||
653 | tty_lock(tty); | 653 | tty_lock(); |
654 | mutex_lock(&tty->ldisc_mutex); | 654 | mutex_lock(&tty->ldisc_mutex); |
655 | 655 | ||
656 | /* handle wait idle failure locked */ | 656 | /* handle wait idle failure locked */ |
@@ -665,7 +665,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) | |||
665 | clear_bit(TTY_LDISC_CHANGING, &tty->flags); | 665 | clear_bit(TTY_LDISC_CHANGING, &tty->flags); |
666 | mutex_unlock(&tty->ldisc_mutex); | 666 | mutex_unlock(&tty->ldisc_mutex); |
667 | tty_ldisc_put(new_ldisc); | 667 | tty_ldisc_put(new_ldisc); |
668 | tty_unlock(tty); | 668 | tty_unlock(); |
669 | return -EIO; | 669 | return -EIO; |
670 | } | 670 | } |
671 | 671 | ||
@@ -708,7 +708,7 @@ enable: | |||
708 | if (o_work) | 708 | if (o_work) |
709 | schedule_work(&o_tty->buf.work); | 709 | schedule_work(&o_tty->buf.work); |
710 | mutex_unlock(&tty->ldisc_mutex); | 710 | mutex_unlock(&tty->ldisc_mutex); |
711 | tty_unlock(tty); | 711 | tty_unlock(); |
712 | return retval; | 712 | return retval; |
713 | } | 713 | } |
714 | 714 | ||
@@ -816,11 +816,11 @@ void tty_ldisc_hangup(struct tty_struct *tty) | |||
816 | * need to wait for another function taking the BTM | 816 | * need to wait for another function taking the BTM |
817 | */ | 817 | */ |
818 | clear_bit(TTY_LDISC, &tty->flags); | 818 | clear_bit(TTY_LDISC, &tty->flags); |
819 | tty_unlock(tty); | 819 | tty_unlock(); |
820 | cancel_work_sync(&tty->buf.work); | 820 | cancel_work_sync(&tty->buf.work); |
821 | mutex_unlock(&tty->ldisc_mutex); | 821 | mutex_unlock(&tty->ldisc_mutex); |
822 | retry: | 822 | retry: |
823 | tty_lock(tty); | 823 | tty_lock(); |
824 | mutex_lock(&tty->ldisc_mutex); | 824 | mutex_lock(&tty->ldisc_mutex); |
825 | 825 | ||
826 | /* At this point we have a closed ldisc and we want to | 826 | /* At this point we have a closed ldisc and we want to |
@@ -831,7 +831,7 @@ retry: | |||
831 | if (atomic_read(&tty->ldisc->users) != 1) { | 831 | if (atomic_read(&tty->ldisc->users) != 1) { |
832 | char cur_n[TASK_COMM_LEN], tty_n[64]; | 832 | char cur_n[TASK_COMM_LEN], tty_n[64]; |
833 | long timeout = 3 * HZ; | 833 | long timeout = 3 * HZ; |
834 | tty_unlock(tty); | 834 | tty_unlock(); |
835 | 835 | ||
836 | while (tty_ldisc_wait_idle(tty, timeout) == -EBUSY) { | 836 | while (tty_ldisc_wait_idle(tty, timeout) == -EBUSY) { |
837 | timeout = MAX_SCHEDULE_TIMEOUT; | 837 | timeout = MAX_SCHEDULE_TIMEOUT; |
@@ -894,23 +894,6 @@ int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty) | |||
894 | tty_ldisc_enable(tty); | 894 | tty_ldisc_enable(tty); |
895 | return 0; | 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 | * tty_ldisc_release - release line discipline | 898 | * tty_ldisc_release - release line discipline |
916 | * @tty: tty being shut down | 899 | * @tty: tty being shut down |
@@ -929,19 +912,27 @@ void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty) | |||
929 | * race with the set_ldisc code path. | 912 | * race with the set_ldisc code path. |
930 | */ | 913 | */ |
931 | 914 | ||
932 | tty_unlock_pair(tty, o_tty); | 915 | tty_unlock(); |
933 | tty_ldisc_halt(tty); | 916 | tty_ldisc_halt(tty); |
934 | tty_ldisc_flush_works(tty); | 917 | tty_ldisc_flush_works(tty); |
935 | if (o_tty) { | 918 | tty_lock(); |
936 | tty_ldisc_halt(o_tty); | ||
937 | tty_ldisc_flush_works(o_tty); | ||
938 | } | ||
939 | tty_lock_pair(tty, o_tty); | ||
940 | 919 | ||
920 | mutex_lock(&tty->ldisc_mutex); | ||
921 | /* | ||
922 | * Now kill off the ldisc | ||
923 | */ | ||
924 | tty_ldisc_close(tty, tty->ldisc); | ||
925 | tty_ldisc_put(tty->ldisc); | ||
926 | /* Force an oops if we mess this up */ | ||
927 | tty->ldisc = NULL; | ||
928 | |||
929 | /* Ensure the next open requests the N_TTY ldisc */ | ||
930 | tty_set_termios_ldisc(tty, N_TTY); | ||
931 | mutex_unlock(&tty->ldisc_mutex); | ||
941 | 932 | ||
942 | tty_ldisc_kill(tty); | 933 | /* This will need doing differently if we need to lock */ |
943 | if (o_tty) | 934 | if (o_tty) |
944 | tty_ldisc_kill(o_tty); | 935 | tty_ldisc_release(o_tty, NULL); |
945 | 936 | ||
946 | /* And the memory resources remaining (buffers, termios) will be | 937 | /* And the memory resources remaining (buffers, termios) will be |
947 | disposed of when the kref hits zero */ | 938 | disposed of when the kref hits zero */ |
diff --git a/drivers/tty/tty_mutex.c b/drivers/tty/tty_mutex.c index 67feac9e6ebb..9ff986c32a21 100644 --- a/drivers/tty/tty_mutex.c +++ b/drivers/tty/tty_mutex.c | |||
@@ -4,70 +4,29 @@ | |||
4 | #include <linux/semaphore.h> | 4 | #include <linux/semaphore.h> |
5 | #include <linux/sched.h> | 5 | #include <linux/sched.h> |
6 | 6 | ||
7 | /* Legacy tty mutex glue */ | 7 | /* |
8 | 8 | * The 'big tty mutex' | |
9 | enum { | 9 | * |
10 | TTY_MUTEX_NORMAL, | 10 | * This mutex is taken and released by tty_lock() and tty_unlock(), |
11 | TTY_MUTEX_NESTED, | 11 | * replacing the older big kernel lock. |
12 | }; | 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 | * Getting the big tty mutex. | 20 | * Getting the big tty mutex. |
16 | */ | 21 | */ |
17 | 22 | void __lockfunc tty_lock(void) | |
18 | static void __lockfunc tty_lock_nested(struct tty_struct *tty, | ||
19 | unsigned int subclass) | ||
20 | { | 23 | { |
21 | if (tty->magic != TTY_MAGIC) { | 24 | mutex_lock(&big_tty_mutex); |
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); | ||
33 | } | 25 | } |
34 | EXPORT_SYMBOL(tty_lock); | 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) { | 30 | mutex_unlock(&big_tty_mutex); |
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); | ||
45 | } | 31 | } |
46 | EXPORT_SYMBOL(tty_unlock); | 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); | ||
diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c index d9cca95a5452..bf6e238146ae 100644 --- a/drivers/tty/tty_port.c +++ b/drivers/tty/tty_port.c | |||
@@ -230,7 +230,7 @@ int tty_port_block_til_ready(struct tty_port *port, | |||
230 | 230 | ||
231 | /* block if port is in the process of being closed */ | 231 | /* block if port is in the process of being closed */ |
232 | if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { | 232 | if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { |
233 | wait_event_interruptible_tty(tty, port->close_wait, | 233 | wait_event_interruptible_tty(port->close_wait, |
234 | !(port->flags & ASYNC_CLOSING)); | 234 | !(port->flags & ASYNC_CLOSING)); |
235 | if (port->flags & ASYNC_HUP_NOTIFY) | 235 | if (port->flags & ASYNC_HUP_NOTIFY) |
236 | return -EAGAIN; | 236 | return -EAGAIN; |
@@ -296,9 +296,9 @@ int tty_port_block_til_ready(struct tty_port *port, | |||
296 | retval = -ERESTARTSYS; | 296 | retval = -ERESTARTSYS; |
297 | break; | 297 | break; |
298 | } | 298 | } |
299 | tty_unlock(tty); | 299 | tty_unlock(); |
300 | schedule(); | 300 | schedule(); |
301 | tty_lock(tty); | 301 | tty_lock(); |
302 | } | 302 | } |
303 | finish_wait(&port->open_wait, &wait); | 303 | finish_wait(&port->open_wait, &wait); |
304 | 304 | ||
diff --git a/include/linux/tty.h b/include/linux/tty.h index 4990ef2b1fb7..9f47ab540f65 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h | |||
@@ -268,7 +268,6 @@ struct tty_struct { | |||
268 | struct mutex ldisc_mutex; | 268 | struct mutex ldisc_mutex; |
269 | struct tty_ldisc *ldisc; | 269 | struct tty_ldisc *ldisc; |
270 | 270 | ||
271 | struct mutex legacy_mutex; | ||
272 | struct mutex termios_mutex; | 271 | struct mutex termios_mutex; |
273 | spinlock_t ctrl_lock; | 272 | spinlock_t ctrl_lock; |
274 | /* Termios values are protected by the termios mutex */ | 273 | /* Termios values are protected by the termios mutex */ |
@@ -606,12 +605,8 @@ extern long vt_compat_ioctl(struct tty_struct *tty, | |||
606 | 605 | ||
607 | /* tty_mutex.c */ | 606 | /* tty_mutex.c */ |
608 | /* functions for preparation of BKL removal */ | 607 | /* functions for preparation of BKL removal */ |
609 | extern void __lockfunc tty_lock(struct tty_struct *tty); | 608 | extern void __lockfunc tty_lock(void) __acquires(tty_lock); |
610 | extern void __lockfunc tty_unlock(struct tty_struct *tty); | 609 | extern void __lockfunc tty_unlock(void) __releases(tty_lock); |
611 | extern void __lockfunc tty_lock_pair(struct tty_struct *tty, | ||
612 | struct tty_struct *tty2); | ||
613 | extern void __lockfunc tty_unlock_pair(struct tty_struct *tty, | ||
614 | struct tty_struct *tty2); | ||
615 | 610 | ||
616 | /* | 611 | /* |
617 | * this shall be called only from where BTM is held (like close) | 612 | * this shall be called only from where BTM is held (like close) |
@@ -626,9 +621,9 @@ extern void __lockfunc tty_unlock_pair(struct tty_struct *tty, | |||
626 | static inline void tty_wait_until_sent_from_close(struct tty_struct *tty, | 621 | static inline void tty_wait_until_sent_from_close(struct tty_struct *tty, |
627 | long timeout) | 622 | long timeout) |
628 | { | 623 | { |
629 | tty_unlock(tty); /* tty->ops->close holds the BTM, drop it while waiting */ | 624 | tty_unlock(); /* tty->ops->close holds the BTM, drop it while waiting */ |
630 | tty_wait_until_sent(tty, timeout); | 625 | tty_wait_until_sent(tty, timeout); |
631 | tty_lock(tty); | 626 | tty_lock(); |
632 | } | 627 | } |
633 | 628 | ||
634 | /* | 629 | /* |
@@ -643,16 +638,16 @@ static inline void tty_wait_until_sent_from_close(struct tty_struct *tty, | |||
643 | * | 638 | * |
644 | * Do not use in new code. | 639 | * Do not use in new code. |
645 | */ | 640 | */ |
646 | #define wait_event_interruptible_tty(tty, wq, condition) \ | 641 | #define wait_event_interruptible_tty(wq, condition) \ |
647 | ({ \ | 642 | ({ \ |
648 | int __ret = 0; \ | 643 | int __ret = 0; \ |
649 | if (!(condition)) { \ | 644 | if (!(condition)) { \ |
650 | __wait_event_interruptible_tty(tty, wq, condition, __ret); \ | 645 | __wait_event_interruptible_tty(wq, condition, __ret); \ |
651 | } \ | 646 | } \ |
652 | __ret; \ | 647 | __ret; \ |
653 | }) | 648 | }) |
654 | 649 | ||
655 | #define __wait_event_interruptible_tty(tty, wq, condition, ret) \ | 650 | #define __wait_event_interruptible_tty(wq, condition, ret) \ |
656 | do { \ | 651 | do { \ |
657 | DEFINE_WAIT(__wait); \ | 652 | DEFINE_WAIT(__wait); \ |
658 | \ | 653 | \ |
@@ -661,9 +656,9 @@ do { \ | |||
661 | if (condition) \ | 656 | if (condition) \ |
662 | break; \ | 657 | break; \ |
663 | if (!signal_pending(current)) { \ | 658 | if (!signal_pending(current)) { \ |
664 | tty_unlock(tty); \ | 659 | tty_unlock(); \ |
665 | schedule(); \ | 660 | schedule(); \ |
666 | tty_lock(tty); \ | 661 | tty_lock(); \ |
667 | continue; \ | 662 | continue; \ |
668 | } \ | 663 | } \ |
669 | ret = -ERESTARTSYS; \ | 664 | ret = -ERESTARTSYS; \ |
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c index aa5d73b786ac..d1820ff14aee 100644 --- a/net/bluetooth/rfcomm/tty.c +++ b/net/bluetooth/rfcomm/tty.c | |||
@@ -710,9 +710,9 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp) | |||
710 | break; | 710 | break; |
711 | } | 711 | } |
712 | 712 | ||
713 | tty_unlock(tty); | 713 | tty_unlock(); |
714 | schedule(); | 714 | schedule(); |
715 | tty_lock(tty); | 715 | tty_lock(); |
716 | } | 716 | } |
717 | set_current_state(TASK_RUNNING); | 717 | set_current_state(TASK_RUNNING); |
718 | remove_wait_queue(&dev->wait, &wait); | 718 | remove_wait_queue(&dev->wait, &wait); |