提交 e8c65d14 编写于 作者: A Alan Cox 提交者: Greg Kroah-Hartman

nozomi: Fix mutex handling

The original author didn't realise the kernel lock was a drop while sleep
lock so did clever (and wrong) things to work around the non need to avoid
deadlocks. Remove the cleverness and the comment (as we don't hold the BKL
now anyway in those paths)
Signed-off-by: NAlan Cox <alan@linux.intel.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 266794eb
...@@ -1693,15 +1693,7 @@ static int ntty_write(struct tty_struct *tty, const unsigned char *buffer, ...@@ -1693,15 +1693,7 @@ static int ntty_write(struct tty_struct *tty, const unsigned char *buffer,
if (!dc || !port) if (!dc || !port)
return -ENODEV; return -ENODEV;
if (unlikely(!mutex_trylock(&port->tty_sem))) { mutex_lock(&port->tty_sem);
/*
* must test lock as tty layer wraps calls
* to this function with BKL
*/
dev_err(&dc->pdev->dev, "Would have deadlocked - "
"return EAGAIN\n");
return -EAGAIN;
}
if (unlikely(!port->port.count)) { if (unlikely(!port->port.count)) {
DBG1(" "); DBG1(" ");
...@@ -1741,25 +1733,23 @@ static int ntty_write(struct tty_struct *tty, const unsigned char *buffer, ...@@ -1741,25 +1733,23 @@ static int ntty_write(struct tty_struct *tty, const unsigned char *buffer,
* This method is called by the upper tty layer. * This method is called by the upper tty layer.
* #according to sources N_TTY.c it expects a value >= 0 and * #according to sources N_TTY.c it expects a value >= 0 and
* does not check for negative values. * does not check for negative values.
*
* If the port is unplugged report lots of room and let the bits
* dribble away so we don't block anything.
*/ */
static int ntty_write_room(struct tty_struct *tty) static int ntty_write_room(struct tty_struct *tty)
{ {
struct port *port = tty->driver_data; struct port *port = tty->driver_data;
int room = 0; int room = 4096;
const struct nozomi *dc = get_dc_by_tty(tty); const struct nozomi *dc = get_dc_by_tty(tty);
if (!dc || !port) if (dc) {
return 0; mutex_lock(&port->tty_sem);
if (!mutex_trylock(&port->tty_sem)) if (port->port.count)
return 0; room = port->fifo_ul.size -
kfifo_len(&port->fifo_ul);
if (!port->port.count)
goto exit;
room = port->fifo_ul.size - kfifo_len(&port->fifo_ul);
exit:
mutex_unlock(&port->tty_sem); mutex_unlock(&port->tty_sem);
}
return room; return room;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册