Skip to contentSkip to conversation

tty: Fix lookahead_buf crash with serdev

PATCH Superseded Vincent Whitchurch 2 participants 2 messages Aug 16, 2022 TTY layer and serial drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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")
---
 drivers/tty/tty_buffer.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/tty/tty_buffer.c +2 -1
index 9fdecc795b6b..a1c97d4a45fb 100644
@@ -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
#1 lore raw
Quoted 15 lines · Vincent Whitchurch

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")
---
 drivers/tty/tty_buffer.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/tty/tty_buffer.c +0 -0
index 9fdecc795b6b..a1c97d4a45fb 100644

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 -0
 		head->lookahead += count;
 	}
 }
Signature · 1 line
 i.