From 65cce922f363785cc6a2e3d2f35f54744c0cb755 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Tue, 24 Aug 2010 07:48:34 +0300 Subject: [PATCH] --- yaml --- r: 213483 b: refs/heads/master c: f573bd1764f0f3f47754ca1ae7b2eb2909798a60 h: refs/heads/master i: 213481: a77ed3df6ebe23dd6b0e0433575a8416c1d6794d 213479: d8b6ce79467fdda4b3f77afbc21a27ba33b0e742 v: v3 --- [refs] | 2 +- trunk/drivers/char/pty.c | 4 +++- trunk/drivers/char/tty_io.c | 15 +++++++++++---- trunk/include/linux/tty.h | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/[refs] b/[refs] index e1e6d3c5a55c..b632fc8aefd6 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 8a28af7f7e42cd0f107e0d84e4ece89e7ef24d3f +refs/heads/master: f573bd1764f0f3f47754ca1ae7b2eb2909798a60 diff --git a/trunk/drivers/char/pty.c b/trunk/drivers/char/pty.c index c350d01716bd..923a48585501 100644 --- a/trunk/drivers/char/pty.c +++ b/trunk/drivers/char/pty.c @@ -676,7 +676,9 @@ static int ptmx_open(struct inode *inode, struct file *filp) set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ - tty_add_file(tty, filp); + retval = tty_add_file(tty, filp); + if (retval) + goto out; retval = devpts_pty_new(inode, tty->link); if (retval) diff --git a/trunk/drivers/char/tty_io.c b/trunk/drivers/char/tty_io.c index dc184d4b5638..d6c659f2f659 100644 --- a/trunk/drivers/char/tty_io.c +++ b/trunk/drivers/char/tty_io.c @@ -196,12 +196,13 @@ static inline struct tty_struct *file_tty(struct file *file) } /* Associate a new file with the tty structure */ -void tty_add_file(struct tty_struct *tty, struct file *file) +int tty_add_file(struct tty_struct *tty, struct file *file) { struct tty_file_private *priv; - /* XXX: must implement proper error handling in callers */ - priv = kmalloc(sizeof(*priv), GFP_KERNEL|__GFP_NOFAIL); + priv = kmalloc(sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; priv->tty = tty; priv->file = file; @@ -210,6 +211,8 @@ void tty_add_file(struct tty_struct *tty, struct file *file) spin_lock(&tty_files_lock); list_add(&priv->list, &tty->tty_files); spin_unlock(&tty_files_lock); + + return 0; } /* Delete file from its tty */ @@ -1877,7 +1880,11 @@ static int tty_open(struct inode *inode, struct file *filp) return PTR_ERR(tty); } - tty_add_file(tty, filp); + retval = tty_add_file(tty, filp); + if (retval) { + tty_unlock(); + return retval; + } check_tty_count(tty, "tty_open"); if (tty->driver->type == TTY_DRIVER_TYPE_PTY && diff --git a/trunk/include/linux/tty.h b/trunk/include/linux/tty.h index d94eb86266c4..86be0cdeb11b 100644 --- a/trunk/include/linux/tty.h +++ b/trunk/include/linux/tty.h @@ -466,7 +466,7 @@ extern void proc_clear_tty(struct task_struct *p); extern struct tty_struct *get_current_tty(void); extern void tty_default_fops(struct file_operations *fops); extern struct tty_struct *alloc_tty_struct(void); -extern void tty_add_file(struct tty_struct *tty, struct file *file); +extern int tty_add_file(struct tty_struct *tty, struct file *file); extern void free_tty_struct(struct tty_struct *tty); extern void initialize_tty_struct(struct tty_struct *tty, struct tty_driver *driver, int idx);