Commit ec79d605 authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Greg Kroah-Hartman

tty: replace BKL with a new tty_lock

As a preparation for replacing the big kernel lock
in the TTY layer, wrap all the callers in new
macros tty_lock, tty_lock_nested and tty_unlock.
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 3f582b8c
...@@ -1072,7 +1072,7 @@ static int get_serial_info(struct async_struct * info, ...@@ -1072,7 +1072,7 @@ static int get_serial_info(struct async_struct * info,
if (!retinfo) if (!retinfo)
return -EFAULT; return -EFAULT;
memset(&tmp, 0, sizeof(tmp)); memset(&tmp, 0, sizeof(tmp));
lock_kernel(); tty_lock();
tmp.type = state->type; tmp.type = state->type;
tmp.line = state->line; tmp.line = state->line;
tmp.port = state->port; tmp.port = state->port;
...@@ -1083,7 +1083,7 @@ static int get_serial_info(struct async_struct * info, ...@@ -1083,7 +1083,7 @@ static int get_serial_info(struct async_struct * info,
tmp.close_delay = state->close_delay; tmp.close_delay = state->close_delay;
tmp.closing_wait = state->closing_wait; tmp.closing_wait = state->closing_wait;
tmp.custom_divisor = state->custom_divisor; tmp.custom_divisor = state->custom_divisor;
unlock_kernel(); tty_unlock();
if (copy_to_user(retinfo,&tmp,sizeof(*retinfo))) if (copy_to_user(retinfo,&tmp,sizeof(*retinfo)))
return -EFAULT; return -EFAULT;
return 0; return 0;
...@@ -1100,14 +1100,14 @@ static int set_serial_info(struct async_struct * info, ...@@ -1100,14 +1100,14 @@ static int set_serial_info(struct async_struct * info,
if (copy_from_user(&new_serial,new_info,sizeof(new_serial))) if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
return -EFAULT; return -EFAULT;
lock_kernel(); tty_lock();
state = info->state; state = info->state;
old_state = *state; old_state = *state;
change_irq = new_serial.irq != state->irq; change_irq = new_serial.irq != state->irq;
change_port = (new_serial.port != state->port); change_port = (new_serial.port != state->port);
if(change_irq || change_port || (new_serial.xmit_fifo_size != state->xmit_fifo_size)) { if(change_irq || change_port || (new_serial.xmit_fifo_size != state->xmit_fifo_size)) {
unlock_kernel(); tty_unlock();
return -EINVAL; return -EINVAL;
} }
...@@ -1127,7 +1127,7 @@ static int set_serial_info(struct async_struct * info, ...@@ -1127,7 +1127,7 @@ static int set_serial_info(struct async_struct * info,
} }
if (new_serial.baud_base < 9600) { if (new_serial.baud_base < 9600) {
unlock_kernel(); tty_unlock();
return -EINVAL; return -EINVAL;
} }
...@@ -1163,7 +1163,7 @@ static int set_serial_info(struct async_struct * info, ...@@ -1163,7 +1163,7 @@ static int set_serial_info(struct async_struct * info,
} }
} else } else
retval = startup(info); retval = startup(info);
unlock_kernel(); tty_unlock();
return retval; return retval;
} }
...@@ -1538,7 +1538,7 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout) ...@@ -1538,7 +1538,7 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
orig_jiffies = jiffies; orig_jiffies = jiffies;
lock_kernel(); tty_lock_nested(); /* tty_wait_until_sent is called from lots of places */
/* /*
* Set the check interval to be 1/5 of the estimated time to * Set the check interval to be 1/5 of the estimated time to
* send a single character, and make it at least 1. The check * send a single character, and make it at least 1. The check
...@@ -1579,7 +1579,7 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout) ...@@ -1579,7 +1579,7 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
break; break;
} }
__set_current_state(TASK_RUNNING); __set_current_state(TASK_RUNNING);
unlock_kernel(); tty_unlock();
#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies); printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
#endif #endif
......
...@@ -67,15 +67,15 @@ static void set_led(char state) ...@@ -67,15 +67,15 @@ static void set_led(char state)
static int briq_panel_open(struct inode *ino, struct file *filep) static int briq_panel_open(struct inode *ino, struct file *filep)
{ {
lock_kernel(); tty_lock();
/* enforce single access, vfd_is_open is protected by BKL */ /* enforce single access, vfd_is_open is protected by BKL */
if (vfd_is_open) { if (vfd_is_open) {
unlock_kernel(); tty_unlock();
return -EBUSY; return -EBUSY;
} }
vfd_is_open = 1; vfd_is_open = 1;
unlock_kernel(); tty_unlock();
return 0; return 0;
} }
......
...@@ -598,18 +598,18 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file, ...@@ -598,18 +598,18 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
return -EFAULT; return -EFAULT;
} }
lock_kernel(); tty_lock();
for (;;) { for (;;) {
if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) { if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) {
unlock_kernel(); tty_unlock();
return -EIO; return -EIO;
} }
n_hdlc = tty2n_hdlc (tty); n_hdlc = tty2n_hdlc (tty);
if (!n_hdlc || n_hdlc->magic != HDLC_MAGIC || if (!n_hdlc || n_hdlc->magic != HDLC_MAGIC ||
tty != n_hdlc->tty) { tty != n_hdlc->tty) {
unlock_kernel(); tty_unlock();
return 0; return 0;
} }
...@@ -619,13 +619,13 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file, ...@@ -619,13 +619,13 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
/* no data */ /* no data */
if (file->f_flags & O_NONBLOCK) { if (file->f_flags & O_NONBLOCK) {
unlock_kernel(); tty_unlock();
return -EAGAIN; return -EAGAIN;
} }
interruptible_sleep_on (&tty->read_wait); interruptible_sleep_on (&tty->read_wait);
if (signal_pending(current)) { if (signal_pending(current)) {
unlock_kernel(); tty_unlock();
return -EINTR; return -EINTR;
} }
} }
...@@ -648,7 +648,7 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file, ...@@ -648,7 +648,7 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
kfree(rbuf); kfree(rbuf);
else else
n_hdlc_buf_put(&n_hdlc->rx_free_buf_list,rbuf); n_hdlc_buf_put(&n_hdlc->rx_free_buf_list,rbuf);
unlock_kernel(); tty_unlock();
return ret; return ret;
} /* end of n_hdlc_tty_read() */ } /* end of n_hdlc_tty_read() */
...@@ -691,7 +691,7 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file, ...@@ -691,7 +691,7 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file,
count = maxframe; count = maxframe;
} }
lock_kernel(); tty_lock();
add_wait_queue(&tty->write_wait, &wait); add_wait_queue(&tty->write_wait, &wait);
set_current_state(TASK_INTERRUPTIBLE); set_current_state(TASK_INTERRUPTIBLE);
...@@ -731,7 +731,7 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file, ...@@ -731,7 +731,7 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file,
n_hdlc_buf_put(&n_hdlc->tx_buf_list,tbuf); n_hdlc_buf_put(&n_hdlc->tx_buf_list,tbuf);
n_hdlc_send_frames(n_hdlc,tty); n_hdlc_send_frames(n_hdlc,tty);
} }
unlock_kernel(); tty_unlock();
return error; return error;
} /* end of n_hdlc_tty_write() */ } /* end of n_hdlc_tty_write() */
......
...@@ -1067,7 +1067,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file, ...@@ -1067,7 +1067,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
TRACE_L("read()"); TRACE_L("read()");
lock_kernel(); tty_lock();
pClient = findClient(pInfo, task_pid(current)); pClient = findClient(pInfo, task_pid(current));
if (pClient) { if (pClient) {
...@@ -1109,7 +1109,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file, ...@@ -1109,7 +1109,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
} }
ret = -EPERM; ret = -EPERM;
unlock: unlock:
unlock_kernel(); tty_unlock();
return ret; return ret;
} }
...@@ -1158,7 +1158,7 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file, ...@@ -1158,7 +1158,7 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
pHeader->locks = 0; pHeader->locks = 0;
pHeader->owner = NULL; pHeader->owner = NULL;
lock_kernel(); tty_lock();
pClient = findClient(pInfo, task_pid(current)); pClient = findClient(pInfo, task_pid(current));
if (pClient) { if (pClient) {
...@@ -1177,7 +1177,7 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file, ...@@ -1177,7 +1177,7 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
add_tx_queue(pInfo, pHeader); add_tx_queue(pInfo, pHeader);
trigger_transmit(pInfo); trigger_transmit(pInfo);
unlock_kernel(); tty_unlock();
return 0; return 0;
} }
......
...@@ -692,9 +692,9 @@ static int ptmx_open(struct inode *inode, struct file *filp) ...@@ -692,9 +692,9 @@ static int ptmx_open(struct inode *inode, struct file *filp)
{ {
int ret; int ret;
lock_kernel(); tty_lock();
ret = __ptmx_open(inode, filp); ret = __ptmx_open(inode, filp);
unlock_kernel(); tty_unlock();
return ret; return ret;
} }
......
...@@ -313,7 +313,7 @@ int paste_selection(struct tty_struct *tty) ...@@ -313,7 +313,7 @@ int paste_selection(struct tty_struct *tty)
struct tty_ldisc *ld; struct tty_ldisc *ld;
DECLARE_WAITQUEUE(wait, current); DECLARE_WAITQUEUE(wait, current);
lock_kernel(); tty_lock_nested(); /* always called with BTM from vt_ioctl */
acquire_console_sem(); acquire_console_sem();
poke_blanked_console(); poke_blanked_console();
...@@ -338,6 +338,6 @@ int paste_selection(struct tty_struct *tty) ...@@ -338,6 +338,6 @@ int paste_selection(struct tty_struct *tty)
__set_current_state(TASK_RUNNING); __set_current_state(TASK_RUNNING);
tty_ldisc_deref(ld); tty_ldisc_deref(ld);
unlock_kernel(); tty_unlock();
return 0; return 0;
} }
...@@ -1505,7 +1505,7 @@ cy_ioctl(struct tty_struct *tty, struct file *file, ...@@ -1505,7 +1505,7 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg); /* */ printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg); /* */
#endif #endif
lock_kernel(); tty_lock();
switch (cmd) { switch (cmd) {
case CYGETMON: case CYGETMON:
...@@ -1561,7 +1561,7 @@ cy_ioctl(struct tty_struct *tty, struct file *file, ...@@ -1561,7 +1561,7 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
default: default:
ret_val = -ENOIOCTLCMD; ret_val = -ENOIOCTLCMD;
} }
unlock_kernel(); tty_unlock();
#ifdef SERIAL_DEBUG_OTHER #ifdef SERIAL_DEBUG_OTHER
printk("cy_ioctl done\n"); printk("cy_ioctl done\n");
......
...@@ -1699,7 +1699,7 @@ static long sx_fw_ioctl(struct file *filp, unsigned int cmd, ...@@ -1699,7 +1699,7 @@ static long sx_fw_ioctl(struct file *filp, unsigned int cmd,
if (!capable(CAP_SYS_RAWIO)) if (!capable(CAP_SYS_RAWIO))
return -EPERM; return -EPERM;
lock_kernel(); tty_lock();
sx_dprintk(SX_DEBUG_FIRMWARE, "IOCTL %x: %lx\n", cmd, arg); sx_dprintk(SX_DEBUG_FIRMWARE, "IOCTL %x: %lx\n", cmd, arg);
...@@ -1848,7 +1848,7 @@ static long sx_fw_ioctl(struct file *filp, unsigned int cmd, ...@@ -1848,7 +1848,7 @@ static long sx_fw_ioctl(struct file *filp, unsigned int cmd,
break; break;
} }
out: out:
unlock_kernel(); tty_unlock();
func_exit(); func_exit();
return rc; return rc;
} }
...@@ -1859,7 +1859,7 @@ static int sx_break(struct tty_struct *tty, int flag) ...@@ -1859,7 +1859,7 @@ static int sx_break(struct tty_struct *tty, int flag)
int rv; int rv;
func_enter(); func_enter();
lock_kernel(); tty_lock();
if (flag) if (flag)
rv = sx_send_command(port, HS_START, -1, HS_IDLE_BREAK); rv = sx_send_command(port, HS_START, -1, HS_IDLE_BREAK);
...@@ -1868,7 +1868,7 @@ static int sx_break(struct tty_struct *tty, int flag) ...@@ -1868,7 +1868,7 @@ static int sx_break(struct tty_struct *tty, int flag)
if (rv != 1) if (rv != 1)
printk(KERN_ERR "sx: couldn't send break (%x).\n", printk(KERN_ERR "sx: couldn't send break (%x).\n",
read_sx_byte(port->board, CHAN_OFFSET(port, hi_hstat))); read_sx_byte(port->board, CHAN_OFFSET(port, hi_hstat)));
unlock_kernel(); tty_unlock();
func_exit(); func_exit();
return 0; return 0;
} }
...@@ -1909,7 +1909,7 @@ static int sx_ioctl(struct tty_struct *tty, struct file *filp, ...@@ -1909,7 +1909,7 @@ static int sx_ioctl(struct tty_struct *tty, struct file *filp,
/* func_enter2(); */ /* func_enter2(); */
rc = 0; rc = 0;
lock_kernel(); tty_lock();
switch (cmd) { switch (cmd) {
case TIOCGSERIAL: case TIOCGSERIAL:
rc = gs_getserial(&port->gs, argp); rc = gs_getserial(&port->gs, argp);
...@@ -1921,7 +1921,7 @@ static int sx_ioctl(struct tty_struct *tty, struct file *filp, ...@@ -1921,7 +1921,7 @@ static int sx_ioctl(struct tty_struct *tty, struct file *filp,
rc = -ENOIOCTLCMD; rc = -ENOIOCTLCMD;
break; break;
} }
unlock_kernel(); tty_unlock();
/* func_exit(); */ /* func_exit(); */
return rc; return rc;
......
This diff is collapsed.
...@@ -440,6 +440,8 @@ static void tty_set_termios_ldisc(struct tty_struct *tty, int num) ...@@ -440,6 +440,8 @@ static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
* *
* A helper opening method. Also a convenient debugging and check * A helper opening method. Also a convenient debugging and check
* point. * point.
*
* Locking: always called with BTM already held.
*/ */
static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld) static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld)
...@@ -447,10 +449,10 @@ static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld) ...@@ -447,10 +449,10 @@ static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld)
WARN_ON(test_and_set_bit(TTY_LDISC_OPEN, &tty->flags)); WARN_ON(test_and_set_bit(TTY_LDISC_OPEN, &tty->flags));
if (ld->ops->open) { if (ld->ops->open) {
int ret; int ret;
/* BKL here locks verus a hangup event */ /* BTM here locks versus a hangup event */
lock_kernel(); tty_lock_nested(); /* always held here already */
ret = ld->ops->open(tty); ret = ld->ops->open(tty);
unlock_kernel(); tty_unlock();
return ret; return ret;
} }
return 0; return 0;
...@@ -553,7 +555,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) ...@@ -553,7 +555,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
if (IS_ERR(new_ldisc)) if (IS_ERR(new_ldisc))
return PTR_ERR(new_ldisc); return PTR_ERR(new_ldisc);
lock_kernel(); tty_lock();
/* /*
* We need to look at the tty locking here for pty/tty pairs * We need to look at the tty locking here for pty/tty pairs
* when both sides try to change in parallel. * when both sides try to change in parallel.
...@@ -567,12 +569,12 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) ...@@ -567,12 +569,12 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
*/ */
if (tty->ldisc->ops->num == ldisc) { if (tty->ldisc->ops->num == ldisc) {
unlock_kernel(); tty_unlock();
tty_ldisc_put(new_ldisc); tty_ldisc_put(new_ldisc);
return 0; return 0;
} }
unlock_kernel(); tty_unlock();
/* /*
* Problem: What do we do if this blocks ? * Problem: What do we do if this blocks ?
* We could deadlock here * We could deadlock here
...@@ -594,7 +596,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) ...@@ -594,7 +596,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
mutex_lock(&tty->ldisc_mutex); mutex_lock(&tty->ldisc_mutex);
} }
lock_kernel(); tty_lock();
set_bit(TTY_LDISC_CHANGING, &tty->flags); set_bit(TTY_LDISC_CHANGING, &tty->flags);
...@@ -607,7 +609,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) ...@@ -607,7 +609,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
o_ldisc = tty->ldisc; o_ldisc = tty->ldisc;
unlock_kernel(); tty_unlock();
/* /*
* Make sure we don't change while someone holds a * Make sure we don't change while someone holds a
* reference to the line discipline. The TTY_LDISC bit * reference to the line discipline. The TTY_LDISC bit
...@@ -633,14 +635,14 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) ...@@ -633,14 +635,14 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
flush_scheduled_work(); flush_scheduled_work();
mutex_lock(&tty->ldisc_mutex); mutex_lock(&tty->ldisc_mutex);
lock_kernel(); tty_lock();
if (test_bit(TTY_HUPPED, &tty->flags)) { if (test_bit(TTY_HUPPED, &tty->flags)) {
/* We were raced by the hangup method. It will have stomped /* We were raced by the hangup method. It will have stomped
the ldisc data and closed the ldisc down */ the ldisc data and closed the ldisc down */
clear_bit(TTY_LDISC_CHANGING, &tty->flags); clear_bit(TTY_LDISC_CHANGING, &tty->flags);
mutex_unlock(&tty->ldisc_mutex); mutex_unlock(&tty->ldisc_mutex);
tty_ldisc_put(new_ldisc); tty_ldisc_put(new_ldisc);
unlock_kernel(); tty_unlock();
return -EIO; return -EIO;
} }
...@@ -682,7 +684,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) ...@@ -682,7 +684,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
if (o_work) if (o_work)
schedule_delayed_work(&o_tty->buf.work, 1); schedule_delayed_work(&o_tty->buf.work, 1);
mutex_unlock(&tty->ldisc_mutex); mutex_unlock(&tty->ldisc_mutex);
unlock_kernel(); tty_unlock();
return retval; return retval;
} }
......
...@@ -463,10 +463,10 @@ vcs_open(struct inode *inode, struct file *filp) ...@@ -463,10 +463,10 @@ vcs_open(struct inode *inode, struct file *filp)
unsigned int currcons = iminor(inode) & 127; unsigned int currcons = iminor(inode) & 127;
int ret = 0; int ret = 0;
lock_kernel(); tty_lock();
if(currcons && !vc_cons_allocated(currcons-1)) if(currcons && !vc_cons_allocated(currcons-1))
ret = -ENXIO; ret = -ENXIO;
unlock_kernel(); tty_unlock();
return ret; return ret;
} }
......
...@@ -509,7 +509,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, ...@@ -509,7 +509,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
console = vc->vc_num; console = vc->vc_num;
lock_kernel(); tty_lock();
if (!vc_cons_allocated(console)) { /* impossible? */ if (!vc_cons_allocated(console)) { /* impossible? */
ret = -ENOIOCTLCMD; ret = -ENOIOCTLCMD;
...@@ -1336,7 +1336,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, ...@@ -1336,7 +1336,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
ret = -ENOIOCTLCMD; ret = -ENOIOCTLCMD;
} }
out: out:
unlock_kernel(); tty_unlock();
return ret; return ret;
eperm: eperm:
ret = -EPERM; ret = -EPERM;
...@@ -1503,7 +1503,7 @@ long vt_compat_ioctl(struct tty_struct *tty, struct file * file, ...@@ -1503,7 +1503,7 @@ long vt_compat_ioctl(struct tty_struct *tty, struct file * file,
console = vc->vc_num; console = vc->vc_num;
lock_kernel(); tty_lock();
if (!vc_cons_allocated(console)) { /* impossible? */ if (!vc_cons_allocated(console)) { /* impossible? */
ret = -ENOIOCTLCMD; ret = -ENOIOCTLCMD;
...@@ -1571,11 +1571,11 @@ long vt_compat_ioctl(struct tty_struct *tty, struct file * file, ...@@ -1571,11 +1571,11 @@ long vt_compat_ioctl(struct tty_struct *tty, struct file * file,
goto fallback; goto fallback;
} }
out: out:
unlock_kernel(); tty_unlock();
return ret; return ret;
fallback: fallback:
unlock_kernel(); tty_unlock();
return vt_ioctl(tty, file, cmd, arg); return vt_ioctl(tty, file, cmd, arg);
} }
......
...@@ -1705,7 +1705,7 @@ static void rs_360_wait_until_sent(struct tty_struct *tty, int timeout) ...@@ -1705,7 +1705,7 @@ static void rs_360_wait_until_sent(struct tty_struct *tty, int timeout)
printk("jiff=%lu...", jiffies); printk("jiff=%lu...", jiffies);
#endif #endif
lock_kernel(); tty_lock_nested(); /* always held already since we come from ->close */
/* We go through the loop at least once because we can't tell /* We go through the loop at least once because we can't tell
* exactly when the last character exits the shifter. There can * exactly when the last character exits the shifter. There can
* be at least two characters waiting to be sent after the buffers * be at least two characters waiting to be sent after the buffers
...@@ -1734,7 +1734,7 @@ static void rs_360_wait_until_sent(struct tty_struct *tty, int timeout) ...@@ -1734,7 +1734,7 @@ static void rs_360_wait_until_sent(struct tty_struct *tty, int timeout)
bdp--; bdp--;
} while (bdp->status & BD_SC_READY); } while (bdp->status & BD_SC_READY);
current->state = TASK_RUNNING; current->state = TASK_RUNNING;
unlock_kernel(); tty_unlock();
#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies); printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
#endif #endif
......
...@@ -3935,7 +3935,7 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout) ...@@ -3935,7 +3935,7 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
* Check R_DMA_CHx_STATUS bit 0-6=number of available bytes in FIFO * Check R_DMA_CHx_STATUS bit 0-6=number of available bytes in FIFO
* R_DMA_CHx_HWSW bit 31-16=nbr of bytes left in DMA buffer (0=64k) * R_DMA_CHx_HWSW bit 31-16=nbr of bytes left in DMA buffer (0=64k)
*/ */
lock_kernel(); tty_lock_nested(); /* locked already when coming from close */
orig_jiffies = jiffies; orig_jiffies = jiffies;
while (info->xmit.head != info->xmit.tail || /* More in send queue */ while (info->xmit.head != info->xmit.tail || /* More in send queue */
(*info->ostatusadr & 0x007f) || /* more in FIFO */ (*info->ostatusadr & 0x007f) || /* more in FIFO */
...@@ -3952,7 +3952,7 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout) ...@@ -3952,7 +3952,7 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
curr_time_usec - info->last_tx_active_usec; curr_time_usec - info->last_tx_active_usec;
} }
set_current_state(TASK_RUNNING); set_current_state(TASK_RUNNING);
unlock_kernel(); tty_unlock();
} }
/* /*
......
...@@ -1274,7 +1274,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp) ...@@ -1274,7 +1274,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
struct uart_port *uport; struct uart_port *uport;
unsigned long flags; unsigned long flags;
BUG_ON(!kernel_locked()); BUG_ON(!tty_locked());
if (!state) if (!state)
return; return;
...@@ -1382,7 +1382,7 @@ static void uart_wait_until_sent(struct tty_struct *tty, int timeout) ...@@ -1382,7 +1382,7 @@ static void uart_wait_until_sent(struct tty_struct *tty, int timeout)
if (port->type == PORT_UNKNOWN || port->fifosize == 0) if (port->type == PORT_UNKNOWN || port->fifosize == 0)
return; return;
lock_kernel(); tty_lock_nested(); /* already locked when coming from close */
/* /*
* Set the check interval to be 1/5 of the estimated time to * Set the check interval to be 1/5 of the estimated time to
...@@ -1429,7 +1429,7 @@ static void uart_wait_until_sent(struct tty_struct *tty, int timeout) ...@@ -1429,7 +1429,7 @@ static void uart_wait_until_sent(struct tty_struct *tty, int timeout)
break; break;
} }
set_current_state(TASK_RUNNING); /* might not be needed */ set_current_state(TASK_RUNNING); /* might not be needed */
unlock_kernel(); tty_unlock();
} }
/* /*
...@@ -1444,7 +1444,7 @@ static void uart_hangup(struct tty_struct *tty) ...@@ -1444,7 +1444,7 @@ static void uart_hangup(struct tty_struct *tty)
struct tty_port *port = &state->port; struct tty_port *port = &state->port;
unsigned long flags; unsigned long flags;
BUG_ON(!kernel_locked()); BUG_ON(!tty_locked());
pr_debug("uart_hangup(%d)\n", state->uart_port->line); pr_debug("uart_hangup(%d)\n", state->uart_port->line);
mutex_lock(&port->mutex); mutex_lock(&port->mutex);
...@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp) ...@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
struct tty_port *port; struct tty_port *port;
int retval, line = tty->index; int retval, line = tty->index;
BUG_ON(!kernel_locked()); BUG_ON(!tty_locked());
pr_debug("uart_open(%d) called\n", line); pr_debug("uart_open(%d) called\n", line);
/* /*
......
...@@ -1108,7 +1108,7 @@ static int vgacon_do_font_op(struct vgastate *state,char *arg,int set,int ch512) ...@@ -1108,7 +1108,7 @@ static int vgacon_do_font_op(struct vgastate *state,char *arg,int set,int ch512)
charmap += 4 * cmapsz; charmap += 4 * cmapsz;
#endif #endif
unlock_kernel(); tty_unlock();
spin_lock_irq(&vga_lock); spin_lock_irq(&vga_lock);
/* First, the Sequencer */ /* First, the Sequencer */
vga_wseq(state->vgabase, VGA_SEQ_RESET, 0x1); vga_wseq(state->vgabase, VGA_SEQ_RESET, 0x1);
...@@ -1192,7 +1192,7 @@ static int vgacon_do_font_op(struct vgastate *state,char *arg,int set,int ch512) ...@@ -1192,7 +1192,7 @@ static int vgacon_do_font_op(struct vgastate *state,char *arg,int set,int ch512)
vga_wattr(state->vgabase, VGA_AR_ENABLE_DISPLAY, 0); vga_wattr(state->vgabase, VGA_AR_ENABLE_DISPLAY, 0);
} }
spin_unlock_irq(&vga_lock); spin_unlock_irq(&vga_lock);
lock_kernel(); tty_lock();
return 0; return 0;
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <linux/tty_driver.h> #include <linux/tty_driver.h>
#include <linux/tty_ldisc.h> #include <linux/tty_ldisc.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/smp_lock.h>
#include <asm/system.h> #include <asm/system.h>
...@@ -576,5 +577,35 @@ extern int vt_ioctl(struct tty_struct *tty, struct file *file, ...@@ -576,5 +577,35 @@ extern int vt_ioctl(struct tty_struct *tty, struct file *file,
extern long vt_compat_ioctl(struct tty_struct *tty, struct file * file, extern long vt_compat_ioctl(struct tty_struct *tty, struct file * file,
unsigned int cmd, unsigned long arg); unsigned int cmd, unsigned long arg);
/* functions for preparation of BKL removal */
/*
* tty_lock_nested get the tty_lock while potentially holding it
*
* The Big TTY Mutex is a recursive lock, meaning you can take it
* from a thread that is already holding it.
* This is bad for a number of reasons, so tty_lock_nested should
* really be used as rarely as possible. If a code location can
* be shown to never get called with this held already, it should
* use tty_lock() instead.
*/
static inline void __lockfunc tty_lock_nested(void) __acquires(kernel_lock)
{
lock_kernel();
}
static inline void tty_lock(void) __acquires(kernel_lock)
{
#ifdef CONFIG_LOCK_KERNEL
/* kernel_locked is 1 for !CONFIG_LOCK_KERNEL */
WARN_ON(kernel_locked());
#endif
lock_kernel();
}
static inline void tty_unlock(void) __releases(kernel_lock)
{
unlock_kernel();
}
#define tty_locked() (kernel_locked())
#endif /* __KERNEL__ */ #endif /* __KERNEL__ */
#endif #endif
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