Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 280661
b: refs/heads/master
c: b82154a
h: refs/heads/master
i:
  280659: 381ad00
v: v3
  • Loading branch information
Jiri Slaby authored and Greg Kroah-Hartman committed Nov 15, 2011
1 parent 226aa8b commit 8222371
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1411dc4aa21d364f40ed363c8e715939c15f57c2
refs/heads/master: b82154ac37a7d12335c7c3d3c34c549171ec0cb4
57 changes: 39 additions & 18 deletions trunk/drivers/tty/tty_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1796,6 +1796,33 @@ int tty_release(struct inode *inode, struct file *filp)
return 0;
}

/**
* tty_open_current_tty - get tty of current task for open
* @device: device number
* @filp: file pointer to tty
* @return: tty of the current task iff @device is /dev/tty
*
* We cannot return driver and index like for the other nodes because
* devpts will not work then. It expects inodes to be from devpts FS.
*/
static struct tty_struct *tty_open_current_tty(dev_t device, struct file *filp)
{
struct tty_struct *tty;

if (device != MKDEV(TTYAUX_MAJOR, 0))
return NULL;

tty = get_current_tty();
if (!tty)
return ERR_PTR(-ENXIO);

filp->f_flags |= O_NONBLOCK; /* Don't let /dev/tty block */
/* noctty = 1; */
tty_kref_put(tty);
/* FIXME: we put a reference and return a TTY! */
return tty;
}

/**
* tty_open - open a tty device
* @inode: inode of device file
Expand All @@ -1819,9 +1846,9 @@ int tty_release(struct inode *inode, struct file *filp)

static int tty_open(struct inode *inode, struct file *filp)
{
struct tty_struct *tty = NULL;
struct tty_struct *tty;
int noctty, retval;
struct tty_driver *driver;
struct tty_driver *driver = NULL;
int index;
dev_t device = inode->i_rdev;
unsigned saved_flags = filp->f_flags;
Expand All @@ -1840,22 +1867,15 @@ static int tty_open(struct inode *inode, struct file *filp)
mutex_lock(&tty_mutex);
tty_lock();

if (device == MKDEV(TTYAUX_MAJOR, 0)) {
tty = get_current_tty();
if (!tty) {
tty_unlock();
mutex_unlock(&tty_mutex);
tty_free_file(filp);
return -ENXIO;
}
driver = tty_driver_kref_get(tty->driver);
index = tty->index;
filp->f_flags |= O_NONBLOCK; /* Don't let /dev/tty block */
/* noctty = 1; */
/* FIXME: Should we take a driver reference ? */
tty_kref_put(tty);
tty = tty_open_current_tty(device, filp);
if (IS_ERR(tty)) {
tty_unlock();
mutex_unlock(&tty_mutex);
tty_free_file(filp);
return PTR_ERR(tty);
} else if (tty)
goto got_driver;
}

#ifdef CONFIG_VT
if (device == MKDEV(TTY_MAJOR, 0)) {
extern struct tty_driver *console_driver;
Expand Down Expand Up @@ -1911,7 +1931,8 @@ static int tty_open(struct inode *inode, struct file *filp)
tty = tty_init_dev(driver, index, 0);

mutex_unlock(&tty_mutex);
tty_driver_kref_put(driver);
if (driver)
tty_driver_kref_put(driver);
if (IS_ERR(tty)) {
tty_unlock();
tty_free_file(filp);
Expand Down

0 comments on commit 8222371

Please sign in to comment.