All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/10] USB: serial: break and sysrq fixes and cleanups
@ 2020-07-08 12:49 Johan Hovold
  2020-07-08 12:49 ` [PATCH 01/10] USB: serial: ftdi_sio: make process-packet buffer unsigned Johan Hovold
                   ` (10 more replies)
  0 siblings, 11 replies; 13+ messages in thread
From: Johan Hovold @ 2020-07-08 12:49 UTC (permalink / raw)
  To: linux-usb; +Cc: Johan Hovold

This series fixes the break and sysrq handling in the ftdi driver (which
have never really worked) and optimises the sysrq handling somewhat.

Included are also some related clean ups.

Johan


Johan Hovold (10):
  USB: serial: ftdi_sio: make process-packet buffer unsigned
  USB: serial: ftdi_sio: clean up receive processing
  USB: serial: ftdi_sio: fix break and sysrq handling
  USB: serial: only set sysrq timestamp for consoles
  USB: serial: only process sysrq when enabled
  USB: serial: inline sysrq dummy function
  USB: serial: add sysrq break-handler dummy
  USB: serial: drop unnecessary sysrq include
  USB: serial: drop extern keyword from function declarations
  USB: serial: drop redundant transfer-buffer casts

 drivers/usb/serial/aircable.c |  2 +-
 drivers/usb/serial/f81232.c   |  4 +-
 drivers/usb/serial/f81534.c   |  2 +-
 drivers/usb/serial/ftdi_sio.c | 59 +++++++++++++---------
 drivers/usb/serial/generic.c  | 22 ++++----
 drivers/usb/serial/mxuport.c  |  6 +--
 drivers/usb/serial/option.c   |  3 +-
 drivers/usb/serial/pl2303.c   |  2 +-
 drivers/usb/serial/sierra.c   |  3 +-
 drivers/usb/serial/ssu100.c   |  7 +--
 include/linux/usb/serial.h    | 95 ++++++++++++++++++-----------------
 11 files changed, 107 insertions(+), 98 deletions(-)

-- 
2.26.2


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 01/10] USB: serial: ftdi_sio: make process-packet buffer unsigned
  2020-07-08 12:49 [PATCH 00/10] USB: serial: break and sysrq fixes and cleanups Johan Hovold
@ 2020-07-08 12:49 ` Johan Hovold
  2020-07-08 12:49 ` [PATCH 02/10] USB: serial: ftdi_sio: clean up receive processing Johan Hovold
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Johan Hovold @ 2020-07-08 12:49 UTC (permalink / raw)
  To: linux-usb; +Cc: Johan Hovold

Use an unsigned type for the process-packet buffer argument and give it
a more apt name.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/ftdi_sio.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 9ad44a96dfe3..96b9e2768ac5 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -2480,12 +2480,12 @@ static int ftdi_prepare_write_buffer(struct usb_serial_port *port,
 #define FTDI_RS_ERR_MASK (FTDI_RS_BI | FTDI_RS_PE | FTDI_RS_FE | FTDI_RS_OE)
 
 static int ftdi_process_packet(struct usb_serial_port *port,
-		struct ftdi_private *priv, char *packet, int len)
+		struct ftdi_private *priv, unsigned char *buf, int len)
 {
+	unsigned char status;
+	unsigned char *ch;
 	int i;
-	char status;
 	char flag;
-	char *ch;
 
 	if (len < 2) {
 		dev_dbg(&port->dev, "malformed packet\n");
@@ -2495,7 +2495,7 @@ static int ftdi_process_packet(struct usb_serial_port *port,
 	/* Compare new line status to the old one, signal if different/
 	   N.B. packet may be processed more than once, but differences
 	   are only processed once.  */
-	status = packet[0] & FTDI_STATUS_B0_MASK;
+	status = buf[0] & FTDI_STATUS_B0_MASK;
 	if (status != priv->prev_status) {
 		char diff_status = status ^ priv->prev_status;
 
@@ -2521,7 +2521,7 @@ static int ftdi_process_packet(struct usb_serial_port *port,
 	}
 
 	/* save if the transmitter is empty or not */
-	if (packet[1] & FTDI_RS_TEMT)
+	if (buf[1] & FTDI_RS_TEMT)
 		priv->transmit_empty = 1;
 	else
 		priv->transmit_empty = 0;
@@ -2535,29 +2535,29 @@ static int ftdi_process_packet(struct usb_serial_port *port,
 	 * data payload to avoid over-reporting.
 	 */
 	flag = TTY_NORMAL;
-	if (packet[1] & FTDI_RS_ERR_MASK) {
+	if (buf[1] & FTDI_RS_ERR_MASK) {
 		/* Break takes precedence over parity, which takes precedence
 		 * over framing errors */
-		if (packet[1] & FTDI_RS_BI) {
+		if (buf[1] & FTDI_RS_BI) {
 			flag = TTY_BREAK;
 			port->icount.brk++;
 			usb_serial_handle_break(port);
-		} else if (packet[1] & FTDI_RS_PE) {
+		} else if (buf[1] & FTDI_RS_PE) {
 			flag = TTY_PARITY;
 			port->icount.parity++;
-		} else if (packet[1] & FTDI_RS_FE) {
+		} else if (buf[1] & FTDI_RS_FE) {
 			flag = TTY_FRAME;
 			port->icount.frame++;
 		}
 		/* Overrun is special, not associated with a char */
-		if (packet[1] & FTDI_RS_OE) {
+		if (buf[1] & FTDI_RS_OE) {
 			port->icount.overrun++;
 			tty_insert_flip_char(&port->port, 0, TTY_OVERRUN);
 		}
 	}
 
 	port->icount.rx += len;
-	ch = packet + 2;
+	ch = buf + 2;
 
 	if (port->port.console && port->sysrq) {
 		for (i = 0; i < len; i++, ch++) {
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 02/10] USB: serial: ftdi_sio: clean up receive processing
  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 ` Johan Hovold
  2020-07-08 12:49 ` [PATCH 03/10] USB: serial: ftdi_sio: fix break and sysrq handling Johan Hovold
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Johan Hovold @ 2020-07-08 12:49 UTC (permalink / raw)
  To: linux-usb; +Cc: Johan Hovold

Clean up receive processing by dropping the character pointer and
keeping the length argument unchanged throughout the function.

Also make it more apparent that sysrq processing can consume a
characters by adding an explicit continue.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/ftdi_sio.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 96b9e2768ac5..33f1cca7eaa6 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -2483,7 +2483,6 @@ static int ftdi_process_packet(struct usb_serial_port *port,
 		struct ftdi_private *priv, unsigned char *buf, int len)
 {
 	unsigned char status;
-	unsigned char *ch;
 	int i;
 	char flag;
 
@@ -2526,8 +2525,7 @@ static int ftdi_process_packet(struct usb_serial_port *port,
 	else
 		priv->transmit_empty = 0;
 
-	len -= 2;
-	if (!len)
+	if (len == 2)
 		return 0;	/* status only */
 
 	/*
@@ -2556,19 +2554,20 @@ static int ftdi_process_packet(struct usb_serial_port *port,
 		}
 	}
 
-	port->icount.rx += len;
-	ch = buf + 2;
+	port->icount.rx += len - 2;
 
 	if (port->port.console && port->sysrq) {
-		for (i = 0; i < len; i++, ch++) {
-			if (!usb_serial_handle_sysrq_char(port, *ch))
-				tty_insert_flip_char(&port->port, *ch, flag);
+		for (i = 2; i < len; i++) {
+			if (usb_serial_handle_sysrq_char(port, buf[i]))
+				continue;
+			tty_insert_flip_char(&port->port, buf[i], flag);
 		}
 	} else {
-		tty_insert_flip_string_fixed_flag(&port->port, ch, flag, len);
+		tty_insert_flip_string_fixed_flag(&port->port, buf + 2, flag,
+				len - 2);
 	}
 
-	return len;
+	return len - 2;
 }
 
 static void ftdi_process_read_urb(struct urb *urb)
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 03/10] USB: serial: ftdi_sio: fix break and sysrq handling
  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
  2020-07-08 12:49 ` [PATCH 04/10] USB: serial: only set sysrq timestamp for consoles Johan Hovold
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Johan Hovold @ 2020-07-08 12:49 UTC (permalink / raw)
  To: linux-usb; +Cc: Johan Hovold

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


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 04/10] USB: serial: only set sysrq timestamp for consoles
  2020-07-08 12:49 [PATCH 00/10] USB: serial: break and sysrq fixes and cleanups Johan Hovold
                   ` (2 preceding siblings ...)
  2020-07-08 12:49 ` [PATCH 03/10] USB: serial: ftdi_sio: fix break and sysrq handling Johan Hovold
@ 2020-07-08 12:49 ` Johan Hovold
  2020-07-08 12:49 ` [PATCH 05/10] USB: serial: only process sysrq when enabled Johan Hovold
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Johan Hovold @ 2020-07-08 12:49 UTC (permalink / raw)
  To: linux-usb; +Cc: Johan Hovold

Only set the sysrq timestamp for console ports to avoid having every
driver also check the console flag when processing incoming data.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/f81232.c   |  4 ++--
 drivers/usb/serial/f81534.c   |  2 +-
 drivers/usb/serial/ftdi_sio.c |  2 +-
 drivers/usb/serial/generic.c  | 11 +++++++----
 drivers/usb/serial/mxuport.c  |  6 +++---
 drivers/usb/serial/pl2303.c   |  2 +-
 drivers/usb/serial/ssu100.c   |  5 +++--
 7 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c
index dcda7fb164b4..0c7eacc630e0 100644
--- a/drivers/usb/serial/f81232.c
+++ b/drivers/usb/serial/f81232.c
@@ -424,7 +424,7 @@ static void f81232_process_read_urb(struct urb *urb)
 		lsr = data[i];
 		tty_flag = f81232_handle_lsr(port, lsr);
 
-		if (port->port.console && port->sysrq) {
+		if (port->sysrq) {
 			if (usb_serial_handle_sysrq_char(port, data[i + 1]))
 				continue;
 		}
@@ -461,7 +461,7 @@ static void f81534a_process_read_urb(struct urb *urb)
 	lsr = data[len - 1];
 	tty_flag = f81232_handle_lsr(port, lsr);
 
-	if (port->port.console && port->sysrq) {
+	if (port->sysrq) {
 		for (i = 1; i < len - 1; ++i) {
 			if (!usb_serial_handle_sysrq_char(port, data[i])) {
 				tty_insert_flip_char(&port->port, data[i],
diff --git a/drivers/usb/serial/f81534.c b/drivers/usb/serial/f81534.c
index 2b39bda035c7..5661fd03e545 100644
--- a/drivers/usb/serial/f81534.c
+++ b/drivers/usb/serial/f81534.c
@@ -1238,7 +1238,7 @@ static void f81534_process_per_serial_block(struct usb_serial_port *port,
 			schedule_work(&port_priv->lsr_work);
 		}
 
-		if (port->port.console && port->sysrq) {
+		if (port->sysrq) {
 			if (usb_serial_handle_sysrq_char(port, data[i]))
 				continue;
 		}
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 07b146d7033a..ade68405b015 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -2561,7 +2561,7 @@ static int ftdi_process_packet(struct usb_serial_port *port,
 
 	port->icount.rx += len - 2;
 
-	if (brkint || (port->port.console && port->sysrq)) {
+	if (brkint || port->sysrq) {
 		for (i = 2; i < len; i++) {
 			if (brkint && i == len - 1) {
 				if (usb_serial_handle_break(port))
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 5cdf180cda23..05a2a3aa3963 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -355,13 +355,13 @@ void usb_serial_generic_process_read_urb(struct urb *urb)
 	 * stuff like 3G modems, so shortcircuit it in the 99.9999999% of
 	 * cases where the USB serial is not a console anyway.
 	 */
-	if (!port->port.console || !port->sysrq) {
-		tty_insert_flip_string(&port->port, ch, urb->actual_length);
-	} else {
+	if (port->sysrq) {
 		for (i = 0; i < urb->actual_length; i++, ch++) {
 			if (!usb_serial_handle_sysrq_char(port, *ch))
 				tty_insert_flip_char(&port->port, *ch, TTY_NORMAL);
 		}
+	} else {
+		tty_insert_flip_string(&port->port, ch, urb->actual_length);
 	}
 	tty_flip_buffer_push(&port->port);
 }
@@ -574,7 +574,7 @@ EXPORT_SYMBOL_GPL(usb_serial_generic_get_icount);
 #ifdef CONFIG_MAGIC_SYSRQ
 int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch)
 {
-	if (port->sysrq && port->port.console) {
+	if (port->sysrq) {
 		if (ch && time_before(jiffies, port->sysrq)) {
 			handle_sysrq(ch);
 			port->sysrq = 0;
@@ -594,6 +594,9 @@ EXPORT_SYMBOL_GPL(usb_serial_handle_sysrq_char);
 
 int usb_serial_handle_break(struct usb_serial_port *port)
 {
+	if (!port->port.console)
+		return 0;
+
 	if (!port->sysrq) {
 		port->sysrq = jiffies + HZ*5;
 		return 1;
diff --git a/drivers/usb/serial/mxuport.c b/drivers/usb/serial/mxuport.c
index 2513ee902779..5d38c2a0f590 100644
--- a/drivers/usb/serial/mxuport.c
+++ b/drivers/usb/serial/mxuport.c
@@ -327,14 +327,14 @@ static void mxuport_process_read_urb_data(struct usb_serial_port *port,
 {
 	int i;
 
-	if (!port->port.console || !port->sysrq) {
-		tty_insert_flip_string(&port->port, data, size);
-	} else {
+	if (port->sysrq) {
 		for (i = 0; i < size; i++, data++) {
 			if (!usb_serial_handle_sysrq_char(port, *data))
 				tty_insert_flip_char(&port->port, *data,
 						     TTY_NORMAL);
 		}
+	} else {
+		tty_insert_flip_string(&port->port, data, size);
 	}
 	tty_flip_buffer_push(&port->port);
 }
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index c5a2995dfa2e..048452d8a4a4 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -1101,7 +1101,7 @@ static void pl2303_process_read_urb(struct urb *urb)
 	if (line_status & UART_OVERRUN_ERROR)
 		tty_insert_flip_char(&port->port, 0, TTY_OVERRUN);
 
-	if (port->port.console && port->sysrq) {
+	if (port->sysrq) {
 		for (i = 0; i < urb->actual_length; ++i)
 			if (!usb_serial_handle_sysrq_char(port, data[i]))
 				tty_insert_flip_char(&port->port, data[i],
diff --git a/drivers/usb/serial/ssu100.c b/drivers/usb/serial/ssu100.c
index f6aea9f1be1a..01472b96bf38 100644
--- a/drivers/usb/serial/ssu100.c
+++ b/drivers/usb/serial/ssu100.c
@@ -517,13 +517,14 @@ static void ssu100_process_read_urb(struct urb *urb)
 	if (!len)
 		return;	/* status only */
 
-	if (port->port.console && port->sysrq) {
+	if (port->sysrq) {
 		for (i = 0; i < len; i++, ch++) {
 			if (!usb_serial_handle_sysrq_char(port, *ch))
 				tty_insert_flip_char(&port->port, *ch, flag);
 		}
-	} else
+	} else {
 		tty_insert_flip_string_fixed_flag(&port->port, ch, flag, len);
+	}
 
 	tty_flip_buffer_push(&port->port);
 }
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 05/10] USB: serial: only process sysrq when enabled
  2020-07-08 12:49 [PATCH 00/10] USB: serial: break and sysrq fixes and cleanups Johan Hovold
                   ` (3 preceding siblings ...)
  2020-07-08 12:49 ` [PATCH 04/10] USB: serial: only set sysrq timestamp for consoles Johan Hovold
@ 2020-07-08 12:49 ` Johan Hovold
  2020-07-08 12:49 ` [PATCH 06/10] USB: serial: inline sysrq dummy function Johan Hovold
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Johan Hovold @ 2020-07-08 12:49 UTC (permalink / raw)
  To: linux-usb; +Cc: Johan Hovold

Do not set the sysrq timestamp unless CONFIG_MAGIC_SYSRQ is enabled to
avoid unnecessary per-character processing for consoles.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/generic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 05a2a3aa3963..c5b35252c931 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -594,7 +594,7 @@ EXPORT_SYMBOL_GPL(usb_serial_handle_sysrq_char);
 
 int usb_serial_handle_break(struct usb_serial_port *port)
 {
-	if (!port->port.console)
+	if (!port->port.console || !IS_ENABLED(CONFIG_MAGIC_SYSRQ))
 		return 0;
 
 	if (!port->sysrq) {
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 06/10] USB: serial: inline sysrq dummy function
  2020-07-08 12:49 [PATCH 00/10] USB: serial: break and sysrq fixes and cleanups Johan Hovold
                   ` (4 preceding siblings ...)
  2020-07-08 12:49 ` [PATCH 05/10] USB: serial: only process sysrq when enabled Johan Hovold
@ 2020-07-08 12:49 ` Johan Hovold
  2020-07-08 12:49 ` [PATCH 07/10] USB: serial: add sysrq break-handler dummy Johan Hovold
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Johan Hovold @ 2020-07-08 12:49 UTC (permalink / raw)
  To: linux-usb; +Cc: Johan Hovold

Inline the dummy sysrq character handling when either console support or
magic-sysrq support isn't enabled to allow the compiler to eliminate
unused code.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/generic.c | 9 ++-------
 include/linux/usb/serial.h   | 9 +++++++++
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index c5b35252c931..a9b6d103aaf6 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -571,7 +571,7 @@ int usb_serial_generic_get_icount(struct tty_struct *tty,
 }
 EXPORT_SYMBOL_GPL(usb_serial_generic_get_icount);
 
-#ifdef CONFIG_MAGIC_SYSRQ
+#if defined(CONFIG_USB_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
 int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch)
 {
 	if (port->sysrq) {
@@ -584,13 +584,8 @@ int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch)
 	}
 	return 0;
 }
-#else
-int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch)
-{
-	return 0;
-}
-#endif
 EXPORT_SYMBOL_GPL(usb_serial_handle_sysrq_char);
+#endif
 
 int usb_serial_handle_break(struct usb_serial_port *port)
 {
diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h
index 14cac4a1ae8f..be73646706a9 100644
--- a/include/linux/usb/serial.h
+++ b/include/linux/usb/serial.h
@@ -365,8 +365,17 @@ extern int usb_serial_generic_submit_read_urbs(struct usb_serial_port *port,
 extern void usb_serial_generic_process_read_urb(struct urb *urb);
 extern int usb_serial_generic_prepare_write_buffer(struct usb_serial_port *port,
 						void *dest, size_t size);
+
+#if defined(CONFIG_USB_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
 extern int usb_serial_handle_sysrq_char(struct usb_serial_port *port,
 					unsigned int ch);
+#else
+static inline int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch)
+{
+	return 0;
+}
+#endif
+
 extern int usb_serial_handle_break(struct usb_serial_port *port);
 extern void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port,
 					 struct tty_struct *tty,
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 07/10] USB: serial: add sysrq break-handler dummy
  2020-07-08 12:49 [PATCH 00/10] USB: serial: break and sysrq fixes and cleanups Johan Hovold
                   ` (5 preceding siblings ...)
  2020-07-08 12:49 ` [PATCH 06/10] USB: serial: inline sysrq dummy function Johan Hovold
@ 2020-07-08 12:49 ` Johan Hovold
  2020-07-08 12:49 ` [PATCH 08/10] USB: serial: drop unnecessary sysrq include Johan Hovold
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Johan Hovold @ 2020-07-08 12:49 UTC (permalink / raw)
  To: linux-usb; +Cc: Johan Hovold

Add inline sysrq break-handler dummy to allow the compiler to eliminate
further code when either console or sysrq support isn't enabled and to
clearly mark the two sysrq functions as belonging together.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/generic.c | 4 ++--
 include/linux/usb/serial.h   | 6 +++++-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index a9b6d103aaf6..e60f74f11acc 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -585,11 +585,10 @@ int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch)
 	return 0;
 }
 EXPORT_SYMBOL_GPL(usb_serial_handle_sysrq_char);
-#endif
 
 int usb_serial_handle_break(struct usb_serial_port *port)
 {
-	if (!port->port.console || !IS_ENABLED(CONFIG_MAGIC_SYSRQ))
+	if (!port->port.console)
 		return 0;
 
 	if (!port->sysrq) {
@@ -600,6 +599,7 @@ int usb_serial_handle_break(struct usb_serial_port *port)
 	return 0;
 }
 EXPORT_SYMBOL_GPL(usb_serial_handle_break);
+#endif
 
 /**
  * usb_serial_handle_dcd_change - handle a change of carrier detect state
diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h
index be73646706a9..c4ed4404335e 100644
--- a/include/linux/usb/serial.h
+++ b/include/linux/usb/serial.h
@@ -369,14 +369,18 @@ extern int usb_serial_generic_prepare_write_buffer(struct usb_serial_port *port,
 #if defined(CONFIG_USB_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
 extern int usb_serial_handle_sysrq_char(struct usb_serial_port *port,
 					unsigned int ch);
+extern int usb_serial_handle_break(struct usb_serial_port *port);
 #else
 static inline int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch)
 {
 	return 0;
 }
+static inline int usb_serial_handle_break(struct usb_serial_port *port)
+{
+	return 0;
+}
 #endif
 
-extern int usb_serial_handle_break(struct usb_serial_port *port);
 extern void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port,
 					 struct tty_struct *tty,
 					 unsigned int status);
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 08/10] USB: serial: drop unnecessary sysrq include
  2020-07-08 12:49 [PATCH 00/10] USB: serial: break and sysrq fixes and cleanups Johan Hovold
                   ` (6 preceding siblings ...)
  2020-07-08 12:49 ` [PATCH 07/10] USB: serial: add sysrq break-handler dummy Johan Hovold
@ 2020-07-08 12:49 ` Johan Hovold
  2020-07-08 12:49 ` [PATCH 09/10] USB: serial: drop extern keyword from function declarations Johan Hovold
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Johan Hovold @ 2020-07-08 12:49 UTC (permalink / raw)
  To: linux-usb; +Cc: Johan Hovold

There's no need to include sysrq.h in the subsystem header.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 include/linux/usb/serial.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h
index c4ed4404335e..4becca7ae264 100644
--- a/include/linux/usb/serial.h
+++ b/include/linux/usb/serial.h
@@ -17,7 +17,6 @@
 #include <linux/kref.h>
 #include <linux/mutex.h>
 #include <linux/serial.h>
-#include <linux/sysrq.h>
 #include <linux/kfifo.h>
 
 /* The maximum number of ports one device can grab at once */
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 09/10] USB: serial: drop extern keyword from function declarations
  2020-07-08 12:49 [PATCH 00/10] USB: serial: break and sysrq fixes and cleanups Johan Hovold
                   ` (7 preceding siblings ...)
  2020-07-08 12:49 ` [PATCH 08/10] USB: serial: drop unnecessary sysrq include Johan Hovold
@ 2020-07-08 12:49 ` 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
  10 siblings, 0 replies; 13+ messages in thread
From: Johan Hovold @ 2020-07-08 12:49 UTC (permalink / raw)
  To: linux-usb; +Cc: Johan Hovold

Drop the redundant extern keyword from function declarations in the
subsystem header file to improve readability (and make it easier to spot
the global variables).

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 include/linux/usb/serial.h | 81 +++++++++++++++++---------------------
 1 file changed, 36 insertions(+), 45 deletions(-)

diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h
index 4becca7ae264..6d756d03f46f 100644
--- a/include/linux/usb/serial.h
+++ b/include/linux/usb/serial.h
@@ -315,19 +315,19 @@ struct usb_serial_driver {
 #define to_usb_serial_driver(d) \
 	container_of(d, struct usb_serial_driver, driver)
 
-extern int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[],
+int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[],
 		const char *name, const struct usb_device_id *id_table);
-extern void usb_serial_deregister_drivers(struct usb_serial_driver *const serial_drivers[]);
-extern void usb_serial_port_softint(struct usb_serial_port *port);
+void usb_serial_deregister_drivers(struct usb_serial_driver *const serial_drivers[]);
+void usb_serial_port_softint(struct usb_serial_port *port);
 
-extern int usb_serial_suspend(struct usb_interface *intf, pm_message_t message);
-extern int usb_serial_resume(struct usb_interface *intf);
+int usb_serial_suspend(struct usb_interface *intf, pm_message_t message);
+int usb_serial_resume(struct usb_interface *intf);
 
 /* USB Serial console functions */
 #ifdef CONFIG_USB_SERIAL_CONSOLE
-extern void usb_serial_console_init(int minor);
-extern void usb_serial_console_exit(void);
-extern void usb_serial_console_disconnect(struct usb_serial *serial);
+void usb_serial_console_init(int minor);
+void usb_serial_console_exit(void);
+void usb_serial_console_disconnect(struct usb_serial *serial);
 #else
 static inline void usb_serial_console_init(int minor) { }
 static inline void usb_serial_console_exit(void) { }
@@ -335,40 +335,32 @@ static inline void usb_serial_console_disconnect(struct usb_serial *serial) {}
 #endif
 
 /* Functions needed by other parts of the usbserial core */
-extern struct usb_serial_port *usb_serial_port_get_by_minor(unsigned int minor);
-extern void usb_serial_put(struct usb_serial *serial);
-extern int usb_serial_generic_open(struct tty_struct *tty,
-	struct usb_serial_port *port);
-extern int usb_serial_generic_write_start(struct usb_serial_port *port,
-							gfp_t mem_flags);
-extern int usb_serial_generic_write(struct tty_struct *tty,
-	struct usb_serial_port *port, const unsigned char *buf, int count);
-extern void usb_serial_generic_close(struct usb_serial_port *port);
-extern int usb_serial_generic_resume(struct usb_serial *serial);
-extern int usb_serial_generic_write_room(struct tty_struct *tty);
-extern int usb_serial_generic_chars_in_buffer(struct tty_struct *tty);
-extern void usb_serial_generic_wait_until_sent(struct tty_struct *tty,
-								long timeout);
-extern void usb_serial_generic_read_bulk_callback(struct urb *urb);
-extern void usb_serial_generic_write_bulk_callback(struct urb *urb);
-extern void usb_serial_generic_throttle(struct tty_struct *tty);
-extern void usb_serial_generic_unthrottle(struct tty_struct *tty);
-extern int usb_serial_generic_tiocmiwait(struct tty_struct *tty,
-							unsigned long arg);
-extern int usb_serial_generic_get_icount(struct tty_struct *tty,
-					struct serial_icounter_struct *icount);
-extern int usb_serial_generic_register(void);
-extern void usb_serial_generic_deregister(void);
-extern int usb_serial_generic_submit_read_urbs(struct usb_serial_port *port,
-						 gfp_t mem_flags);
-extern void usb_serial_generic_process_read_urb(struct urb *urb);
-extern int usb_serial_generic_prepare_write_buffer(struct usb_serial_port *port,
-						void *dest, size_t size);
+struct usb_serial_port *usb_serial_port_get_by_minor(unsigned int minor);
+void usb_serial_put(struct usb_serial *serial);
+int usb_serial_generic_open(struct tty_struct *tty, struct usb_serial_port *port);
+int usb_serial_generic_write_start(struct usb_serial_port *port, gfp_t mem_flags);
+int usb_serial_generic_write(struct tty_struct *tty, struct usb_serial_port *port,
+		const unsigned char *buf, int count);
+void usb_serial_generic_close(struct usb_serial_port *port);
+int usb_serial_generic_resume(struct usb_serial *serial);
+int usb_serial_generic_write_room(struct tty_struct *tty);
+int usb_serial_generic_chars_in_buffer(struct tty_struct *tty);
+void usb_serial_generic_wait_until_sent(struct tty_struct *tty, long timeout);
+void usb_serial_generic_read_bulk_callback(struct urb *urb);
+void usb_serial_generic_write_bulk_callback(struct urb *urb);
+void usb_serial_generic_throttle(struct tty_struct *tty);
+void usb_serial_generic_unthrottle(struct tty_struct *tty);
+int usb_serial_generic_tiocmiwait(struct tty_struct *tty, unsigned long arg);
+int usb_serial_generic_get_icount(struct tty_struct *tty, struct serial_icounter_struct *icount);
+int usb_serial_generic_register(void);
+void usb_serial_generic_deregister(void);
+int usb_serial_generic_submit_read_urbs(struct usb_serial_port *port, gfp_t mem_flags);
+void usb_serial_generic_process_read_urb(struct urb *urb);
+int usb_serial_generic_prepare_write_buffer(struct usb_serial_port *port, void *dest, size_t size);
 
 #if defined(CONFIG_USB_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
-extern int usb_serial_handle_sysrq_char(struct usb_serial_port *port,
-					unsigned int ch);
-extern int usb_serial_handle_break(struct usb_serial_port *port);
+int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch);
+int usb_serial_handle_break(struct usb_serial_port *port);
 #else
 static inline int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch)
 {
@@ -380,13 +372,12 @@ static inline int usb_serial_handle_break(struct usb_serial_port *port)
 }
 #endif
 
-extern void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port,
-					 struct tty_struct *tty,
-					 unsigned int status);
+void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port,
+		struct tty_struct *tty, unsigned int status);
 
 
-extern int usb_serial_bus_register(struct usb_serial_driver *device);
-extern void usb_serial_bus_deregister(struct usb_serial_driver *device);
+int usb_serial_bus_register(struct usb_serial_driver *device);
+void usb_serial_bus_deregister(struct usb_serial_driver *device);
 
 extern struct bus_type usb_serial_bus_type;
 extern struct tty_driver *usb_serial_tty_driver;
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 10/10] USB: serial: drop redundant transfer-buffer casts
  2020-07-08 12:49 [PATCH 00/10] USB: serial: break and sysrq fixes and cleanups Johan Hovold
                   ` (8 preceding siblings ...)
  2020-07-08 12:49 ` [PATCH 09/10] USB: serial: drop extern keyword from function declarations Johan Hovold
@ 2020-07-08 12:50 ` Johan Hovold
  2020-07-08 15:45 ` [PATCH 00/10] USB: serial: break and sysrq fixes and cleanups Greg KH
  10 siblings, 0 replies; 13+ messages in thread
From: Johan Hovold @ 2020-07-08 12:50 UTC (permalink / raw)
  To: linux-usb; +Cc: Johan Hovold

Drop redundant URB transfer-buffer casts.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/aircable.c | 2 +-
 drivers/usb/serial/ftdi_sio.c | 2 +-
 drivers/usb/serial/generic.c  | 2 +-
 drivers/usb/serial/option.c   | 3 +--
 drivers/usb/serial/sierra.c   | 3 +--
 drivers/usb/serial/ssu100.c   | 2 +-
 6 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/serial/aircable.c b/drivers/usb/serial/aircable.c
index 84d52953dd0a..a1df686c3066 100644
--- a/drivers/usb/serial/aircable.c
+++ b/drivers/usb/serial/aircable.c
@@ -117,7 +117,7 @@ static int aircable_process_packet(struct usb_serial_port *port,
 static void aircable_process_read_urb(struct urb *urb)
 {
 	struct usb_serial_port *port = urb->context;
-	char *data = (char *)urb->transfer_buffer;
+	char *data = urb->transfer_buffer;
 	int has_headers;
 	int count;
 	int len;
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index ade68405b015..871cdccf3a5f 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -2584,7 +2584,7 @@ static void ftdi_process_read_urb(struct urb *urb)
 {
 	struct usb_serial_port *port = urb->context;
 	struct ftdi_private *priv = usb_get_serial_port_data(port);
-	char *data = (char *)urb->transfer_buffer;
+	char *data = urb->transfer_buffer;
 	int i;
 	int len;
 	int count = 0;
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index e60f74f11acc..d10aa3d2ee49 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -345,7 +345,7 @@ EXPORT_SYMBOL_GPL(usb_serial_generic_submit_read_urbs);
 void usb_serial_generic_process_read_urb(struct urb *urb)
 {
 	struct usb_serial_port *port = urb->context;
-	char *ch = (char *)urb->transfer_buffer;
+	char *ch = urb->transfer_buffer;
 	int i;
 
 	if (!urb->actual_length)
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 254a8bbeea67..8e74903352e7 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -2151,8 +2151,7 @@ static void option_instat_callback(struct urb *urb)
 	dev_dbg(dev, "%s: urb %p port %p has data %p\n", __func__, urb, port, portdata);
 
 	if (status == 0) {
-		struct usb_ctrlrequest *req_pkt =
-				(struct usb_ctrlrequest *)urb->transfer_buffer;
+		struct usb_ctrlrequest *req_pkt = urb->transfer_buffer;
 
 		if (!req_pkt) {
 			dev_dbg(dev, "%s: NULL req_pkt\n", __func__);
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c
index e8b130157b57..a862aa788a19 100644
--- a/drivers/usb/serial/sierra.c
+++ b/drivers/usb/serial/sierra.c
@@ -570,8 +570,7 @@ static void sierra_instat_callback(struct urb *urb)
 		urb, port, portdata);
 
 	if (status == 0) {
-		struct usb_ctrlrequest *req_pkt =
-				(struct usb_ctrlrequest *)urb->transfer_buffer;
+		struct usb_ctrlrequest *req_pkt = urb->transfer_buffer;
 
 		if (!req_pkt) {
 			dev_dbg(&port->dev, "%s: NULL req_pkt\n",
diff --git a/drivers/usb/serial/ssu100.c b/drivers/usb/serial/ssu100.c
index 01472b96bf38..7d39d35e52a1 100644
--- a/drivers/usb/serial/ssu100.c
+++ b/drivers/usb/serial/ssu100.c
@@ -495,7 +495,7 @@ static void ssu100_update_lsr(struct usb_serial_port *port, u8 lsr,
 static void ssu100_process_read_urb(struct urb *urb)
 {
 	struct usb_serial_port *port = urb->context;
-	char *packet = (char *)urb->transfer_buffer;
+	char *packet = urb->transfer_buffer;
 	char flag = TTY_NORMAL;
 	u32 len = urb->actual_length;
 	int i;
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 00/10] USB: serial: break and sysrq fixes and cleanups
  2020-07-08 12:49 [PATCH 00/10] USB: serial: break and sysrq fixes and cleanups Johan Hovold
                   ` (9 preceding siblings ...)
  2020-07-08 12:50 ` [PATCH 10/10] USB: serial: drop redundant transfer-buffer casts Johan Hovold
@ 2020-07-08 15:45 ` Greg KH
  2020-07-09  7:23   ` Johan Hovold
  10 siblings, 1 reply; 13+ messages in thread
From: Greg KH @ 2020-07-08 15:45 UTC (permalink / raw)
  To: Johan Hovold; +Cc: linux-usb

On Wed, Jul 08, 2020 at 02:49:50PM +0200, Johan Hovold wrote:
> This series fixes the break and sysrq handling in the ftdi driver (which
> have never really worked) and optimises the sysrq handling somewhat.
> 
> Included are also some related clean ups.

Nice!

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 00/10] USB: serial: break and sysrq fixes and cleanups
  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
  0 siblings, 0 replies; 13+ messages in thread
From: Johan Hovold @ 2020-07-09  7:23 UTC (permalink / raw)
  To: Greg KH; +Cc: Johan Hovold, linux-usb

On Wed, Jul 08, 2020 at 05:45:35PM +0200, Greg Kroah-Hartman wrote:
> On Wed, Jul 08, 2020 at 02:49:50PM +0200, Johan Hovold wrote:
> > This series fixes the break and sysrq handling in the ftdi driver (which
> > have never really worked) and optimises the sysrq handling somewhat.
> > 
> > Included are also some related clean ups.
> 
> Nice!
> 
> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Thanks for reviewing. Now applied.

Johan

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-07-09  7:23 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 03/10] USB: serial: ftdi_sio: fix break and sysrq handling Johan Hovold
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.