public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tty: Fix lookahead_buf crash with serdev
@ 2022-08-16  7:11 Vincent Whitchurch
  2022-08-16  7:21 ` Ilpo Järvinen
  0 siblings, 1 reply; 2+ messages in thread
From: Vincent Whitchurch @ 2022-08-16  7:11 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: kernel, Vincent Whitchurch, Andy Shevchenko, Ilpo Järvinen,
	linux-kernel

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 <vincent.whitchurch@axis.com>
---
 drivers/tty/tty_buffer.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
index 9fdecc795b6b..a1c97d4a45fb 100644
--- a/drivers/tty/tty_buffer.c
+++ b/drivers/tty/tty_buffer.c
@@ -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;
 	}
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] tty: Fix lookahead_buf crash with serdev
  2022-08-16  7:11 [PATCH] tty: Fix lookahead_buf crash with serdev Vincent Whitchurch
@ 2022-08-16  7:21 ` Ilpo Järvinen
  0 siblings, 0 replies; 2+ messages in thread
From: Ilpo Järvinen @ 2022-08-16  7:21 UTC (permalink / raw)
  To: Vincent Whitchurch
  Cc: Greg Kroah-Hartman, Jiri Slaby, kernel, Andy Shevchenko, LKML

On Tue, 16 Aug 2022, Vincent Whitchurch wrote:

> 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 <vincent.whitchurch@axis.com>
> ---
>  drivers/tty/tty_buffer.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
> index 9fdecc795b6b..a1c97d4a45fb 100644
> --- a/drivers/tty/tty_buffer.c
> +++ b/drivers/tty/tty_buffer.c
> @@ -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.

>  		head->lookahead += count;
>  	}
>  }
> 

-- 
 i.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-08-16  9:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-16  7:11 [PATCH] tty: Fix lookahead_buf crash with serdev Vincent Whitchurch
2022-08-16  7:21 ` Ilpo Järvinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox