Commit 50dceaae authored by Alexander Viro's avatar Alexander Viro Committed by Christoph Hellwig

[PATCH] tty cleanups (10/12)

Preparations to cleanup:
	* call of get_tty_driver() moved from init_dev() to its callers
	* instead of kdev_t dev we pass struct tty_struct *driver and int index
parent b695aea2
...@@ -799,20 +799,13 @@ static inline void tty_line_name(struct tty_driver *driver, int index, char *p) ...@@ -799,20 +799,13 @@ static inline void tty_line_name(struct tty_driver *driver, int index, char *p)
* really quite straightforward. The semaphore locking can probably be * really quite straightforward. The semaphore locking can probably be
* relaxed for the (most common) case of reopening a tty. * relaxed for the (most common) case of reopening a tty.
*/ */
static int init_dev(kdev_t device, struct tty_struct **ret_tty) static int init_dev(struct tty_driver *driver, int idx,
struct tty_struct **ret_tty)
{ {
struct tty_struct *tty, *o_tty; struct tty_struct *tty, *o_tty;
struct termios *tp, **tp_loc, *o_tp, **o_tp_loc; struct termios *tp, **tp_loc, *o_tp, **o_tp_loc;
struct termios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc; struct termios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc;
struct tty_driver *driver;
int retval=0; int retval=0;
int idx;
driver = get_tty_driver(device);
if (!driver)
return -ENODEV;
idx = minor(device) - driver->minor_start;
/* /*
* Check whether we need to acquire the tty semaphore to avoid * Check whether we need to acquire the tty semaphore to avoid
...@@ -845,7 +838,7 @@ static int init_dev(kdev_t device, struct tty_struct **ret_tty) ...@@ -845,7 +838,7 @@ static int init_dev(kdev_t device, struct tty_struct **ret_tty)
if(!tty) if(!tty)
goto fail_no_mem; goto fail_no_mem;
initialize_tty_struct(tty); initialize_tty_struct(tty);
tty->device = device; tty->device = mk_kdev(driver->major, driver->minor_start + idx);
tty->driver = driver; tty->driver = driver;
tty->index = idx; tty->index = idx;
tty_line_name(driver, idx, tty->name); tty_line_name(driver, idx, tty->name);
...@@ -1315,6 +1308,8 @@ static int tty_open(struct inode * inode, struct file * filp) ...@@ -1315,6 +1308,8 @@ static int tty_open(struct inode * inode, struct file * filp)
{ {
struct tty_struct *tty; struct tty_struct *tty;
int noctty, retval; int noctty, retval;
struct tty_driver *driver;
int index;
kdev_t device; kdev_t device;
unsigned short saved_flags; unsigned short saved_flags;
char buf[64]; char buf[64];
...@@ -1351,18 +1346,14 @@ static int tty_open(struct inode * inode, struct file * filp) ...@@ -1351,18 +1346,14 @@ static int tty_open(struct inode * inode, struct file * filp)
if (IS_PTMX_DEV(device)) { if (IS_PTMX_DEV(device)) {
#ifdef CONFIG_UNIX98_PTYS #ifdef CONFIG_UNIX98_PTYS
/* find a free pty. */ /* find a free pty. */
int major, minor; int major;
struct tty_driver *driver;
/* find a device that is not in use. */ /* find a device that is not in use. */
retval = -1; retval = -1;
for (major = 0 ; major < UNIX98_NR_MAJORS ; major++) { for (major = 0 ; major < UNIX98_NR_MAJORS ; major++) {
driver = &ptm_driver[major]; driver = &ptm_driver[major];
for (minor = driver->minor_start; for (index = 0; index < driver->num ; index++)
minor < driver->minor_start + driver->num; if (!init_dev(driver, index, &tty))
minor++) {
device = mk_kdev(driver->major, minor);
if (!init_dev(device, &tty))
goto ptmx_found; /* ok! */ goto ptmx_found; /* ok! */
} }
} }
...@@ -1370,14 +1361,18 @@ static int tty_open(struct inode * inode, struct file * filp) ...@@ -1370,14 +1361,18 @@ static int tty_open(struct inode * inode, struct file * filp)
ptmx_found: ptmx_found:
set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
minor -= driver->minor_start; devpts_pty_new(driver->other->name_base + index, MKDEV(driver->other->major, index + driver->other->minor_start));
devpts_pty_new(driver->other->name_base + minor, MKDEV(driver->other->major, minor + driver->other->minor_start));
noctty = 1; noctty = 1;
#else #else
return -ENODEV; return -ENODEV;
#endif /* CONFIG_UNIX_98_PTYS */ #endif /* CONFIG_UNIX_98_PTYS */
} else { } else {
retval = init_dev(device, &tty); driver = get_tty_driver(device);
if (!driver)
return -ENODEV;
index = minor(device) - driver->minor_start;
retval = init_dev(driver, index, &tty);
if (retval) if (retval)
return retval; return retval;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment