Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8412614imu; Tue, 4 Dec 2018 08:02:20 -0800 (PST) X-Google-Smtp-Source: AFSGD/UMu4mZeC3Pp7eaCvOPwZctvsQuBrTRziWCEF5pY+ScKVG5qiVGvXS1zDviJ60cGFj7E7PV X-Received: by 2002:a63:101d:: with SMTP id f29mr17373807pgl.38.1543939340433; Tue, 04 Dec 2018 08:02:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543939340; cv=none; d=google.com; s=arc-20160816; b=VB66V9qHbXd49YZmk2S0UfJw48VmDvSbgbfndpI7pxH1PVOJLezT2gSmreClffuIpv ZhaKjOiSK9QMvirqiXh+LjY7oQc5ixaY04cuGCtR4izaA7vLtfc0xd1hyrx/SrQi+CEM wYtl0zQ1UKbcKjQJOmRpnymJzPrZqQOh0iB4Pgr4br/uc0wZgkBc9NgdSlcwC6SRf8Wh QNs2F5YJyNXnpA9RH6zrzR42pBkaKk1RWcso7On0cKN1fDGLMQSI3MD6zLf1hplCyGcG gg2PaZGb2feP50ZtZtCq6NCIB0GuRG/zJqqRJekqnKDGSy0RVqJkw5G1riFpMdwPW/Pb hw/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4AfIsjpkJHb43W/ZaV+KazQjDgZpHguTHKABJHXmS4k=; b=uyKjGmvUwh2bBJCpZ+VyzB4KoHqCe3yDxzqpDNnRuxuguRAk8myGl+i24DEyQqImA6 tSqTfnPhAiPWxGau3Mq8U/yhCYOkY6nZVlqOOT/13PjQeRwayKn54XS183+EUo5hoZgC Fro1R8YwCbiLIdYciuByCbNMs6FWYR+Kdrx8ImbQvH/o4VKjhFVm8xPQONPPFfQGE3Ax nUTerTeJRUutNdCbztTERF4b9foJsGSBLzzdHiYNy7RM5EINGQxroD3AMvckiDkTKlqD nEhGuy7zSmP75haDYuKlpGDee107gY42998hgvI0u8HzxfdTvCadctYrdWuiVuQtmFPL LA1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=tYpoiwit; 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 a6si15990877pfa.227.2018.12.04.08.01.53; Tue, 04 Dec 2018 08:02:20 -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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=tYpoiwit; 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 S1726674AbeLDQBO (ORCPT + 99 others); Tue, 4 Dec 2018 11:01:14 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:42130 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726367AbeLDQBO (ORCPT ); Tue, 4 Dec 2018 11:01:14 -0500 Received: by mail-lf1-f68.google.com with SMTP id l10so12321627lfh.9; Tue, 04 Dec 2018 08:01:11 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=4AfIsjpkJHb43W/ZaV+KazQjDgZpHguTHKABJHXmS4k=; b=tYpoiwitTOKccZVDzZLWbWjAwiHqWx0SlN2hEzsHRgx6BXi08Pfiz0Kp1ahO7+ZVyR jeLLVJdM5qK3gQjiMihY6b5VOIa403OyPhi05UkouSjqdK8qFxmB+pYW58JQNnQPVoXd rANO5r8ELK4Yn22RHuje0u5WZViqJLMUJqxX0EVYJXL6RXpKQgZpofigTUbceRHjaNfI +q5kox9N//RkyxnJ+lo3Ez+4iTi5EWjdhtcISnJ6GLy7p2mFAcOgdNcr5fPBQZ28rOBG 8ljuyjSpSGFH7E+SY93prvKs2W5K9Gt9aLPl2v8SODQ3RrjyI3Z6+oVHkkLTxTSvMUIF 9pDw== 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:mime-version:content-transfer-encoding; bh=4AfIsjpkJHb43W/ZaV+KazQjDgZpHguTHKABJHXmS4k=; b=VCff88zPNo8+vjT/3Phi4GOV50WaPHL3qN1k/sOgehn4bHJPaa63ei0YGd19zu+aDY cwiFH0uVzPqnLgP4P/SUx+gbzBQXZJCUkuTfrPXOs9k9/PKHRJwMe5T4Sw6YCn28pd4V gNG5NbdGI0fXVppR2tnHzdWAN9LRkWAPk5doIEccXSfb0ieFSmC9vGHiuiUhI2+sqmAi JiN6lmBUDZ869RnuE9OWLtKJLT23DVVMFssYYZoZmCH3T85l7LLk4T/0D9bE64+s9Yyr ixWEcR7uThL+lzDYpVeeB0PidzJqttzepvizb+3H72gadNh6DzRGpYZaAc9QmqRL3I2O 9FbA== X-Gm-Message-State: AA+aEWa94PftarmXDa/6gxd3RKPZ/sxiRRsEmfnsu+OIs0M2Fl6SGNdo WRgDz/m9671Vb5xwEjJm8eJQWEMW X-Received: by 2002:a19:1901:: with SMTP id 1mr10661394lfz.99.1543939270148; Tue, 04 Dec 2018 08:01:10 -0800 (PST) Received: from xi.terra (c-74bee655.07-184-6d6c6d4.bbcust.telenor.se. [85.230.190.116]) by smtp.gmail.com with ESMTPSA id o17sm2994042lff.77.2018.12.04.08.01.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Dec 2018 08:01:09 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.91) (envelope-from ) id 1gUD8I-0006Pw-QE; Tue, 04 Dec 2018 17:01:10 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Jarkko Nikula , Greg Kroah-Hartman , Jiri Slaby , linux-kernel@vger.kernel.org, Johan Hovold , stable , Florian Zumbiehl Subject: [PATCH] USB: serial: console: fix reported terminal settings Date: Tue, 4 Dec 2018 17:00:36 +0100 Message-Id: <20181204160036.24625-1-johan@kernel.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181204155904.GC18087@localhost> References: <20181204155904.GC18087@localhost> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The USB-serial console implementation has never reported the actual terminal settings used. Despite storing the corresponding cflags in its struct console, this was never honoured on later tty open() where the tty termios would be left initialised to the driver defaults. Unlike the serial console implementation, the USB-serial code calls subdriver open() already at console setup. While calling set_termios() before open() looks like it could work for some USB-serial drivers, others definitely do not expect this, so modelling this after serial core is going to be intrusive, if at all possible. Instead, use a (renamed) tty helper to save the termios data used at console setup, so that the tty termios reflects the actual terminal settings after a subsequent tty open(). Note that the calls to tty_init_termios() (tty_driver_install()) and tty_save_termios() are serialised using the disconnect mutex. This specifically fixes a regression that was triggered by a recent change adding software flow control to the pl2303 driver: a getty trying to disable flow control while leaving the baud rate unchanged would now also set the baud rate to the driver default (prior to the flow-control change this had been a noop). Fixes: 7041d9c3f01b ("USB: serial: pl2303: add support for tx xon/xoff flow control") Cc: stable # 4.18 Reported-by: Jarkko Nikula Cc: Florian Zumbiehl Signed-off-by: Johan Hovold --- drivers/tty/tty_io.c | 11 +++++++++-- drivers/usb/serial/console.c | 2 +- include/linux/tty.h | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index ee80dfbd5442..687250ec8032 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -1373,7 +1373,13 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx) return ERR_PTR(retval); } -static void tty_free_termios(struct tty_struct *tty) +/** + * tty_save_termios() - save tty termios data in driver table + * @tty: tty whose termios data to save + * + * Locking: Caller guarantees serialisation with tty_init_termios(). + */ +void tty_save_termios(struct tty_struct *tty) { struct ktermios *tp; int idx = tty->index; @@ -1392,6 +1398,7 @@ static void tty_free_termios(struct tty_struct *tty) } *tp = tty->termios; } +EXPORT_SYMBOL_GPL(tty_save_termios); /** * tty_flush_works - flush all works of a tty/pty pair @@ -1491,7 +1498,7 @@ static void release_tty(struct tty_struct *tty, int idx) WARN_ON(!mutex_is_locked(&tty_mutex)); if (tty->ops->shutdown) tty->ops->shutdown(tty); - tty_free_termios(tty); + tty_save_termios(tty); tty_driver_remove_tty(tty->driver, tty); tty->port->itty = NULL; if (tty->link) diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c index 17940589c647..7d289302ff6c 100644 --- a/drivers/usb/serial/console.c +++ b/drivers/usb/serial/console.c @@ -101,7 +101,6 @@ static int usb_console_setup(struct console *co, char *options) cflag |= PARENB; break; } - co->cflag = cflag; /* * no need to check the index here: if the index is wrong, console @@ -164,6 +163,7 @@ static int usb_console_setup(struct console *co, char *options) serial->type->set_termios(tty, port, &dummy); tty_port_tty_set(&port->port, NULL); + tty_save_termios(tty); tty_kref_put(tty); } tty_port_set_initialized(&port->port, 1); diff --git a/include/linux/tty.h b/include/linux/tty.h index 414db2bce715..392138fe59b6 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h @@ -556,6 +556,7 @@ extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx); extern void tty_release_struct(struct tty_struct *tty, int idx); extern int tty_release(struct inode *inode, struct file *filp); extern void tty_init_termios(struct tty_struct *tty); +extern void tty_save_termios(struct tty_struct *tty); extern int tty_standard_install(struct tty_driver *driver, struct tty_struct *tty); -- 2.19.2