From nobody Sat Feb 7 18:15:15 2026 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 7B7DFEB64DD for ; Wed, 12 Jul 2023 06:42:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231765AbjGLGmb (ORCPT ); Wed, 12 Jul 2023 02:42:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231436AbjGLGmX (ORCPT ); Wed, 12 Jul 2023 02:42:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56B13DC; Tue, 11 Jul 2023 23:42:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DB147616C6; Wed, 12 Jul 2023 06:42:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41D4CC433CA; Wed, 12 Jul 2023 06:42:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689144141; bh=4M+311SCFHjZNmmXmuQ/Cv4yRF1MEJ3AD4kmj9Cg3lk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N4MG+dAtkwpcmoTDEbe3jbtoPQXG8HG25mU6Pi7CLiLQTLpSGarELUrU7MDOkZ1Vv SqqMV5XJdK8TBQ/sEZA5PZM2I149HIdh9JLMpHRoie7v6AQkb7kHh5c2WTEEHXkHki IKIynxUXpaBPA7QrJT/tPtaq7IrfAD6uPpTQ3eMJFV7B4e/IFkCgZiN9FJsHWtgBgG zxDXV82q39SLJIQWnSiHLNJjWAIDvCFo5xNpzghZW6rXNnCUzc28lFkZYxrF04/P52 08RKQJhg0XQurQkI9ho+d9RWBFvUs7o80T1Q+QS20iMGWBHp5oK/tqnK83vq6XEm8I HH7XqOzgX2TGg== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 1/4] n_tty: drop fp from n_tty_receive_buf_real_raw() Date: Wed, 12 Jul 2023 08:42:13 +0200 Message-ID: <20230712064216.12150-2-jirislaby@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230712064216.12150-1-jirislaby@kernel.org> References: <20230712064216.12150-1-jirislaby@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The 'fp' parameter of n_tty_receive_buf_real_raw() is unused, so drop it. Signed-off-by: Jiri Slaby (SUSE) --- drivers/tty/n_tty.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c index 552e8a741562..1599012f20c8 100644 --- a/drivers/tty/n_tty.c +++ b/drivers/tty/n_tty.c @@ -1502,7 +1502,7 @@ static void n_tty_lookahead_flow_ctrl(struct tty_stru= ct *tty, const unsigned cha =20 static void n_tty_receive_buf_real_raw(struct tty_struct *tty, const unsigned char *cp, - const char *fp, int count) + int count) { struct n_tty_data *ldata =3D tty->disc_data; size_t n, head; @@ -1597,7 +1597,7 @@ static void __receive_buf(struct tty_struct *tty, con= st unsigned char *cp, size_t la_count =3D min_t(size_t, ldata->lookahead_count, count); =20 if (ldata->real_raw) - n_tty_receive_buf_real_raw(tty, cp, fp, count); + n_tty_receive_buf_real_raw(tty, cp, count); else if (ldata->raw || (L_EXTPROC(tty) && !preops)) n_tty_receive_buf_raw(tty, cp, fp, count); else if (tty->closing && !L_EXTPROC(tty)) { --=20 2.41.0 From nobody Sat Feb 7 18:15:15 2026 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 71756EB64DA for ; Wed, 12 Jul 2023 06:42:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230399AbjGLGmh (ORCPT ); Wed, 12 Jul 2023 02:42:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231417AbjGLGmY (ORCPT ); Wed, 12 Jul 2023 02:42:24 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5706F0; Tue, 11 Jul 2023 23:42:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 62172616E1; Wed, 12 Jul 2023 06:42:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9393C433C9; Wed, 12 Jul 2023 06:42:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689144142; bh=CJX8SlHepZCFBu+LS4vVyP3RzICxchrVKsWPVGHPYpw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U6Gie6O9A3O459QBabIn//QM15zKQA/tPiBY12tiUfnPVO6GDmsVZpUqPBFQHPY5t pAH5De2DsESSlJPIgf9jk871/t/HnaQwO8WEO5KtUq9RNcbfV2b/hIR+Hu4PSCAaAB Wluw0VFct/Ppnkj4dFWTpP/dkhTr01XNyUY+ikIrMCA/zba3n2q+ADdBvAoIJ99MqZ omwXLBUADJ4m1mQ9DlqONBuBqBpxYj/q+S3Jbp/Rxh1W0Ssx7mz/1KvHwrho1MZK8Z IZsvRvaVdgXqDOhfvFQymzROAC7u6Po3RQN/gd3PHVfXgtBy2pqDCwAncFJAu1JFFS Dx85An/jWdHbw== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 2/4] n_tty: simplify and sanitize zero_buffer() Date: Wed, 12 Jul 2023 08:42:14 +0200 Message-ID: <20230712064216.12150-3-jirislaby@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230712064216.12150-1-jirislaby@kernel.org> References: <20230712064216.12150-1-jirislaby@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" * Make 'tty' parameter const as we only look at tty flags here. * Make 'size' parameter of size_t type as everyone passes that and memset() (the consumer) expects size_t too. So be consistent. * Remove redundant local variables, place the content directly to the 'if'. * Use 0 instead of 0x00 in memset(). The former is more obvious. No functional changes expected. Signed-off-by: Jiri Slaby (SUSE) --- drivers/tty/n_tty.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c index 1599012f20c8..c1859ae263eb 100644 --- a/drivers/tty/n_tty.c +++ b/drivers/tty/n_tty.c @@ -158,13 +158,10 @@ static inline unsigned char *echo_buf_addr(struct n_t= ty_data *ldata, size_t i) } =20 /* If we are not echoing the data, perhaps this is a secret so erase it */ -static void zero_buffer(struct tty_struct *tty, u8 *buffer, int size) +static void zero_buffer(const struct tty_struct *tty, u8 *buffer, size_t s= ize) { - bool icanon =3D !!L_ICANON(tty); - bool no_echo =3D !L_ECHO(tty); - - if (icanon && no_echo) - memset(buffer, 0x00, size); + if (L_ICANON(tty) && !L_ECHO(tty)) + memset(buffer, 0, size); } =20 static void tty_copy(struct tty_struct *tty, void *to, size_t tail, size_t= n) --=20 2.41.0 From nobody Sat Feb 7 18:15:15 2026 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 365F1EB64DD for ; Wed, 12 Jul 2023 06:42:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231916AbjGLGmj (ORCPT ); Wed, 12 Jul 2023 02:42:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231226AbjGLGm1 (ORCPT ); Wed, 12 Jul 2023 02:42:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6F9910EF; Tue, 11 Jul 2023 23:42:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D625F615BC; Wed, 12 Jul 2023 06:42:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D0DCC433CB; Wed, 12 Jul 2023 06:42:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689144144; bh=Qb5Il4Ai3jz4ymmAYs7Bq9ZdwscdsCLE+1C9yMaXeVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=As2rNQVfalJRMvLFNrtv1VrG5i7f59JwKdMVkYfEN0aTq5+AVknDuK7Gmqre9vg+z YSJ19JB5AE75G37Clf3Ed5e0HxDWJjnJ1j1gdlRRfdIU2pXMO05SEFbLBL1JJvoNka iYomw+cAJjBHZeDngNFwbWlhZujNFQweWMOmg+13Tb58KcpQy+ZFyLCMGdUQjUDDCU STiVOMdGvJD9t0Gc3V6bUcXImDEsHNfFSiyxxFpbw1uWYFVBX+zPpHjyHTaF0sO/ab 0GXmce6yxw7+P0Lr8A+a3WOU71hL42kL4e+tz6vkd7Fb961a1ijO9BpQaQZgHTXWBH z1zqZNjI/Pztw== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 3/4] n_tty: pass ldata to canon_skip_eof() directly Date: Wed, 12 Jul 2023 08:42:15 +0200 Message-ID: <20230712064216.12150-4-jirislaby@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230712064216.12150-1-jirislaby@kernel.org> References: <20230712064216.12150-1-jirislaby@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 'tty' is not needed in canon_skip_eof(), so we can pass 'ldata' directly instead. Signed-off-by: Jiri Slaby (SUSE) --- drivers/tty/n_tty.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c index c1859ae263eb..bab7005ef520 100644 --- a/drivers/tty/n_tty.c +++ b/drivers/tty/n_tty.c @@ -2053,9 +2053,8 @@ static bool canon_copy_from_read_buf(struct tty_struc= t *tty, * EOF (special EOL character that's a __DISABLED_CHAR) * in the stream, silently eat the EOF. */ -static void canon_skip_eof(struct tty_struct *tty) +static void canon_skip_eof(struct n_tty_data *ldata) { - struct n_tty_data *ldata =3D tty->disc_data; size_t tail, canon_head; =20 canon_head =3D smp_load_acquire(&ldata->canon_head); @@ -2153,7 +2152,7 @@ static ssize_t n_tty_read(struct tty_struct *tty, str= uct file *file, * releasing the lock and returning done. */ if (!nr) - canon_skip_eof(tty); + canon_skip_eof(ldata); else if (canon_copy_from_read_buf(tty, &kb, &nr)) return kb - kbuf; } else { --=20 2.41.0 From nobody Sat Feb 7 18:15:15 2026 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 91BA0EB64DA for ; Wed, 12 Jul 2023 06:42:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231533AbjGLGml (ORCPT ); Wed, 12 Jul 2023 02:42:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231572AbjGLGm3 (ORCPT ); Wed, 12 Jul 2023 02:42:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B761510F2; Tue, 11 Jul 2023 23:42:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 56293616E6; Wed, 12 Jul 2023 06:42:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B492EC433C9; Wed, 12 Jul 2023 06:42:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689144145; bh=GFYfNtNLbJlEVMFARX9D95/viTg0poYGqyqRS7iGZIk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oZ1wldekR0t0ek/LvRcS1k1M6WxZ0PEZQy+pRkKD2d9FDyitlyTDs4DdqG4CjWdNE RDH3g544uw/QjV9wX7idZAZon2ChoBszPFrVha5kDrjP2qLZi+tv+NDMfWY3Zn0KB2 z55/WUxClIGQaafrymmtXI0Z1KPc1t3AA7XU8NLdB92BarOUBb57/iQT9lA8K+bWrZ arJoaU8xzshPCqBuNx5xgYFh0lBNeG6SUDf2SBh/qVNajhSK8R93bgHiQrW0szZf8J 6sh84rH8HuO1xFG/xRM+JCiU0oqARbORsVzZS5hCQC+jr6JLZ2kKyh+BFs94dA9Lo1 rzHUC51jE30+w== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 4/4] n_tty: make many tty parameters const Date: Wed, 12 Jul 2023 08:42:16 +0200 Message-ID: <20230712064216.12150-5-jirislaby@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230712064216.12150-1-jirislaby@kernel.org> References: <20230712064216.12150-1-jirislaby@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In many n_tty functions, the 'tty' parameter is used to either obtain 'ldata', or test the tty flags. So mark 'tty' in them const to make obvious that it is only read. Signed-off-by: Jiri Slaby (SUSE) --- drivers/tty/n_tty.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c index bab7005ef520..0043cc84b91a 100644 --- a/drivers/tty/n_tty.c +++ b/drivers/tty/n_tty.c @@ -164,7 +164,8 @@ static void zero_buffer(const struct tty_struct *tty, u= 8 *buffer, size_t size) memset(buffer, 0, size); } =20 -static void tty_copy(struct tty_struct *tty, void *to, size_t tail, size_t= n) +static void tty_copy(const struct tty_struct *tty, void *to, size_t tail, + size_t n) { struct n_tty_data *ldata =3D tty->disc_data; size_t size =3D N_TTY_BUF_SIZE - tail; @@ -195,7 +196,7 @@ static void tty_copy(struct tty_struct *tty, void *to, = size_t tail, size_t n) * * n_tty_read()/consumer path: * holds non-exclusive %termios_rwsem */ -static void n_tty_kick_worker(struct tty_struct *tty) +static void n_tty_kick_worker(const struct tty_struct *tty) { struct n_tty_data *ldata =3D tty->disc_data; =20 @@ -215,9 +216,9 @@ static void n_tty_kick_worker(struct tty_struct *tty) } } =20 -static ssize_t chars_in_buffer(struct tty_struct *tty) +static ssize_t chars_in_buffer(const struct tty_struct *tty) { - struct n_tty_data *ldata =3D tty->disc_data; + const struct n_tty_data *ldata =3D tty->disc_data; ssize_t n =3D 0; =20 if (!ldata->icanon) @@ -393,7 +394,7 @@ static inline int is_utf8_continuation(unsigned char c) * Returns: true if the utf8 character @c is a multibyte continuation char= acter * and the terminal is in unicode mode. */ -static inline int is_continuation(unsigned char c, struct tty_struct *tty) +static inline int is_continuation(unsigned char c, const struct tty_struct= *tty) { return I_IUTF8(tty) && is_utf8_continuation(c); } @@ -913,7 +914,7 @@ static void echo_char_raw(unsigned char c, struct n_tty= _data *ldata) * This variant tags control characters to be echoed as "^X" (where X is t= he * letter representing the control char). */ -static void echo_char(unsigned char c, struct tty_struct *tty) +static void echo_char(unsigned char c, const struct tty_struct *tty) { struct n_tty_data *ldata =3D tty->disc_data; =20 @@ -951,7 +952,7 @@ static inline void finish_erasing(struct n_tty_data *ld= ata) * Locking: n_tty_receive_buf()/producer path: * caller holds non-exclusive %termios_rwsem */ -static void eraser(unsigned char c, struct tty_struct *tty) +static void eraser(unsigned char c, const struct tty_struct *tty) { struct n_tty_data *ldata =3D tty->disc_data; enum { ERASE, WERASE, KILL } kill_type; @@ -1167,7 +1168,7 @@ static void n_tty_receive_break(struct tty_struct *tt= y) * Called from the receive_buf path so single threaded. Does not need lock= ing * as num_overrun and overrun_time are function private. */ -static void n_tty_receive_overrun(struct tty_struct *tty) +static void n_tty_receive_overrun(const struct tty_struct *tty) { struct n_tty_data *ldata =3D tty->disc_data; =20 @@ -1191,7 +1192,8 @@ static void n_tty_receive_overrun(struct tty_struct *= tty) * Locking: n_tty_receive_buf()/producer path: * caller holds non-exclusive %termios_rwsem */ -static void n_tty_receive_parity_error(struct tty_struct *tty, unsigned ch= ar c) +static void n_tty_receive_parity_error(const struct tty_struct *tty, + unsigned char c) { struct n_tty_data *ldata =3D tty->disc_data; =20 @@ -1498,8 +1500,8 @@ static void n_tty_lookahead_flow_ctrl(struct tty_stru= ct *tty, const unsigned cha } =20 static void -n_tty_receive_buf_real_raw(struct tty_struct *tty, const unsigned char *cp, - int count) +n_tty_receive_buf_real_raw(const struct tty_struct *tty, + const unsigned char *cp, int count) { struct n_tty_data *ldata =3D tty->disc_data; size_t n, head; @@ -1900,9 +1902,9 @@ static int n_tty_open(struct tty_struct *tty) return 0; } =20 -static inline int input_available_p(struct tty_struct *tty, int poll) +static inline int input_available_p(const struct tty_struct *tty, int poll) { - struct n_tty_data *ldata =3D tty->disc_data; + const struct n_tty_data *ldata =3D tty->disc_data; int amt =3D poll && !TIME_CHAR(tty) && MIN_CHAR(tty) ? MIN_CHAR(tty) : 1; =20 if (ldata->icanon && !L_EXTPROC(tty)) @@ -1929,7 +1931,7 @@ static inline int input_available_p(struct tty_struct= *tty, int poll) * caller holds non-exclusive %termios_rwsem; * read_tail published */ -static bool copy_from_read_buf(struct tty_struct *tty, +static bool copy_from_read_buf(const struct tty_struct *tty, unsigned char **kbp, size_t *nr) =20 @@ -1984,7 +1986,7 @@ static bool copy_from_read_buf(struct tty_struct *tty, * caller holds non-exclusive %termios_rwsem; * read_tail published */ -static bool canon_copy_from_read_buf(struct tty_struct *tty, +static bool canon_copy_from_read_buf(const struct tty_struct *tty, unsigned char **kbp, size_t *nr) { --=20 2.41.0