tty: Remove __GFP_NOFAIL from tty_add_file()
Subsystems (2)
PATCH 1/1 tty: Remove __GFP_NOFAIL from tty_add_file()
This patch removes __GFP_NOFAIL use from tty_add_file() and adds proper error handling to the call-sites of the function.
Cc Andrew Morton <[email protected]>
Cc Alan Cox <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc David Rientjes <[email protected]>
Signed-off-by Pekka Enberg <[email protected]>
--- drivers/char/pty.c | 4 +++- drivers/char/tty_io.c | 15 +++++++++++---- include/linux/tty.h | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-)
drivers/char/pty.c +3 -1
@@ -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 out1; retval =devpts_pty_new (inode, tty->link);if (retval)
drivers/char/tty_io.c +11 -4
@@ -194,12 +194,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;
@@ -208,6 +209,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 */
@@ -1875,7 +1878,11 @@ got_driver: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 &&
include/linux/tty.h +1 -1
@@ -465,7 +465,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);
Signature · 1 line
1.6.3.3
Quoted 5 lines · Pekka Enberg
drivers/char/pty.c +0
-0
drivers/char/pty.c static int ptmx_open(struct inode *inode, struct file *filp) · line 684
Quoted 10 lines
drivers/char/pty.c +3
-1@@ -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 out1; retval =devpts_pty_new (inode, tty->link);if (retval)
This needs devpts_kill_index() to reverse the successful devpts_new_index(), so I think it should be "goto out" and not "goto out1".