Skip to contentSkip to conversation

tty: double unlock on error in ptmx_open()

PATCH New Dan Carpenter 1 participant 1 message Jul 11, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tty: double unlock on error in ptmx_open()

The problem here is that we called mutex_unlock(&devpts_mutex) on the error path when we weren't holding the lock.

drivers/tty/pty.c +1 -3
index d855883..a0ca083 100644
@@ -618,13 +618,12 @@ static int ptmx_open(struct inode *inode, struct file *filp)
 	/* find a device that is not in use. */
 	mutex_lock(&devpts_mutex);
 	index = devpts_new_index(inode);
+	mutex_unlock(&devpts_mutex);
 	if (index < 0) {
 		retval = index;
 		goto err_file;
 	}
 
-	mutex_unlock(&devpts_mutex);
-
 	mutex_lock(&tty_mutex);
 	tty = tty_init_dev(ptm_driver, index);
 
@@ -659,7 +658,6 @@ out:
 	mutex_unlock(&tty_mutex);
 	devpts_kill_index(inode, index);
 err_file:
-        mutex_unlock(&devpts_mutex);
 	tty_free_file(filp);
 	return retval;
 }