Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2981753imu; Sun, 9 Dec 2018 14:13:50 -0800 (PST) X-Google-Smtp-Source: AFSGD/V4djXYZnDnb6PGlCHwz4mhL0M+/3recgOxMXSim9WWuEVqYPeWPlsZgal2YN+3zMv95hp3 X-Received: by 2002:a63:df13:: with SMTP id u19mr8907580pgg.294.1544393630218; Sun, 09 Dec 2018 14:13:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544393630; cv=none; d=google.com; s=arc-20160816; b=Pd84x9Oh4bQAb+TUhLicLf3dqCGJN2lJPrN0aHu7Ksz3QRFfEL28cnhvZkfRWVEsb8 FEL614qoyduTpQ985awm0wi7engIviOzXVHNC3/WDAnUOPeb757lLSARDwe64wAAbLQj PXjcM/euwuEW5kShbOq6kWIS4PRErj1809ph//omw7aAg2ylf4zug2V5g/fWkfQVQmct 4WnVUUcHOO/U13h6WfcjUAnrt/mG8qohGPJPmb/+XUV6XdCtGv8aWpDfJED8etxrEaLJ Oy0zVKiemAfDBPN+ywiyAgZnI+xpiNFfIZjX6CdoOkzGkdXktvC8FSP5a1fuWXRFAnoc wGtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=ElSt1zarZyJLs8BKV2i7kqyugOVcwn4EvjSX0Sd6bg0=; b=wDTBelQhJCPZAArnNhUlZEAHjxqXzpfjWIrnsZlgSsLB5gL2++KlVpwici1WTGcEi7 VHWDfp8FClBmeUSrEe+m18a1P3zlm4puumUw5fVHBdYhNOyzEzt9N7jwqQkajMyksoFW icP8kHuwRicH2RRNQHZhFUhifT9G/ylqgR8JLEQ4xcrpUAfoXKtOFkj1cRFrgR/717uU kQtWHWImLmgzMMQQ5NGztqC27nEh3vt49kCwaBq9E7Ar3cC/qHmqHk7w1Me9uvB/bh/t pbSquivPYKbgZGS+fvPYodplaM1W0Iq6knGLMz/FN3QcrFSFb56Dd9ZZTv4JSyx3Ymca d2aA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h19si8034295pgb.231.2018.12.09.14.13.35; Sun, 09 Dec 2018 14:13:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728299AbeLIWMF (ORCPT + 99 others); Sun, 9 Dec 2018 17:12:05 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:37764 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727647AbeLIWME (ORCPT ); Sun, 9 Dec 2018 17:12:04 -0500 Received: from pub.yeoldevic.com ([81.174.156.145] helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gW73R-0002ie-2W; Sun, 09 Dec 2018 21:56:01 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gW72Z-0003FJ-Du; Sun, 09 Dec 2018 21:55:07 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Greg Kroah-Hartman" , "Johan Hovold" Date: Sun, 09 Dec 2018 21:50:33 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 040/328] tty: fix termios input-speed encoding when using BOTHER In-Reply-To: X-SA-Exim-Connect-IP: 81.174.156.145 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.62-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Johan Hovold commit 1cee38f0363a88db374e50b232ca17b9a4c12fa0 upstream. 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 [bwh: Backported to 3.16: adjust filename] Signed-off-by: Ben Hutchings --- drivers/tty/tty_ioctl.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/drivers/tty/tty_ioctl.c +++ b/drivers/tty/tty_ioctl.c @@ -407,16 +407,20 @@ void tty_termios_encode_baud_rate(struct termios->c_ospeed = obaud; #ifdef BOTHER + if ((termios->c_cflag >> IBSHIFT) & CBAUD) + ibinput = 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 */ - if ((termios->c_cflag & CBAUD) == BOTHER) + if ((termios->c_cflag & CBAUD) == BOTHER) { oclose = 0; + if (!ibinput) + iclose = 0; + } if (((termios->c_cflag >> IBSHIFT) & CBAUD) == BOTHER) iclose = 0; - if ((termios->c_cflag >> IBSHIFT) & CBAUD) - ibinput = 1; /* An input speed was specified */ #endif termios->c_cflag &= ~CBAUD; #ifdef IBSHIFT