Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1392328imm; Sun, 15 Jul 2018 06:43:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdnIi/XoO2Mmh7pxxWNAtO+Gh+BqdMZDlCECSOhG3a2PCGW6RZQ7gCxTVVw4qrcSo2YQQnn X-Received: by 2002:a17:902:8506:: with SMTP id bj6-v6mr13104690plb.210.1531662187630; Sun, 15 Jul 2018 06:43:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531662187; cv=none; d=google.com; s=arc-20160816; b=KWULXrduY66DcucyNF6r99o+1QE76azH2kWDNtvizr3tF9J7lLh2m+RH4btVHKibBH JsjRGMoJbaRnMyyc6chdm+K7uiJAbfB4CbqyumNtCraJtlr1leQQSdBUvE2kQmkDTJr6 a9whjhSBVOiR1zTlM3bstiWOqLSrwpnNg8Aab9HNqi7T+67u29WCfDNg4u5ryzahBIQq RLl9gVYdZRvkFiy7R/kYQlg8Wo7cScFCz1IBlZajem+lxacq99DK0j1ZeohOirCnoJYY X6AqHt7juXaaH5gamrXa/xSz5Zoyn0LDjVdcOcN6zzt2kZ5SnyzvpEQWNRp1nKUzK1lz Vx4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=8BQ0IHaATCYoeTqwviFqp/+r2Wdc9WKKUjlXlfEVTJM=; b=AlDW1VLOW3jZP2xqvBdM2xsjCwFwzO5NyOLU7HVfDhzyP3ruVykb+tsq9vJIweQwtl nKGz4XZo/BmEM0RAx0D8YTYQbNiZhn0ymJ6vn+AhdoJLqburC8K+SkUzFuJHIyiLMYp/ SYkxeacURBA4TltHZ7/KjI/m6dYuaFfmVFIOpGfIFpW8qnEeJI/rzoqjBcN6zfYRZT9h FVaW9qwRkDF/5DeC/+bZAvoWTjv4zvMzyoa404Ir93YZ9PMv0EcT+nneMlD9R7OTmx9t D0JQxHFROzIh4XNuM9yanlWY1aETrBuG9DNc/CSF8Kbv3wFL/Zmdn+Zn8u4jL/TC1BDa IoUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=X4ON2ZlO; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d37-v6si28031145plb.481.2018.07.15.06.42.39; Sun, 15 Jul 2018 06:43:07 -0700 (PDT) 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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=X4ON2ZlO; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726662AbeGOOEm (ORCPT + 99 others); Sun, 15 Jul 2018 10:04:42 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:41138 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726235AbeGOOEm (ORCPT ); Sun, 15 Jul 2018 10:04:42 -0400 Received: by mail-lj1-f196.google.com with SMTP id y17-v6so22995477ljy.8 for ; Sun, 15 Jul 2018 06:41:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=8BQ0IHaATCYoeTqwviFqp/+r2Wdc9WKKUjlXlfEVTJM=; b=X4ON2ZlOBXVIZ7yepqQX/70owlb6Ksgcju2K9lJ3ZQ6L5WytzrJWLBti3kqNGZ6lYK hEoStBzcM9DudHd5K4BPApR5s75Zauoe74HlWpanF58pwapjVfhKlYB7CYsDs7e3KI1w KWfgpPeiOUaSHrErnPOMwvO5lNIqQoh4AwkZIoJQ6AX8zHozBdbHjUKsy/MbQZGacpvl 4bt+XIBrQ7uJmNxorcc+ztaN1Kq2MbwR1a104IH42APHhVw0xu6osz/D1Ms98YCf6ZK7 U1RIhlg9qt0kRh+UN2kAgcCxRywMyKc6TQ4vyslWfTB5jZOrC+H2DTvodfIh0agd0k1v rYbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=8BQ0IHaATCYoeTqwviFqp/+r2Wdc9WKKUjlXlfEVTJM=; b=GCtnzPEU13BP5hdBb9is/A75GqIO2+adIz1ti8avkq7VwcAb4loUxhHz5uI+02sRk9 QlWvQpX5Vo5wxR2izbrSCu034Zn74fsQXPHQeJq0QefskOJkqmGuJbBvjAOfx3nyb65A UGYeUOZQZRHx8I13L6vvl15tmq0MuxARrOoe9btvNHuaelTFwgetbvl1KKekJoVSZfL5 VqDZVsShEdKBysWIUuD3S72ufeJlelUz6unY7Vya5K6Hd6TXblASZEPG7j93igL3JZI1 NAZ4eWySVJeB83d8ZIB4uRu2HXyqfl/ug/fdusofBR6HnP1UJ7vI3EVhDA8eJBoykEtl 2niA== X-Gm-Message-State: AOUpUlHAZ+nTp0zIBTP8R5IkAxyao5imb71Daa2DaB4ogaNLYdLUVyzg 2qWMAmiotfsaiL6TCXKvTQ4= X-Received: by 2002:a2e:291c:: with SMTP id u28-v6mr7739669lje.70.1531662100519; Sun, 15 Jul 2018 06:41:40 -0700 (PDT) Received: from xi.terra (c-8bb2e655.07-184-6d6c6d4.bbcust.telenor.se. [85.230.178.139]) by smtp.gmail.com with ESMTPSA id n17-v6sm4436982ljb.82.2018.07.15.06.41.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Jul 2018 06:41:39 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.91) (envelope-from ) id 1fehHJ-0006WP-1t; Sun, 15 Jul 2018 15:41:33 +0200 From: Johan Hovold To: Greg Kroah-Hartman Cc: Jiri Slaby , Alan Cox , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 2/3] tty: fix termios input-speed encoding when using BOTHER Date: Sun, 15 Jul 2018 15:39:34 +0200 Message-Id: <20180715133935.24964-3-johan@kernel.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180715133935.24964-1-johan@kernel.org> References: <20180715133935.24964-1-johan@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 a7a438f54e69..3e827a3d48d5 100644 --- a/drivers/tty/tty_baudrate.c +++ b/drivers/tty/tty_baudrate.c @@ -157,16 +157,20 @@ void tty_termios_encode_baud_rate(struct ktermios *termios, 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 -- 2.18.0