aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty/tty_io.c
diff options
context:
space:
mode:
authorPeter Hurley <peter@hurleysoftware.com>2014-11-05 12:12:51 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-11-05 21:24:10 -0500
commitaa3cb814a8efae1b7c81516b4bee41f831fe2e7a (patch)
tree605a0b8caa6509226aa78900666f4aea4867f9a8 /drivers/tty/tty_io.c
parent52494eeb993ef6865f7817c8b473f798771371fc (diff)
tty: Drop tty_mutex before tty reopen
Holding tty_mutex for a tty re-open is no longer necessary since "tty: Clarify re-open behavior of master ptys". Because the slave tty count is no longer accessed by tty_reopen(), holding tty_mutex to prevent concurrent final tty_release() of the slave pty is not required. As with "tty: Re-open /dev/tty without tty_mutex", holding a tty kref until the tty_lock is acquired is sufficient to ensure the tty has not been freed, which, in turn, is sufficient to ensure the tty_lock can be safely acquired and the tty count can be safely retrieved. A non-zero tty count with the tty lock held guarantees that release_tty() has not run and cannot run concurrently with tty_reopen(). Change tty_driver_lookup_tty() to acquire the tty kref, which allows the tty_mutex to be dropped before acquiring the tty lock. Dropping the tty_mutex before attempting the tty_lock allows other ttys to be opened and released, without needing this tty_reopen() to complete. Reviewed-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/tty_io.c')
-rw-r--r--drivers/tty/tty_io.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 2e166a1be2b7..66d6bcc24c7e 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1344,19 +1344,24 @@ static ssize_t tty_line_name(struct tty_driver *driver, int index, char *p)
1344 * @driver: the driver for the tty 1344 * @driver: the driver for the tty
1345 * @idx: the minor number 1345 * @idx: the minor number
1346 * 1346 *
1347 * Return the tty, if found or ERR_PTR() otherwise. 1347 * Return the tty, if found. If not found, return NULL or ERR_PTR() if the
1348 * driver lookup() method returns an error.
1348 * 1349 *
1349 * Locking: tty_mutex must be held. If tty is found, the mutex must 1350 * Locking: tty_mutex must be held. If the tty is found, bump the tty kref.
1350 * be held until the 'fast-open' is also done. Will change once we
1351 * have refcounting in the driver and per driver locking
1352 */ 1351 */
1353static struct tty_struct *tty_driver_lookup_tty(struct tty_driver *driver, 1352static struct tty_struct *tty_driver_lookup_tty(struct tty_driver *driver,
1354 struct inode *inode, int idx) 1353 struct inode *inode, int idx)
1355{ 1354{
1355 struct tty_struct *tty;
1356
1356 if (driver->ops->lookup) 1357 if (driver->ops->lookup)
1357 return driver->ops->lookup(driver, inode, idx); 1358 tty = driver->ops->lookup(driver, inode, idx);
1359 else
1360 tty = driver->ttys[idx];
1358 1361
1359 return driver->ttys[idx]; 1362 if (!IS_ERR(tty))
1363 tty_kref_get(tty);
1364 return tty;
1360} 1365}
1361 1366
1362/** 1367/**
@@ -2081,16 +2086,20 @@ retry_open:
2081 } 2086 }
2082 2087
2083 if (tty) { 2088 if (tty) {
2089 mutex_unlock(&tty_mutex);
2084 tty_lock(tty); 2090 tty_lock(tty);
2091 /* safe to drop the kref from tty_driver_lookup_tty() */
2092 tty_kref_put(tty);
2085 retval = tty_reopen(tty); 2093 retval = tty_reopen(tty);
2086 if (retval < 0) { 2094 if (retval < 0) {
2087 tty_unlock(tty); 2095 tty_unlock(tty);
2088 tty = ERR_PTR(retval); 2096 tty = ERR_PTR(retval);
2089 } 2097 }
2090 } else /* Returns with the tty_lock held for now */ 2098 } else { /* Returns with the tty_lock held for now */
2091 tty = tty_init_dev(driver, index); 2099 tty = tty_init_dev(driver, index);
2100 mutex_unlock(&tty_mutex);
2101 }
2092 2102
2093 mutex_unlock(&tty_mutex);
2094 tty_driver_kref_put(driver); 2103 tty_driver_kref_put(driver);
2095 } 2104 }
2096 2105