tty: Fix lookahead_buf crash with serdev
PATCH 1/1 tty: Fix lookahead_buf crash with serdev
Do not follow a NULL pointer if the tty_port_client_operations does not implement the ->lookahead_buf() callback, which is the case with serdev's ttyport.
Fixes 6bb6fa6908ebd3 ("tty: Implement lookahead to process XON/XOFF timely")
Signed-off-by Vincent Whitchurch <[email protected]>
--- drivers/tty/tty_buffer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/tty/tty_buffer.c +2 -1
@@ -493,7 +493,8 @@ static void lookahead_bufs(struct tty_port *port, struct tty_buffer *head)if (~head->flags &TTYB_NORMAL ) f =flag_buf_ptr (head, head->lookahead); - port->client_ops->lookahead_buf (port, p, f, count); +if (port->client_ops->lookahead_buf) + port->client_ops->lookahead_buf (port, p, f, count); head->lookahead += count; } }
Signature · 1 line
2.34.1
Quoted 15 lines · Vincent Whitchurch
Do not follow a NULL pointer if the
tty_port_client_operationsdoes not implement the ->lookahead_buf() callback, which is the case with serdev's ttyport.Fixes 6bb6fa6908ebd3 ("tty: Implement lookahead to process XON/XOFF timely")Signed-off-by Vincent Whitchurch <[email protected]>--- drivers/tty/tty_buffer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/tty/tty_buffer.c +0
-0
drivers/tty/tty_buffer.c static void lookahead_bufs(struct tty_port *port, struct tty_buffer *head) · line 497
Quoted 6 lines
drivers/tty/tty_buffer.c +2
-1@@ -493,7 +493,8 @@ static void lookahead_bufs(struct tty_port *port, struct tty_buffer *head)if (~head->flags &TTYB_NORMAL ) f =flag_buf_ptr (head, head->lookahead); - port->client_ops->lookahead_buf (port, p, f, count); +if (port->client_ops->lookahead_buf) + port->client_ops->lookahead_buf (port, p, f, count);
While this works, I'd put the preceeding calculations of p and f into the same block as they just prep parameters for the call.
Quoted 4 lines
drivers/tty/tty_buffer.c +0
-0head->lookahead += count; } }
Signature · 1 line
i.