Skip to content

Commit 22077b0

Browse files
Jiri Slabygregkh
authored andcommitted
tty: serial_core, remove state checks in uart_poll*
Coverity complains about uart_state checks in polling functions. And it is indeed correct. We do something like this: struct uart_state *state = drv->state + line; if (!state) return; Adding 'line' to drv->state would move the potential NULL pointer to something near NULL and the check is useless. Even if we checked pure drv->state, nothing guarantees it is not freed and NULLed after the check. So if the only user of this interface (kgdboc) needs to assure something, this is neither the correct thing, nor place to do so. Signed-off-by: Jiri Slaby <jslaby@suse.cz> Cc: linux-serial@vger.kernel.org Cc: Jason Wessel <jason.wessel@windriver.com> Cc: kgdb-bugreport@lists.sourceforge.net Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fab8a02 commit 22077b0

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

drivers/tty/serial/serial_core.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,9 +2331,6 @@ static int uart_poll_init(struct tty_driver *driver, int line, char *options)
23312331
int flow = 'n';
23322332
int ret = 0;
23332333

2334-
if (!state)
2335-
return -1;
2336-
23372334
tport = &state->port;
23382335
mutex_lock(&tport->mutex);
23392336

@@ -2368,13 +2365,12 @@ static int uart_poll_get_char(struct tty_driver *driver, int line)
23682365
struct uart_port *port;
23692366
int ret = -1;
23702367

2371-
if (state) {
2372-
port = uart_port_ref(state);
2373-
if (port) {
2374-
ret = port->ops->poll_get_char(port);
2375-
uart_port_deref(port);
2376-
}
2368+
port = uart_port_ref(state);
2369+
if (port) {
2370+
ret = port->ops->poll_get_char(port);
2371+
uart_port_deref(port);
23772372
}
2373+
23782374
return ret;
23792375
}
23802376

@@ -2384,9 +2380,6 @@ static void uart_poll_put_char(struct tty_driver *driver, int line, char ch)
23842380
struct uart_state *state = drv->state + line;
23852381
struct uart_port *port;
23862382

2387-
if (!state)
2388-
return;
2389-
23902383
port = uart_port_ref(state);
23912384
if (!port)
23922385
return;

0 commit comments

Comments
 (0)