提交 49c02304 编写于 作者: P Peter Hurley 提交者: Greg Kroah-Hartman

serial: core: Expand port mutex section in uart_poll_init()

Prepare uart_poll_init() to safely dereference uart port; expand the
port mutex section to guarantee uart port remains valid until
uart_poll_init() completes.
Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 5c0517fe
...@@ -2230,42 +2230,42 @@ static int uart_poll_init(struct tty_driver *driver, int line, char *options) ...@@ -2230,42 +2230,42 @@ static int uart_poll_init(struct tty_driver *driver, int line, char *options)
{ {
struct uart_driver *drv = driver->driver_state; struct uart_driver *drv = driver->driver_state;
struct uart_state *state = drv->state + line; struct uart_state *state = drv->state + line;
struct tty_port *tport;
struct uart_port *port; struct uart_port *port;
int baud = 9600; int baud = 9600;
int bits = 8; int bits = 8;
int parity = 'n'; int parity = 'n';
int flow = 'n'; int flow = 'n';
int ret; int ret = 0;
if (!state || !state->uart_port) if (!state)
return -1; return -1;
tport = &state->port;
mutex_lock(&tport->mutex);
port = state->uart_port; port = state->uart_port;
if (!(port->ops->poll_get_char && port->ops->poll_put_char)) if (!(port->ops->poll_get_char && port->ops->poll_put_char)) {
return -1; ret = -1;
goto out;
}
if (port->ops->poll_init) { if (port->ops->poll_init) {
struct tty_port *tport = &state->port;
ret = 0;
mutex_lock(&tport->mutex);
/* /*
* We don't set initialized as we only initialized the hw, * We don't set initialized as we only initialized the hw,
* e.g. state->xmit is still uninitialized. * e.g. state->xmit is still uninitialized.
*/ */
if (!tty_port_initialized(tport)) if (!tty_port_initialized(tport))
ret = port->ops->poll_init(port); ret = port->ops->poll_init(port);
mutex_unlock(&tport->mutex);
if (ret)
return ret;
} }
if (options) { if (!ret && options) {
uart_parse_options(options, &baud, &parity, &bits, &flow); uart_parse_options(options, &baud, &parity, &bits, &flow);
return uart_set_options(port, NULL, baud, parity, bits, flow); ret = uart_set_options(port, NULL, baud, parity, bits, flow);
} }
out:
return 0; mutex_unlock(&tport->mutex);
return ret;
} }
static int uart_poll_get_char(struct tty_driver *driver, int line) static int uart_poll_get_char(struct tty_driver *driver, int line)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册