Skip to content

Commit 4a2b5fd

Browse files
Sukadev Bhattiprolutorvalds
authored andcommitted
Move tty lookup/reopen to caller
Move tty_driver_lookup_tty() and tty_reopen() from tty_init_dev() into tty_open() (one of the two callers of tty_init_dev()). These calls are not really required in ptmx_open(), the other caller, since ptmx_open() would be setting up a new tty. Changelog[v2]: - remove the lookup and reopen calls from ptmx_open - merge with recent changes to ttydev tree Signed-off-by: Sukadev Bhattiprolu <sukadev@us.ibm.com> Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent bf970ee commit 4a2b5fd

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

‎drivers/char/tty_io.c‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,19 +1376,6 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx,
13761376
struct tty_struct *tty;
13771377
int retval;
13781378

1379-
/* check whether we're reopening an existing tty */
1380-
tty = tty_driver_lookup_tty(driver, idx);
1381-
1382-
if (IS_ERR(tty))
1383-
return tty;
1384-
1385-
if (tty) {
1386-
retval = tty_reopen(tty);
1387-
if (retval)
1388-
return ERR_PTR(retval);
1389-
return tty;
1390-
}
1391-
13921379
/* Check if pty master is being opened multiple times */
13931380
if (driver->subtype == PTY_TYPE_MASTER &&
13941381
(driver->flags & TTY_DRIVER_DEVPTS_MEM) && !first_ok)
@@ -1790,7 +1777,7 @@ void tty_release_dev(struct file *filp)
17901777

17911778
static int __tty_open(struct inode *inode, struct file *filp)
17921779
{
1793-
struct tty_struct *tty;
1780+
struct tty_struct *tty = NULL;
17941781
int noctty, retval;
17951782
struct tty_driver *driver;
17961783
int index;
@@ -1847,7 +1834,21 @@ static int __tty_open(struct inode *inode, struct file *filp)
18471834
return -ENODEV;
18481835
}
18491836
got_driver:
1850-
tty = tty_init_dev(driver, index, 0);
1837+
if (!tty) {
1838+
/* check whether we're reopening an existing tty */
1839+
tty = tty_driver_lookup_tty(driver, index);
1840+
1841+
if (IS_ERR(tty))
1842+
return PTR_ERR(tty);
1843+
}
1844+
1845+
if (tty) {
1846+
retval = tty_reopen(tty);
1847+
if (retval)
1848+
tty = ERR_PTR(retval);
1849+
} else
1850+
tty = tty_init_dev(driver, index, 0);
1851+
18511852
mutex_unlock(&tty_mutex);
18521853
tty_driver_kref_put(driver);
18531854
if (IS_ERR(tty))

0 commit comments

Comments
 (0)