From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 181ECC00140 for ; Thu, 18 Aug 2022 11:50:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244136AbiHRLul (ORCPT ); Thu, 18 Aug 2022 07:50:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239197AbiHRLub (ORCPT ); Thu, 18 Aug 2022 07:50:31 -0400 Received: from smtp1.axis.com (smtp1.axis.com [195.60.68.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E2C378231 for ; Thu, 18 Aug 2022 04:50:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1660823430; x=1692359430; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=q08MakHc5eVvdV/G/8qb/f8/XhiABt+m4SYHF2LmOHM=; b=OoQrmgt6diNPu3sNH74OKyJQlXJJVrUGEEn078OqSrsh9YmAk0fiSeXp aXVPrZFa6pGxbz3D498MGO3AqloUstuvQKEQuS/2Vphv402a363sNfo39 W3XQiJJ0ZditNYHkNx8ClQQx90n47UQOb337kYjztr0HFIeYts3ShH3V9 BxDAnCWTw6ogEu7sh1BneUwxyma0AYm6SYCsr3BbzRP06KLDccqqSTA88 EJ1/pBdAYH2yPIfAlITXSzSh45uBqxRYvtdW6TNDTbymDRok7pNSfxoD5 mvZpO8He3hyl7wKtp8xhkuB6vO81c3pOR8L4flGcEEfWriioqikJn6CSS Q==; From: Vincent Whitchurch To: Greg Kroah-Hartman , Jiri Slaby CC: , Vincent Whitchurch , Andy Shevchenko , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Subject: [PATCH v2] tty: Fix lookahead_buf crash with serdev Date: Thu, 18 Aug 2022 13:50:26 +0200 Message-ID: <20220818115026.2237893-1-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Notes: v2: Move more stuff into if block. drivers/tty/tty_buffer.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c index 9fdecc795b6b..5e287dedce01 100644 --- a/drivers/tty/tty_buffer.c +++ b/drivers/tty/tty_buffer.c @@ -470,7 +470,6 @@ static void lookahead_bufs(struct tty_port *port, struct tty_buffer *head) while (head) { struct tty_buffer *next; - unsigned char *p, *f = NULL; unsigned int count; /* @@ -489,11 +488,16 @@ static void lookahead_bufs(struct tty_port *port, struct tty_buffer *head) continue; } - p = char_buf_ptr(head, head->lookahead); - if (~head->flags & TTYB_NORMAL) - f = flag_buf_ptr(head, head->lookahead); + if (port->client_ops->lookahead_buf) { + unsigned char *p, *f = NULL; + + p = char_buf_ptr(head, head->lookahead); + if (~head->flags & TTYB_NORMAL) + f = flag_buf_ptr(head, head->lookahead); + + port->client_ops->lookahead_buf(port, p, f, count); + } - port->client_ops->lookahead_buf(port, p, f, count); head->lookahead += count; } } -- 2.34.1