aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/char/pty.c4
-rw-r--r--drivers/char/tty_io.c15
-rw-r--r--include/linux/tty.h2
3 files changed, 15 insertions, 6 deletions
diff --git a/drivers/char/pty.c b/drivers/char/pty.c
index c350d01716bd..923a48585501 100644
--- a/drivers/char/pty.c
+++ b/drivers/char/pty.c
@@ -676,7 +676,9 @@ static int ptmx_open(struct inode *inode, struct file *filp)
676 676
677 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ 677 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
678 678
679 tty_add_file(tty, filp); 679 retval = tty_add_file(tty, filp);
680 if (retval)
681 goto out;
680 682
681 retval = devpts_pty_new(inode, tty->link); 683 retval = devpts_pty_new(inode, tty->link);
682 if (retval) 684 if (retval)
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index dc184d4b5638..d6c659f2f659 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -196,12 +196,13 @@ static inline struct tty_struct *file_tty(struct file *file)
196} 196}
197 197
198/* Associate a new file with the tty structure */ 198/* Associate a new file with the tty structure */
199void tty_add_file(struct tty_struct *tty, struct file *file) 199int tty_add_file(struct tty_struct *tty, struct file *file)
200{ 200{
201 struct tty_file_private *priv; 201 struct tty_file_private *priv;
202 202
203 /* XXX: must implement proper error handling in callers */ 203 priv = kmalloc(sizeof(*priv), GFP_KERNEL);
204 priv = kmalloc(sizeof(*priv), GFP_KERNEL|__GFP_NOFAIL); 204 if (!priv)
205 return -ENOMEM;
205 206
206 priv->tty = tty; 207 priv->tty = tty;
207 priv->file = file; 208 priv->file = file;
@@ -210,6 +211,8 @@ void tty_add_file(struct tty_struct *tty, struct file *file)
210 spin_lock(&tty_files_lock); 211 spin_lock(&tty_files_lock);
211 list_add(&priv->list, &tty->tty_files); 212 list_add(&priv->list, &tty->tty_files);
212 spin_unlock(&tty_files_lock); 213 spin_unlock(&tty_files_lock);
214
215 return 0;
213} 216}
214 217
215/* Delete file from its tty */ 218/* Delete file from its tty */
@@ -1877,7 +1880,11 @@ got_driver:
1877 return PTR_ERR(tty); 1880 return PTR_ERR(tty);
1878 } 1881 }
1879 1882
1880 tty_add_file(tty, filp); 1883 retval = tty_add_file(tty, filp);
1884 if (retval) {
1885 tty_unlock();
1886 return retval;
1887 }
1881 1888
1882 check_tty_count(tty, "tty_open"); 1889 check_tty_count(tty, "tty_open");
1883 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && 1890 if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
diff --git a/include/linux/tty.h b/include/linux/tty.h
index d94eb86266c4..86be0cdeb11b 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -466,7 +466,7 @@ extern void proc_clear_tty(struct task_struct *p);
466extern struct tty_struct *get_current_tty(void); 466extern struct tty_struct *get_current_tty(void);
467extern void tty_default_fops(struct file_operations *fops); 467extern void tty_default_fops(struct file_operations *fops);
468extern struct tty_struct *alloc_tty_struct(void); 468extern struct tty_struct *alloc_tty_struct(void);
469extern void tty_add_file(struct tty_struct *tty, struct file *file); 469extern int tty_add_file(struct tty_struct *tty, struct file *file);
470extern void free_tty_struct(struct tty_struct *tty); 470extern void free_tty_struct(struct tty_struct *tty);
471extern void initialize_tty_struct(struct tty_struct *tty, 471extern void initialize_tty_struct(struct tty_struct *tty,
472 struct tty_driver *driver, int idx); 472 struct tty_driver *driver, int idx);