Skip to content

Commit 56c14fb

Browse files
vwaxgregkh
authored andcommitted
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. Reported-by: Hans de Goede <hdegoede@redhat.com> Fixes: 6bb6fa6 ("tty: Implement lookahead to process XON/XOFF timely") Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com> Link: https://lore.kernel.org/r/20220818115026.2237893-1-vincent.whitchurch@axis.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 846651e commit 56c14fb

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

drivers/tty/tty_buffer.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,6 @@ static void lookahead_bufs(struct tty_port *port, struct tty_buffer *head)
470470

471471
while (head) {
472472
struct tty_buffer *next;
473-
unsigned char *p, *f = NULL;
474473
unsigned int count;
475474

476475
/*
@@ -489,11 +488,16 @@ static void lookahead_bufs(struct tty_port *port, struct tty_buffer *head)
489488
continue;
490489
}
491490

492-
p = char_buf_ptr(head, head->lookahead);
493-
if (~head->flags & TTYB_NORMAL)
494-
f = flag_buf_ptr(head, head->lookahead);
491+
if (port->client_ops->lookahead_buf) {
492+
unsigned char *p, *f = NULL;
493+
494+
p = char_buf_ptr(head, head->lookahead);
495+
if (~head->flags & TTYB_NORMAL)
496+
f = flag_buf_ptr(head, head->lookahead);
497+
498+
port->client_ops->lookahead_buf(port, p, f, count);
499+
}
495500

496-
port->client_ops->lookahead_buf(port, p, f, count);
497501
head->lookahead += count;
498502
}
499503
}

0 commit comments

Comments
 (0)