From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-sn1nam02on0127.outbound.protection.outlook.com ([104.47.36.127]:18752 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729202AbeIOGtt (ORCPT ); Sat, 15 Sep 2018 02:49:49 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Johan Hovold , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH AUTOSEL 4.14 24/57] tty: fix termios input-speed encoding when using BOTHER Date: Sat, 15 Sep 2018 01:32:44 +0000 Message-ID: <20180915013223.179909-24-alexander.levin@microsoft.com> References: <20180915013223.179909-1-alexander.levin@microsoft.com> In-Reply-To: <20180915013223.179909-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Johan Hovold [ Upstream commit 1cee38f0363a88db374e50b232ca17b9a4c12fa0 ] When the termios CIBAUD bits are left unset (i.e. B0), we use the same output and input speed and should leave CIBAUD unchanged. When the user requests a rate using BOTHER and c_ospeed which the driver cannot set exactly, the driver can report back the actual baud rate using tty_termios_encode_baud_rate(). If this rate is close enough to a standard rate however, we could end up setting CIBAUD to a Bfoo value despite the user having left it unset. This in turn could lead to an unexpected input rate being set on subsequent termios updates. Fix this by using a zero tolerance value also for the input rate when CIBAUD is clear so that the matching logic works as expected. Fixes: 78137e3b34e1 ("[PATCH] tty: improve encode_baud_rate logic") Signed-off-by: Johan Hovold Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/tty_baudrate.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/tty/tty_baudrate.c b/drivers/tty/tty_baudrate.c index 5c33fd25676d..8457bb941e1a 100644 --- a/drivers/tty/tty_baudrate.c +++ b/drivers/tty/tty_baudrate.c @@ -156,16 +156,20 @@ void tty_termios_encode_baud_rate(struct ktermios *te= rmios, termios->c_ospeed =3D obaud; =20 #ifdef BOTHER + if ((termios->c_cflag >> IBSHIFT) & CBAUD) + ibinput =3D 1; /* An input speed was specified */ + /* If the user asked for a precise weird speed give a precise weird answer. If they asked for a Bfoo speed they may have problems digesting non-exact replies so fuzz a bit */ =20 - if ((termios->c_cflag & CBAUD) =3D=3D BOTHER) + if ((termios->c_cflag & CBAUD) =3D=3D BOTHER) { oclose =3D 0; + if (!ibinput) + iclose =3D 0; + } if (((termios->c_cflag >> IBSHIFT) & CBAUD) =3D=3D BOTHER) iclose =3D 0; - if ((termios->c_cflag >> IBSHIFT) & CBAUD) - ibinput =3D 1; /* An input speed was specified */ #endif termios->c_cflag &=3D ~CBAUD; =20 --=20 2.17.1