Commit ba5db448 authored by Jiri Slaby's avatar Jiri Slaby Committed by Greg Kroah-Hartman

TTY: coalesce fail paths in tty_open

Move them to the end of the function and use gotos as usual.
Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
Cc: Alan Cox <alan@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 5b5e7040
...@@ -1916,27 +1916,20 @@ static int tty_open(struct inode *inode, struct file *filp) ...@@ -1916,27 +1916,20 @@ static int tty_open(struct inode *inode, struct file *filp)
tty = tty_open_current_tty(device, filp); tty = tty_open_current_tty(device, filp);
if (IS_ERR(tty)) { if (IS_ERR(tty)) {
tty_unlock(); retval = PTR_ERR(tty);
mutex_unlock(&tty_mutex); goto err_unlock;
tty_free_file(filp);
return PTR_ERR(tty);
} else if (!tty) { } else if (!tty) {
driver = tty_lookup_driver(device, filp, &noctty, &index); driver = tty_lookup_driver(device, filp, &noctty, &index);
if (IS_ERR(driver)) { if (IS_ERR(driver)) {
tty_unlock(); retval = PTR_ERR(driver);
mutex_unlock(&tty_mutex); goto err_unlock;
tty_free_file(filp);
return PTR_ERR(driver);
} }
/* check whether we're reopening an existing tty */ /* check whether we're reopening an existing tty */
tty = tty_driver_lookup_tty(driver, inode, index); tty = tty_driver_lookup_tty(driver, inode, index);
if (IS_ERR(tty)) { if (IS_ERR(tty)) {
tty_unlock(); retval = PTR_ERR(tty);
mutex_unlock(&tty_mutex); goto err_unlock;
tty_driver_kref_put(driver);
tty_free_file(filp);
return PTR_ERR(tty);
} }
} }
...@@ -1952,8 +1945,8 @@ static int tty_open(struct inode *inode, struct file *filp) ...@@ -1952,8 +1945,8 @@ static int tty_open(struct inode *inode, struct file *filp)
tty_driver_kref_put(driver); tty_driver_kref_put(driver);
if (IS_ERR(tty)) { if (IS_ERR(tty)) {
tty_unlock(); tty_unlock();
tty_free_file(filp); retval = PTR_ERR(tty);
return PTR_ERR(tty); goto err_file;
} }
tty_add_file(tty, filp); tty_add_file(tty, filp);
...@@ -2013,6 +2006,15 @@ static int tty_open(struct inode *inode, struct file *filp) ...@@ -2013,6 +2006,15 @@ static int tty_open(struct inode *inode, struct file *filp)
tty_unlock(); tty_unlock();
mutex_unlock(&tty_mutex); mutex_unlock(&tty_mutex);
return 0; return 0;
err_unlock:
tty_unlock();
mutex_unlock(&tty_mutex);
/* after locks to avoid deadlock */
if (!IS_ERR_OR_NULL(driver))
tty_driver_kref_put(driver);
err_file:
tty_free_file(filp);
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