From: Johan Hovold <johan@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jslaby@suse.com>
Cc: linux-kernel@vger.kernel.org, "Johan Hovold" <johan@kernel.org>,
"Jan Kundrát" <jan.kundrat@cesnet.cz>
Subject: [PATCH 3/3] tty: reset termios state on device registration
Date: Thu, 30 Mar 2017 15:39:36 +0200 [thread overview]
Message-ID: <20170330133936.17907-4-johan@kernel.org> (raw)
In-Reply-To: <20170330133936.17907-1-johan@kernel.org>
Free any saved termios data when registering a tty device so that the
termios state is reset when reusing a minor number.
This is useful for hot-pluggable buses such as USB where it does not
make much sense to reuse saved termios data from an unrelated device
when a new device is later plugged in.
This specifically avoids a situation where the new device does not have
the carrier-detect signal wired, but the saved termios state has CLOCAL
cleared, effectively preventing the port from being opened in blocking
mode as noted by Jan Kundrát <jan.kundrat@cesnet.cz>.
Note that clearing the saved data at deregistration would not work as
the device could still be open.
Also note that the termios data is not reset for drivers with
TTY_DRIVER_DYNAMIC_ALLOC set (e.g. legacy pty) as their character device
is registered at driver registration and could theoretically already
have been opened (and pty termios state is never saved anyway).
Reported-by: Jan Kundrát <jan.kundrat@cesnet.cz>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/tty/tty_io.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 5f834dcb0b15..d697053f5e42 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -3293,6 +3293,7 @@ struct device *tty_register_device_attr(struct tty_driver *driver,
{
char name[64];
dev_t devt = MKDEV(driver->major, driver->minor_start) + index;
+ struct ktermios *tp;
struct device *dev;
int retval;
@@ -3326,6 +3327,16 @@ struct device *tty_register_device_attr(struct tty_driver *driver,
goto err_put;
if (!(driver->flags & TTY_DRIVER_DYNAMIC_ALLOC)) {
+ /*
+ * Free any saved termios data so that the termios state is
+ * reset when reusing a minor number.
+ */
+ tp = driver->termios[index];
+ if (tp) {
+ driver->termios[index] = NULL;
+ kfree(tp);
+ }
+
retval = tty_cdev_add(driver, devt, index, 1);
if (retval)
goto err_del;
--
2.12.2
next prev parent reply other threads:[~2017-03-30 13:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-30 13:39 [PATCH 0/3] tty: close registration race and add termios reset feature Johan Hovold
2017-03-30 13:39 ` [PATCH 1/3] tty: close race between device register and open Johan Hovold
2017-03-30 13:39 ` [PATCH 2/3] tty: drop obsolete termios_locked comments Johan Hovold
2017-03-30 13:39 ` Johan Hovold [this message]
2017-03-31 12:58 ` [PATCH 0/3] tty: close registration race and add termios reset feature Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170330133936.17907-4-johan@kernel.org \
--to=johan@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=jan.kundrat@cesnet.cz \
--cc=jslaby@suse.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox