From: Johan Hovold <johan@kernel.org>
To: linux-usb@vger.kernel.org
Cc: Johan Hovold <johan@kernel.org>
Subject: [PATCH 03/10] USB: serial: ftdi_sio: fix break and sysrq handling
Date: Wed, 8 Jul 2020 14:49:53 +0200 [thread overview]
Message-ID: <20200708125000.15659-4-johan@kernel.org> (raw)
In-Reply-To: <20200708125000.15659-1-johan@kernel.org>
Only the last NUL in a packet should be flagged as a break character,
for example, to avoid dropping unrelated characters when IGNBRK is set.
Also make sysrq work by consuming the break character instead of having
it immediately cancel the sysrq request, and by not processing it
prematurely to avoid triggering a sysrq based on an unrelated character
received in the same packet (which was received *before* the break).
Note that the break flag can be left set also for a packet received
immediately following a break and that and an ending NUL in such a
packet will continue to be reported as a break as there's no good way to
tell it apart from an actual break.
Tested on FT232R and FT232H.
Fixes: 72fda3ca6fc1 ("USB: serial: ftd_sio: implement sysrq handling on break")
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/usb/serial/ftdi_sio.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 33f1cca7eaa6..07b146d7033a 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -2483,6 +2483,7 @@ static int ftdi_process_packet(struct usb_serial_port *port,
struct ftdi_private *priv, unsigned char *buf, int len)
{
unsigned char status;
+ bool brkint = false;
int i;
char flag;
@@ -2534,13 +2535,17 @@ static int ftdi_process_packet(struct usb_serial_port *port,
*/
flag = TTY_NORMAL;
if (buf[1] & FTDI_RS_ERR_MASK) {
- /* Break takes precedence over parity, which takes precedence
- * over framing errors */
- if (buf[1] & FTDI_RS_BI) {
- flag = TTY_BREAK;
+ /*
+ * Break takes precedence over parity, which takes precedence
+ * over framing errors. Note that break is only associated
+ * with the last character in the buffer and only when it's a
+ * NUL.
+ */
+ if (buf[1] & FTDI_RS_BI && buf[len - 1] == '\0') {
port->icount.brk++;
- usb_serial_handle_break(port);
- } else if (buf[1] & FTDI_RS_PE) {
+ brkint = true;
+ }
+ if (buf[1] & FTDI_RS_PE) {
flag = TTY_PARITY;
port->icount.parity++;
} else if (buf[1] & FTDI_RS_FE) {
@@ -2556,8 +2561,13 @@ static int ftdi_process_packet(struct usb_serial_port *port,
port->icount.rx += len - 2;
- if (port->port.console && port->sysrq) {
+ if (brkint || (port->port.console && port->sysrq)) {
for (i = 2; i < len; i++) {
+ if (brkint && i == len - 1) {
+ if (usb_serial_handle_break(port))
+ return len - 3;
+ flag = TTY_BREAK;
+ }
if (usb_serial_handle_sysrq_char(port, buf[i]))
continue;
tty_insert_flip_char(&port->port, buf[i], flag);
--
2.26.2
next prev parent reply other threads:[~2020-07-08 12:50 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-08 12:49 [PATCH 00/10] USB: serial: break and sysrq fixes and cleanups Johan Hovold
2020-07-08 12:49 ` [PATCH 01/10] USB: serial: ftdi_sio: make process-packet buffer unsigned Johan Hovold
2020-07-08 12:49 ` [PATCH 02/10] USB: serial: ftdi_sio: clean up receive processing Johan Hovold
2020-07-08 12:49 ` Johan Hovold [this message]
2020-07-08 12:49 ` [PATCH 04/10] USB: serial: only set sysrq timestamp for consoles Johan Hovold
2020-07-08 12:49 ` [PATCH 05/10] USB: serial: only process sysrq when enabled Johan Hovold
2020-07-08 12:49 ` [PATCH 06/10] USB: serial: inline sysrq dummy function Johan Hovold
2020-07-08 12:49 ` [PATCH 07/10] USB: serial: add sysrq break-handler dummy Johan Hovold
2020-07-08 12:49 ` [PATCH 08/10] USB: serial: drop unnecessary sysrq include Johan Hovold
2020-07-08 12:49 ` [PATCH 09/10] USB: serial: drop extern keyword from function declarations Johan Hovold
2020-07-08 12:50 ` [PATCH 10/10] USB: serial: drop redundant transfer-buffer casts Johan Hovold
2020-07-08 15:45 ` [PATCH 00/10] USB: serial: break and sysrq fixes and cleanups Greg KH
2020-07-09 7:23 ` Johan Hovold
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=20200708125000.15659-4-johan@kernel.org \
--to=johan@kernel.org \
--cc=linux-usb@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;
as well as URLs for NNTP newsgroup(s).