Skip to contentSkip to conversation

serial: 8250: Fix restoring termios speed after suspend

PATCH In review Pali Rohár 2 participants 2 messages Sep 24, 2022 – Sep 26, 2022 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 serial: 8250: Fix restoring termios speed after suspend

Since commit edc6afc54968 ("tty: switch to ktermios and new framework") termios speed is no longer stored only in c_cflag member but also in new additional c_ispeed and c_ospeed members. If BOTHER flag is set in c_cflag then termios speed is stored only in these new members.

Since commit 027b57170bf8 ("serial: core: Fix initializing and restoring termios speed") termios speed is available also in struct console.

So properly restore also c_ispeed and c_ospeed members after suspend to fix restoring termios speed which is not represented by Bnnn constant.

Fixes 4516d50aabed ("serial: 8250: Use canary to restart console after suspend")
---
 drivers/tty/serial/8250/8250_port.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/tty/serial/8250/8250_port.c +6 -1
index 39b35a61958c..441f317c55af 100644
@@ -3314,8 +3314,13 @@ static void serial8250_console_restore(struct uart_8250_port *up)
 	unsigned int baud, quot, frac = 0;
 
 	termios.c_cflag = port->cons->cflag;
-	if (port->state->port.tty && termios.c_cflag == 0)
+	termios.c_ispeed = port->cons->ispeed;
+	termios.c_ospeed = port->cons->ospeed;
+	if (port->state->port.tty && termios.c_cflag == 0) {
 		termios.c_cflag = port->state->port.tty->termios.c_cflag;
+		termios.c_ispeed = port->state->port.tty->termios.c_ispeed;
+		termios.c_ospeed = port->state->port.tty->termios.c_ospeed;
+	}
 
 	baud = serial8250_get_baud_rate(port, &termios, NULL);
 	quot = serial8250_get_divisor(port, baud, &frac);
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 22 lines · Pali Rohár

Since commit edc6afc54968 ("tty: switch to ktermios and new framework") termios speed is no longer stored only in c_cflag member but also in new additional c_ispeed and c_ospeed members. If BOTHER flag is set in c_cflag then termios speed is stored only in these new members.

Since commit 027b57170bf8 ("serial: core: Fix initializing and restoring termios speed") termios speed is available also in struct console.

So properly restore also c_ispeed and c_ospeed members after suspend to fix restoring termios speed which is not represented by Bnnn constant.

Fixes 4516d50aabed ("serial: 8250: Use canary to restart console after suspend")
---
  drivers/tty/serial/8250/8250_port.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
drivers/tty/serial/8250/8250_port.c +0 -0
index 39b35a61958c..441f317c55af 100644

drivers/tty/serial/8250/8250_port.c static void serial8250_console_restore(struct uart_8250_port *up) · line 3319

Quoted 7 lines
drivers/tty/serial/8250/8250_port.c +3 -1
@@ -3314,8 +3314,13 @@ static void serial8250_console_restore(struct uart_8250_port *up)
  	unsigned int baud, quot, frac = 0;
 
  	termios.c_cflag = port->cons->cflag;
-	if (port->state->port.tty && termios.c_cflag == 0)
+	termios.c_ispeed = port->cons->ispeed;
+	termios.c_ospeed = port->cons->ospeed;
+	if (port->state->port.tty && termios.c_cflag == 0) {

I don't currently know how safe it is to assume port->state->port.tty cannot change between the test above and the dereferences below.

In anyway, you should cache it as it is used 4 times now. It would make the code definitely more readable.

Quoted 7 lines
drivers/tty/serial/8250/8250_port.c +3 -0
  		termios.c_cflag = port->state->port.tty->termios.c_cflag;
+		termios.c_ispeed = port->state->port.tty->termios.c_ispeed;
+		termios.c_ospeed = port->state->port.tty->termios.c_ospeed;
+	}
 
  	baud = serial8250_get_baud_rate(port, &termios, NULL);
  	quot = serial8250_get_divisor(port, baud, &frac);
Signature · 2 lines
js
suse labs