Skip to content

Commit 0bfd464

Browse files
peterhurleygregkh
authored andcommitted
tty: Wait interruptibly for tty lock on reopen
Allow a signal to interrupt the wait for a tty reopen; eg., if the tty has starting final close and is waiting for the device to drain. Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Cc: stable <stable@vger.kernel.org> # 4.4 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 92e963f commit 0bfd464

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

drivers/tty/tty_io.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2065,7 +2065,12 @@ static int tty_open(struct inode *inode, struct file *filp)
20652065

20662066
if (tty) {
20672067
mutex_unlock(&tty_mutex);
2068-
tty_lock(tty);
2068+
retval = tty_lock_interruptible(tty);
2069+
if (retval) {
2070+
if (retval == -EINTR)
2071+
retval = -ERESTARTSYS;
2072+
goto err_unref;
2073+
}
20692074
/* safe to drop the kref from tty_driver_lookup_tty() */
20702075
tty_kref_put(tty);
20712076
retval = tty_reopen(tty);
@@ -2152,6 +2157,7 @@ static int tty_open(struct inode *inode, struct file *filp)
21522157
return 0;
21532158
err_unlock:
21542159
mutex_unlock(&tty_mutex);
2160+
err_unref:
21552161
/* after locks to avoid deadlock */
21562162
if (!IS_ERR_OR_NULL(driver))
21572163
tty_driver_kref_put(driver);

drivers/tty/tty_mutex.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ void __lockfunc tty_lock(struct tty_struct *tty)
1919
}
2020
EXPORT_SYMBOL(tty_lock);
2121

22+
int tty_lock_interruptible(struct tty_struct *tty)
23+
{
24+
if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty))
25+
return -EIO;
26+
tty_kref_get(tty);
27+
return mutex_lock_interruptible(&tty->legacy_mutex);
28+
}
29+
2230
void __lockfunc tty_unlock(struct tty_struct *tty)
2331
{
2432
if (WARN(tty->magic != TTY_MAGIC, "U Bad %p\n", tty))

include/linux/tty.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ extern long vt_compat_ioctl(struct tty_struct *tty,
649649
/* tty_mutex.c */
650650
/* functions for preparation of BKL removal */
651651
extern void __lockfunc tty_lock(struct tty_struct *tty);
652+
extern int tty_lock_interruptible(struct tty_struct *tty);
652653
extern void __lockfunc tty_unlock(struct tty_struct *tty);
653654
extern void __lockfunc tty_lock_slave(struct tty_struct *tty);
654655
extern void __lockfunc tty_unlock_slave(struct tty_struct *tty);

0 commit comments

Comments
 (0)