From abe5fe23b333a451c83e344b8eb61b079055cba8 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Wed, 9 Nov 2011 21:33:21 +0100 Subject: [PATCH] --- yaml --- r: 280663 b: refs/heads/master c: ba5db44895ec3abc5317a9af86001e688a72185c h: refs/heads/master i: 280661: 82223718b4626e96f59d040d31e4d7a452f99447 280659: 381ad00b81b1b792beba6c482a7b754f0c9657a5 280655: 931dbae91ae36ac4e8bcaee77309bbac568b690e v: v3 --- [refs] | 2 +- trunk/drivers/tty/tty_io.c | 32 +++++++++++++++++--------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/[refs] b/[refs] index 0f9937a60f55..ca11eeaeb1f6 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 5b5e70408f1e8a48deebedc26ba982bbc7db343e +refs/heads/master: ba5db44895ec3abc5317a9af86001e688a72185c diff --git a/trunk/drivers/tty/tty_io.c b/trunk/drivers/tty/tty_io.c index 00b84984308d..ba9194e7b9c8 100644 --- a/trunk/drivers/tty/tty_io.c +++ b/trunk/drivers/tty/tty_io.c @@ -1916,27 +1916,20 @@ static int tty_open(struct inode *inode, struct file *filp) 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); + retval = PTR_ERR(tty); + goto err_unlock; } else if (!tty) { driver = tty_lookup_driver(device, filp, &noctty, &index); if (IS_ERR(driver)) { - tty_unlock(); - mutex_unlock(&tty_mutex); - tty_free_file(filp); - return PTR_ERR(driver); + retval = PTR_ERR(driver); + goto err_unlock; } /* check whether we're reopening an existing tty */ tty = tty_driver_lookup_tty(driver, inode, index); if (IS_ERR(tty)) { - tty_unlock(); - mutex_unlock(&tty_mutex); - tty_driver_kref_put(driver); - tty_free_file(filp); - return PTR_ERR(tty); + retval = PTR_ERR(tty); + goto err_unlock; } } @@ -1952,8 +1945,8 @@ static int tty_open(struct inode *inode, struct file *filp) tty_driver_kref_put(driver); if (IS_ERR(tty)) { tty_unlock(); - tty_free_file(filp); - return PTR_ERR(tty); + retval = PTR_ERR(tty); + goto err_file; } tty_add_file(tty, filp); @@ -2013,6 +2006,15 @@ static int tty_open(struct inode *inode, struct file *filp) tty_unlock(); mutex_unlock(&tty_mutex); 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; }