diff options
author | Chen Gang <gang.chen@asianux.com> | 2012-12-27 15:51:31 +0800 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-01-15 23:00:44 -0800 |
commit | b342dd512f7af0e0e14e29c3e1f863150cfc46ff (patch) | |
tree | 46deb7479d463bb04f426c46b38f12b64060bb01 | |
parent | 074d35cebe96da07ac07f78118bc6a09e60350b5 (diff) | |
download | op-kernel-dev-b342dd512f7af0e0e14e29c3e1f863150cfc46ff.zip op-kernel-dev-b342dd512f7af0e0e14e29c3e1f863150cfc46ff.tar.gz |
drivers/tty/serial: extern function which for release resource, need check pointer, before free it
for extern function uart_remove_one_port:
need check pointer whether be NULL, before the main work.
just like what the other extern function uart_add_one_port has done.
uart_add_one_port and uart_remove_one_port are pair
information:
for the callers (such as drivers/tty/serial/jsm: jsm_tty.c, jsm_driver.c)
they realy assume that:
they still can call uart_remove_one_port, after uart_add_one_port failed
we (as an extern function), have to understand it (just like kfree).
Signed-off-by: Chen Gang <gang.chen@asianux.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/tty/serial/serial_core.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index b5c4e64..ca98a3f 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -2643,6 +2643,7 @@ int uart_remove_one_port(struct uart_driver *drv, struct uart_port *uport) { struct uart_state *state = drv->state + uport->line; struct tty_port *port = &state->port; + int ret = 0; BUG_ON(in_interrupt()); @@ -2657,6 +2658,11 @@ int uart_remove_one_port(struct uart_driver *drv, struct uart_port *uport) * succeeding while we shut down the port. */ mutex_lock(&port->mutex); + if (!state->uart_port) { + mutex_unlock(&port->mutex); + ret = -EINVAL; + goto out; + } uport->flags |= UPF_DEAD; mutex_unlock(&port->mutex); @@ -2680,9 +2686,10 @@ int uart_remove_one_port(struct uart_driver *drv, struct uart_port *uport) uport->type = PORT_UNKNOWN; state->uart_port = NULL; +out: mutex_unlock(&port_mutex); - return 0; + return ret; } /* |