diff options
author | Andy Shevchenko <andriy.shevchenko@linux.intel.com> | 2016-11-24 07:18:55 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-11-28 02:29:34 -0500 |
commit | ef510bea5f6c16663428d914699935bdd7913de8 (patch) | |
tree | 41fe7486117b40f78d795a73a1f3236cab1493ac | |
parent | b8106454733806b56c87493042da77b3b8b48d22 (diff) |
serial: core: don't check port twice in a row
There is no need to check port for NULL in uart_port_deref() since we call it
only when port is defined.
There are few places that violate this. Fix them here as well.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/tty/serial/serial_core.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index f2303f390345..d0847375ea64 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c | |||
@@ -73,7 +73,7 @@ static inline struct uart_port *uart_port_ref(struct uart_state *state) | |||
73 | 73 | ||
74 | static inline void uart_port_deref(struct uart_port *uport) | 74 | static inline void uart_port_deref(struct uart_port *uport) |
75 | { | 75 | { |
76 | if (uport && atomic_dec_and_test(&uport->state->refcount)) | 76 | if (atomic_dec_and_test(&uport->state->refcount)) |
77 | wake_up(&uport->state->remove_wait); | 77 | wake_up(&uport->state->remove_wait); |
78 | } | 78 | } |
79 | 79 | ||
@@ -88,9 +88,10 @@ static inline void uart_port_deref(struct uart_port *uport) | |||
88 | #define uart_port_unlock(uport, flags) \ | 88 | #define uart_port_unlock(uport, flags) \ |
89 | ({ \ | 89 | ({ \ |
90 | struct uart_port *__uport = uport; \ | 90 | struct uart_port *__uport = uport; \ |
91 | if (__uport) \ | 91 | if (__uport) { \ |
92 | spin_unlock_irqrestore(&__uport->lock, flags); \ | 92 | spin_unlock_irqrestore(&__uport->lock, flags); \ |
93 | uart_port_deref(__uport); \ | 93 | uart_port_deref(__uport); \ |
94 | } \ | ||
94 | }) | 95 | }) |
95 | 96 | ||
96 | static inline struct uart_port *uart_port_check(struct uart_state *state) | 97 | static inline struct uart_port *uart_port_check(struct uart_state *state) |
@@ -1515,7 +1516,10 @@ static void uart_wait_until_sent(struct tty_struct *tty, int timeout) | |||
1515 | unsigned long char_time, expire; | 1516 | unsigned long char_time, expire; |
1516 | 1517 | ||
1517 | port = uart_port_ref(state); | 1518 | port = uart_port_ref(state); |
1518 | if (!port || port->type == PORT_UNKNOWN || port->fifosize == 0) { | 1519 | if (!port) |
1520 | return; | ||
1521 | |||
1522 | if (port->type == PORT_UNKNOWN || port->fifosize == 0) { | ||
1519 | uart_port_deref(port); | 1523 | uart_port_deref(port); |
1520 | return; | 1524 | return; |
1521 | } | 1525 | } |
@@ -2365,9 +2369,10 @@ static int uart_poll_get_char(struct tty_driver *driver, int line) | |||
2365 | 2369 | ||
2366 | if (state) { | 2370 | if (state) { |
2367 | port = uart_port_ref(state); | 2371 | port = uart_port_ref(state); |
2368 | if (port) | 2372 | if (port) { |
2369 | ret = port->ops->poll_get_char(port); | 2373 | ret = port->ops->poll_get_char(port); |
2370 | uart_port_deref(port); | 2374 | uart_port_deref(port); |
2375 | } | ||
2371 | } | 2376 | } |
2372 | return ret; | 2377 | return ret; |
2373 | } | 2378 | } |