Skip to content

Commit

Permalink
tty_lock: Localise the lock
Browse files Browse the repository at this point in the history
In each remaining case the tty_lock is associated with a specific tty. This
means we can now lock on a per tty basis. We do need tty_lock_pair() for
the pty case. Uglier but still a step in the right direction.

[fixed up calls in 3 missing drivers - gregkh]

Signed-off-by: Alan Cox <[email protected]>
Acked-by: Arnd Bergmann <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Alan Cox authored and gregkh committed May 4, 2012
1 parent d739e65 commit d29f3ef
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 103 deletions.
4 changes: 2 additions & 2 deletions drivers/staging/serial/68360serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -1859,9 +1859,9 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
printk("block_til_ready blocking: ttys%d, count = %d\n",
info->line, state->count);
#endif
tty_unlock();
tty_unlock(tty);
schedule();
tty_lock();
tty_lock(tty);
}
current->state = TASK_RUNNING;
remove_wait_queue(&info->open_wait, &wait);
Expand Down
12 changes: 6 additions & 6 deletions drivers/tty/amiserial.c
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ static int get_serial_info(struct tty_struct *tty, struct serial_state *state,
if (!retinfo)
return -EFAULT;
memset(&tmp, 0, sizeof(tmp));
tty_lock();
tty_lock(tty);
tmp.line = tty->index;
tmp.port = state->port;
tmp.flags = state->tport.flags;
Expand All @@ -1042,7 +1042,7 @@ static int get_serial_info(struct tty_struct *tty, struct serial_state *state,
tmp.close_delay = state->tport.close_delay;
tmp.closing_wait = state->tport.closing_wait;
tmp.custom_divisor = state->custom_divisor;
tty_unlock();
tty_unlock(tty);
if (copy_to_user(retinfo,&tmp,sizeof(*retinfo)))
return -EFAULT;
return 0;
Expand All @@ -1059,12 +1059,12 @@ static int set_serial_info(struct tty_struct *tty, struct serial_state *state,
if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
return -EFAULT;

tty_lock();
tty_lock(tty);
change_spd = ((new_serial.flags ^ port->flags) & ASYNC_SPD_MASK) ||
new_serial.custom_divisor != state->custom_divisor;
if (new_serial.irq || new_serial.port != state->port ||
new_serial.xmit_fifo_size != state->xmit_fifo_size) {
tty_unlock();
tty_unlock(tty);
return -EINVAL;
}

Expand All @@ -1084,7 +1084,7 @@ static int set_serial_info(struct tty_struct *tty, struct serial_state *state,
}

if (new_serial.baud_base < 9600) {
tty_unlock();
tty_unlock(tty);
return -EINVAL;
}

Expand Down Expand Up @@ -1116,7 +1116,7 @@ static int set_serial_info(struct tty_struct *tty, struct serial_state *state,
}
} else
retval = startup(tty, state);
tty_unlock();
tty_unlock(tty);
return retval;
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/tty/cyclades.c
Original file line number Diff line number Diff line change
Expand Up @@ -1599,7 +1599,7 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
* If the port is the middle of closing, bail out now
*/
if (tty_hung_up_p(filp) || (info->port.flags & ASYNC_CLOSING)) {
wait_event_interruptible_tty(info->port.close_wait,
wait_event_interruptible_tty(tty, info->port.close_wait,
!(info->port.flags & ASYNC_CLOSING));
return (info->port.flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS;
}
Expand Down
11 changes: 6 additions & 5 deletions drivers/tty/n_r3964.c
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,8 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,

TRACE_L("read()");

tty_lock();
/* FIXME: should use a private lock */
tty_lock(tty);

pClient = findClient(pInfo, task_pid(current));
if (pClient) {
Expand All @@ -1077,7 +1078,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
goto unlock;
}
/* block until there is a message: */
wait_event_interruptible_tty(pInfo->read_wait,
wait_event_interruptible_tty(tty, pInfo->read_wait,
(pMsg = remove_msg(pInfo, pClient)));
}

Expand Down Expand Up @@ -1107,7 +1108,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
}
ret = -EPERM;
unlock:
tty_unlock();
tty_unlock(tty);
return ret;
}

Expand Down Expand Up @@ -1156,7 +1157,7 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
pHeader->locks = 0;
pHeader->owner = NULL;

tty_lock();
tty_lock(tty);

pClient = findClient(pInfo, task_pid(current));
if (pClient) {
Expand All @@ -1175,7 +1176,7 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
add_tx_queue(pInfo, pHeader);
trigger_transmit(pInfo);

tty_unlock();
tty_unlock(tty);

return 0;
}
Expand Down
23 changes: 13 additions & 10 deletions drivers/tty/pty.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
wake_up_interruptible(&tty->read_wait);
wake_up_interruptible(&tty->write_wait);
tty->packet = 0;
/* Review - krefs on tty_link ?? */
if (!tty->link)
return;
tty->link->packet = 0;
Expand All @@ -62,9 +63,7 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
mutex_unlock(&devpts_mutex);
}
#endif
tty_unlock();
tty_vhangup(tty->link);
tty_lock();
}
}

Expand Down Expand Up @@ -622,26 +621,29 @@ static int ptmx_open(struct inode *inode, struct file *filp)
return retval;

/* find a device that is not in use. */
tty_lock();
mutex_lock(&devpts_mutex);
index = devpts_new_index(inode);
tty_unlock();
if (index < 0) {
retval = index;
goto err_file;
}

mutex_unlock(&devpts_mutex);

mutex_lock(&tty_mutex);
mutex_lock(&devpts_mutex);
tty = tty_init_dev(ptm_driver, index);
mutex_unlock(&devpts_mutex);
tty_lock();
mutex_unlock(&tty_mutex);

if (IS_ERR(tty)) {
retval = PTR_ERR(tty);
goto out;
}

/* The tty returned here is locked so we can safely
drop the mutex */
mutex_unlock(&devpts_mutex);
mutex_unlock(&tty_mutex);

set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */

tty_add_file(tty, filp);
Expand All @@ -654,16 +656,17 @@ static int ptmx_open(struct inode *inode, struct file *filp)
if (retval)
goto err_release;

tty_unlock();
tty_unlock(tty);
return 0;
err_release:
tty_unlock();
tty_unlock(tty);
tty_release(inode, filp);
return retval;
out:
mutex_unlock(&tty_mutex);
devpts_kill_index(inode, index);
tty_unlock();
err_file:
mutex_unlock(&devpts_mutex);
tty_free_file(filp);
return retval;
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/tty/serial/crisv10.c
Original file line number Diff line number Diff line change
Expand Up @@ -4052,9 +4052,9 @@ block_til_ready(struct tty_struct *tty, struct file * filp,
printk("block_til_ready blocking: ttyS%d, count = %d\n",
info->line, info->count);
#endif
tty_unlock();
tty_unlock(tty);
schedule();
tty_lock();
tty_lock(tty);
}
set_current_state(TASK_RUNNING);
remove_wait_queue(&info->open_wait, &wait);
Expand Down
4 changes: 2 additions & 2 deletions drivers/tty/synclink.c
Original file line number Diff line number Diff line change
Expand Up @@ -3338,9 +3338,9 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
printk("%s(%d):block_til_ready blocking on %s count=%d\n",
__FILE__,__LINE__, tty->driver->name, port->count );

tty_unlock();
tty_unlock(tty);
schedule();
tty_lock();
tty_lock(tty);
}

set_current_state(TASK_RUNNING);
Expand Down
4 changes: 2 additions & 2 deletions drivers/tty/synclink_gt.c
Original file line number Diff line number Diff line change
Expand Up @@ -3336,9 +3336,9 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
}

DBGINFO(("%s block_til_ready wait\n", tty->driver->name));
tty_unlock();
tty_unlock(tty);
schedule();
tty_lock();
tty_lock(tty);
}

set_current_state(TASK_RUNNING);
Expand Down
4 changes: 2 additions & 2 deletions drivers/tty/synclinkmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3357,9 +3357,9 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
printk("%s(%d):%s block_til_ready() count=%d\n",
__FILE__,__LINE__, tty->driver->name, port->count );

tty_unlock();
tty_unlock(tty);
schedule();
tty_lock();
tty_lock(tty);
}

set_current_state(TASK_RUNNING);
Expand Down
Loading

0 comments on commit d29f3ef

Please sign in to comment.