aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Hurley <peter@hurleysoftware.com>2016-01-10 00:13:44 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2016-01-27 02:17:54 -0500
commit0bfd464d3fdd5bb322f9cace4cc47f1796545cf7 (patch)
tree39464f856fd4dc6b58c31e2cfbbbb882ce3b7ec1
parent92e963f50fc74041b5e9e744c330dca48e04f08d (diff)
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>
-rw-r--r--drivers/tty/tty_io.c8
-rw-r--r--drivers/tty/tty_mutex.c8
-rw-r--r--include/linux/tty.h1
3 files changed, 16 insertions, 1 deletions
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 892c92354745..765935b144d6 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -2065,7 +2065,12 @@ retry_open:
2065 2065
2066 if (tty) { 2066 if (tty) {
2067 mutex_unlock(&tty_mutex); 2067 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 }
2069 /* safe to drop the kref from tty_driver_lookup_tty() */ 2074 /* safe to drop the kref from tty_driver_lookup_tty() */
2070 tty_kref_put(tty); 2075 tty_kref_put(tty);
2071 retval = tty_reopen(tty); 2076 retval = tty_reopen(tty);
@@ -2152,6 +2157,7 @@ retry_open:
2152 return 0; 2157 return 0;
2153err_unlock: 2158err_unlock:
2154 mutex_unlock(&tty_mutex); 2159 mutex_unlock(&tty_mutex);
2160err_unref:
2155 /* after locks to avoid deadlock */ 2161 /* after locks to avoid deadlock */
2156 if (!IS_ERR_OR_NULL(driver)) 2162 if (!IS_ERR_OR_NULL(driver))
2157 tty_driver_kref_put(driver); 2163 tty_driver_kref_put(driver);
diff --git a/drivers/tty/tty_mutex.c b/drivers/tty/tty_mutex.c
index 77703a391207..d2f3c4cd697f 100644
--- a/drivers/tty/tty_mutex.c
+++ b/drivers/tty/tty_mutex.c
@@ -19,6 +19,14 @@ void __lockfunc tty_lock(struct tty_struct *tty)
19} 19}
20EXPORT_SYMBOL(tty_lock); 20EXPORT_SYMBOL(tty_lock);
21 21
22int 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
22void __lockfunc tty_unlock(struct tty_struct *tty) 30void __lockfunc tty_unlock(struct tty_struct *tty)
23{ 31{
24 if (WARN(tty->magic != TTY_MAGIC, "U Bad %p\n", tty)) 32 if (WARN(tty->magic != TTY_MAGIC, "U Bad %p\n", tty))
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 2fd8708ea888..d9fb4b043f56 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -649,6 +649,7 @@ extern long vt_compat_ioctl(struct tty_struct *tty,
649/* tty_mutex.c */ 649/* tty_mutex.c */
650/* functions for preparation of BKL removal */ 650/* functions for preparation of BKL removal */
651extern void __lockfunc tty_lock(struct tty_struct *tty); 651extern void __lockfunc tty_lock(struct tty_struct *tty);
652extern int tty_lock_interruptible(struct tty_struct *tty);
652extern void __lockfunc tty_unlock(struct tty_struct *tty); 653extern void __lockfunc tty_unlock(struct tty_struct *tty);
653extern void __lockfunc tty_lock_slave(struct tty_struct *tty); 654extern void __lockfunc tty_lock_slave(struct tty_struct *tty);
654extern void __lockfunc tty_unlock_slave(struct tty_struct *tty); 655extern void __lockfunc tty_unlock_slave(struct tty_struct *tty);