Commit 0a68f64f authored by Alan Cox's avatar Alan Cox Committed by Greg Kroah-Hartman

sdio_uart: Move the open lock

When we move to the tty_port logic the port mutex will protect open v close
v hangup. Move to this first in the existing open code so we have a bisection
point.
Signed-off-by: default avatarAlan Cox <alan@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 530646f4
...@@ -78,7 +78,6 @@ struct sdio_uart_port { ...@@ -78,7 +78,6 @@ struct sdio_uart_port {
struct tty_struct *tty; struct tty_struct *tty;
unsigned int index; unsigned int index;
unsigned int opened; unsigned int opened;
struct mutex open_lock;
struct sdio_func *func; struct sdio_func *func;
struct mutex func_lock; struct mutex func_lock;
struct task_struct *in_sdio_uart_irq; struct task_struct *in_sdio_uart_irq;
...@@ -103,7 +102,6 @@ static int sdio_uart_add_port(struct sdio_uart_port *port) ...@@ -103,7 +102,6 @@ static int sdio_uart_add_port(struct sdio_uart_port *port)
int index, ret = -EBUSY; int index, ret = -EBUSY;
kref_init(&port->kref); kref_init(&port->kref);
mutex_init(&port->open_lock);
mutex_init(&port->func_lock); mutex_init(&port->func_lock);
spin_lock_init(&port->write_lock); spin_lock_init(&port->write_lock);
...@@ -166,7 +164,7 @@ static void sdio_uart_port_remove(struct sdio_uart_port *port) ...@@ -166,7 +164,7 @@ static void sdio_uart_port_remove(struct sdio_uart_port *port)
* give up on that port ASAP. * give up on that port ASAP.
* Beware: the lock ordering is critical. * Beware: the lock ordering is critical.
*/ */
mutex_lock(&port->open_lock); mutex_lock(&port->port.mutex);
mutex_lock(&port->func_lock); mutex_lock(&port->func_lock);
func = port->func; func = port->func;
sdio_claim_host(func); sdio_claim_host(func);
...@@ -179,7 +177,7 @@ static void sdio_uart_port_remove(struct sdio_uart_port *port) ...@@ -179,7 +177,7 @@ static void sdio_uart_port_remove(struct sdio_uart_port *port)
tty_hangup(tty); tty_hangup(tty);
tty_kref_put(tty); tty_kref_put(tty);
} }
mutex_unlock(&port->open_lock); mutex_unlock(&port->port.mutex);
sdio_release_irq(func); sdio_release_irq(func);
sdio_disable_func(func); sdio_disable_func(func);
sdio_release_host(func); sdio_release_host(func);
...@@ -699,14 +697,14 @@ static int sdio_uart_open(struct tty_struct *tty, struct file *filp) ...@@ -699,14 +697,14 @@ static int sdio_uart_open(struct tty_struct *tty, struct file *filp)
if (!port) if (!port)
return -ENODEV; return -ENODEV;
mutex_lock(&port->open_lock); mutex_lock(&port->port.mutex);
/* /*
* Make sure not to mess up with a dead port * Make sure not to mess up with a dead port
* which has not been closed yet. * which has not been closed yet.
*/ */
if (tty->driver_data && tty->driver_data != port) { if (tty->driver_data && tty->driver_data != port) {
mutex_unlock(&port->open_lock); mutex_unlock(&port->port.mutex);
sdio_uart_port_put(port); sdio_uart_port_put(port);
return -EBUSY; return -EBUSY;
} }
...@@ -718,13 +716,13 @@ static int sdio_uart_open(struct tty_struct *tty, struct file *filp) ...@@ -718,13 +716,13 @@ static int sdio_uart_open(struct tty_struct *tty, struct file *filp)
if (ret) { if (ret) {
tty->driver_data = NULL; tty->driver_data = NULL;
tty_port_tty_set(&port->port, NULL); tty_port_tty_set(&port->port, NULL);
mutex_unlock(&port->open_lock); mutex_unlock(&port->port.mutex);
sdio_uart_port_put(port); sdio_uart_port_put(port);
return ret; return ret;
} }
} }
port->opened++; port->opened++;
mutex_unlock(&port->open_lock); mutex_unlock(&port->port.mutex);
return 0; return 0;
} }
...@@ -735,7 +733,7 @@ static void sdio_uart_close(struct tty_struct *tty, struct file * filp) ...@@ -735,7 +733,7 @@ static void sdio_uart_close(struct tty_struct *tty, struct file * filp)
if (!port) if (!port)
return; return;
mutex_lock(&port->open_lock); mutex_lock(&port->port.mutex);
BUG_ON(!port->opened); BUG_ON(!port->opened);
/* /*
...@@ -744,7 +742,7 @@ static void sdio_uart_close(struct tty_struct *tty, struct file * filp) ...@@ -744,7 +742,7 @@ static void sdio_uart_close(struct tty_struct *tty, struct file * filp)
* is larger than port->count. * is larger than port->count.
*/ */
if (tty->count > port->opened) { if (tty->count > port->opened) {
mutex_unlock(&port->open_lock); mutex_unlock(&port->port.mutex);
return; return;
} }
...@@ -756,7 +754,7 @@ static void sdio_uart_close(struct tty_struct *tty, struct file * filp) ...@@ -756,7 +754,7 @@ static void sdio_uart_close(struct tty_struct *tty, struct file * filp)
tty->driver_data = NULL; tty->driver_data = NULL;
tty->closing = 0; tty->closing = 0;
} }
mutex_unlock(&port->open_lock); mutex_unlock(&port->port.mutex);
sdio_uart_port_put(port); sdio_uart_port_put(port);
} }
......
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