tty/serial: Termios flag fixes
Subsystems (9)
v2 cover tty/serial: Termios flag fixes
Here are a few termios flag fixes, mostly CSIZE but a few other flags as well. The fixed flags returned to userspace should now match to what the driver is using. Incorrect CSIZE also causes a miscalculation of timeout in serial core (but it might not be a huge problem being just a handwavy long timeout).
v2:
- Corrected shortlog typo
Ilpo Järvinen (9):
serial: uartlite: Fix BRKINT clearing
serial: digicolor-usart: Don't allow CS5-6
serial: rda-uart: Don't allow CS5-6
serial: txx9: Don't allow CS5-6
serial: sh-sci: Don't allow CS5-6
serial: sifive: Sanitize CSIZE and c_iflag
serial: st-asc: Sanitize CSIZE and correct PARENB for CS7
serial: stm32-usart: Correct CSIZE, bits, and parity
pcmcia: synclink_cs: Don't allow CS5-6
drivers/char/pcmcia/synclink_cs.c | 6 +++++- drivers/tty/serial/digicolor-usart.c | 2 ++ drivers/tty/serial/rda-uart.c | 2 ++ drivers/tty/serial/serial_txx9.c | 2 ++ drivers/tty/serial/sh-sci.c | 6 +++++- drivers/tty/serial/sifive.c | 6 +++++- drivers/tty/serial/st-asc.c | 4 ++++ drivers/tty/serial/stm32-usart.c | 15 ++++++++++++--- drivers/tty/serial/uartlite.c | 3 ++- 9 files changed, 39 insertions(+), 7 deletions(-)
Signature · 1 line
2.30.2
PATCH v2 1/9 serial: uartlite: Fix BRKINT clearing
BRKINT is within c_iflag rather than c_cflag.
--- drivers/tty/serial/uartlite.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/tty/serial/uartlite.c +2 -1
@@ -321,7 +321,8 @@ static void ulite_set_termios(struct uart_port *port, struct ktermios *termios,struct uartlite_data *pdata = port->private_data;/* Set termios to what the hardware supports */ - termios->c_cflag &= ~(BRKINT |CSTOPB |PARENB |PARODD |CSIZE ); + termios->c_iflag &= ~BRKINT ; + termios->c_cflag &= ~(CSTOPB |PARENB |PARODD |CSIZE ); termios->c_cflag |= pdata->cflags & (PARENB |PARODD |CSIZE );tty_termios_encode_baud_rate (termios, pdata->baud, pdata->baud);
Signature · 1 line
2.30.2
PATCH v2 2/9 serial: digicolor-usart: Don't allow CS5-6
In reply to Ilpo JärvinenOnly CS7 and CS8 seem supported but CSIZE is not sanitized to CS8 in the default: block.
Set CSIZE correctly so that userspace knows the effective value. Incorrect CSIZE also results in miscalculation of the frame bits in tty_get_char_size() or in its predecessor where the roughly the same code is directly within uart_update_timeout().
--- drivers/tty/serial/digicolor-usart.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/tty/serial/digicolor-usart.c +2 -0
@@ -309,6 +309,8 @@ static void digicolor_uart_set_termios(struct uart_port *port,case CS8 :default : config |=UA_CONFIG_CHAR_LEN ; + termios->c_cflag &= ~CSIZE ; + termios->c_cflag |=CS8 ;break ; }
Signature · 1 line
2.30.2
PATCH v2 3/9 serial: rda-uart: Don't allow CS5-6
In reply to Ilpo JärvinenOnly CS7 and CS8 are supported but CSIZE is not sanitized after fallthrough from CS5 or CS6 to CS7.
Set CSIZE correctly so that userspace knows the effective value. Incorrect CSIZE also results in miscalculation of the frame bits in tty_get_char_size() or in its predecessor where the roughly the same code is directly within uart_update_timeout().
--- drivers/tty/serial/rda-uart.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/tty/serial/rda-uart.c +2 -0
@@ -262,6 +262,8 @@ static void rda_uart_set_termios(struct uart_port *port, fallthrough;case CS7 : ctrl &= ~RDA_UART_DBITS_8 ; + termios->c_cflag &= ~CSIZE ; + termios->c_cflag |=CS7 ;break ;default : ctrl |=RDA_UART_DBITS_8 ;
Signature · 1 line
2.30.2
PATCH v2 4/9 serial: txx9: Don't allow CS5-6
In reply to Ilpo JärvinenOnly CS7 and CS8 are supported but CSIZE is not sanitized with CS5 or CS6 to CS8.
Set CSIZE correctly so that userspace knows the effective value. Incorrect CSIZE also results in miscalculation of the frame bits in tty_get_char_size() or in its predecessor where the roughly the same code is directly within uart_update_timeout().
--- drivers/tty/serial/serial_txx9.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/tty/serial/serial_txx9.c +2 -0
@@ -618,6 +618,8 @@ serial_txx9_set_termios(struct uart_port *up, struct ktermios *termios,case CS6 :/* not supported */ case CS8 : cval |=TXX9_SILCR_UMODE_8BIT ; + termios->c_cflag &= ~CSIZE ; + termios->c_cflag |=CS8 ;break ; }
Signature · 1 line
2.30.2
PATCH v2 5/9 serial: sh-sci: Don't allow CS5-6
In reply to Ilpo JärvinenOnly CS7 and CS8 seem supported but CSIZE is not sanitized from CS5 or CS6 to CS8.
Set CSIZE correctly so that userspace knows the effective value. Incorrect CSIZE also results in miscalculation of the frame bits in tty_get_char_size() or in its predecessor where the roughly the same code is directly within uart_update_timeout().
--- drivers/tty/serial/sh-sci.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/tty/serial/sh-sci.c +5 -1
@@ -2379,8 +2379,12 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,int best_clk =-1 ;unsigned long flags; -if ((termios->c_cflag &CSIZE ) ==CS7 ) +if ((termios->c_cflag &CSIZE ) ==CS7 ) { smr_val |=SCSMR_CHR ; + }else { + termios->c_cflag &= ~CSIZE ; + termios->c_cflag |=CS8 ; + }if (termios->c_cflag &PARENB ) smr_val |=SCSMR_PE ;if (termios->c_cflag &PARODD )
Signature · 1 line
2.30.2
PATCH v2 6/9 serial: sifive: Sanitize CSIZE and c_iflag
In reply to Ilpo JärvinenOnly CS8 is supported but CSIZE was not sanitized to CS8.
Set CSIZE correctly so that userspace knows the effective value. Incorrect CSIZE also results in miscalculation of the frame bits in tty_get_char_size() or in its predecessor where the roughly the same code is directly within uart_update_timeout().
Similarly, INPCK, PARMRK, and BRKINT are reported textually unsupported but were not cleared in termios c_iflag which is the machine-readable format.
--- drivers/tty/serial/sifive.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/tty/serial/sifive.c +5 -1
@@ -666,12 +666,16 @@ static void sifive_serial_set_termios(struct uart_port *port,int rate;char nstop; -if ((termios->c_cflag &CSIZE ) !=CS8 ) +if ((termios->c_cflag &CSIZE ) !=CS8 ) {dev_err_once (ssp->port.dev,"only 8-bit words supported\n" ); + termios->c_cflag &= ~CSIZE ; + termios->c_cflag |=CS8 ; + }if (termios->c_iflag & (INPCK |PARMRK ))dev_err_once (ssp->port.dev,"parity checking not supported\n" );if (termios->c_iflag &BRKINT )dev_err_once (ssp->port.dev,"BREAK detection not supported\n" ); + termios->c_iflag &= ~(INPCK |PARMRK |BRKINT );/* Set number of stop bits */ nstop = (termios->c_cflag &CSTOPB ) ?2 :1 ;
Signature · 1 line
2.30.2
PATCH v2 7/9 serial: st-asc: Sanitize CSIZE and correct PARENB for CS7
In reply to Ilpo JärvinenOnly CS7 and CS8 seem supported but CSIZE is not sanitized from CS5 or CS6 to CS8. In addition, ASC_CTL_MODE_7BIT_PAR suggests that CS7 has to have parity, thus add PARENB.
Incorrect CSIZE results in miscalculation of the frame bits in tty_get_char_size() or in its predecessor where the roughly the same code is directly within uart_update_timeout().
--- drivers/tty/serial/st-asc.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/tty/serial/st-asc.c +4 -0
@@ -535,10 +535,14 @@ static void asc_set_termios(struct uart_port *port, struct ktermios *termios,/* set character length */ if ((cflag &CSIZE ) ==CS7 ) { ctrl_val |=ASC_CTL_MODE_7BIT_PAR ; + cflag |=PARENB ; }else { ctrl_val |= (cflag &PARENB ) ?ASC_CTL_MODE_8BIT_PAR :ASC_CTL_MODE_8BIT ; + cflag &= ~CSIZE ; + cflag |=CS8 ; } + termios->c_cflag = cflag;/* set stop bit */ ctrl_val |= (cflag &CSTOPB ) ?ASC_CTL_STOP_2BIT :ASC_CTL_STOP_1BIT ;
Signature · 1 line
2.30.2
Re: [PATCH v2 7/9] serial: st-asc: Sanitize CSIZE and correct PARENB for CS7
Hi Ilpo
Quoted 24 lines · Ilpo Järvinen
Only CS7 and CS8 seem supported but CSIZE is not sanitized from CS5 or CS6 to CS8. In addition,
ASC_CTL_MODE_7BIT_PARsuggests that CS7 has to have parity, thus add PARENB.Incorrect CSIZE results in miscalculation of the frame bits in
tty_get_char_size()or in its predecessor where the roughly the same code is directly withinuart_update_timeout().Cc Srinivas Kandagatla <[email protected]>Fixes c4b058560762 (serial:st-asc: Add ST ASC driver.)Signed-off-by Ilpo Järvinen <[email protected]>--- drivers/tty/serial/st-asc.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/tty/serial/st-asc.c +1
-0@@ -535,10 +535,14 @@ static void asc_set_termios(struct uart_port *port, struct ktermios *termios,/* set character length */ if ((cflag &CSIZE ) ==CS7 ) { ctrl_val |=ASC_CTL_MODE_7BIT_PAR ; + cflag |=PARENB ;
drivers/tty/serial/st-asc.c static void asc_set_termios(struct uart_port *port, struct ktermios *termios, · line 548
Quoted 10 lines
drivers/tty/serial/st-asc.c +3
-0}else { ctrl_val |= (cflag &PARENB ) ?ASC_CTL_MODE_8BIT_PAR :ASC_CTL_MODE_8BIT ; + cflag &= ~CSIZE ; + cflag |=CS8 ; } + termios->c_cflag = cflag;/* set stop bit */ ctrl_val |= (cflag &CSTOPB ) ?ASC_CTL_STOP_2BIT :ASC_CTL_STOP_1BIT ;
Thanks
Patrice
PATCH v2 8/9 serial: stm32-usart: Correct CSIZE, bits, and parity
In reply to Ilpo JärvinenAdd CSIZE sanitization for unsupported CSIZE configurations. In addition, if parity is asked for but CSx was unsupported, the sensible result is CS8+parity which requires setting USART_CR1_M0 like with 9 bits.
Incorrect CSIZE results in miscalculation of the frame bits in tty_get_char_size() or in its predecessor where the roughly the same code is directly within uart_update_timeout().
--- drivers/tty/serial/stm32-usart.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/tty/serial/stm32-usart.c +12 -3
@@ -1037,13 +1037,22 @@ static void stm32_usart_set_termios(struct uart_port *port,* CS8 or (CS7 + parity), 8 bits word aka [M1:M0] = 0b00 * M0 and M1 already cleared by cr1 initialization. */ -if (bits ==9 ) +if (bits ==9 ) { cr1 |=USART_CR1_M0 ; -else if ((bits ==7 ) && cfg->has_7bits_data) + }else if ((bits ==7 ) && cfg->has_7bits_data) { cr1 |=USART_CR1_M1 ; -else if (bits !=8 ) + }else if (bits !=8 ) {dev_dbg (port->dev,"Unsupported data bits config: %u bits\n" , bits); + cflag &= ~CSIZE ; + cflag |=CS8 ; + termios->c_cflag = cflag; + bits =8 ; +if (cflag &PARENB ) { + bits++; + cr1 |=USART_CR1_M0 ; + } + } if (ofs->rtor != UNDEF_REG && (stm32_port->rx_ch || (stm32_port->fifoen &&
Signature · 1 line
2.30.2
PATCH v2 9/9 pcmcia: synclink_cs: Don't allow CS5-6
In reply to Ilpo JärvinenOnly CS7 and CS8 seem supported but CSIZE was not sanitized in termios c_cflag. The driver sets 7 bits whenever data_bits is not 8 so default to CS7 when CSIZE is not CS8.
--- drivers/char/pcmcia/synclink_cs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/char/pcmcia/synclink_cs.c +5 -1
@@ -1418,7 +1418,11 @@ static void mgslpc_change_params(MGSLPC_INFO *info, struct tty_struct *tty) info->serial_signals &= ~(SerialSignal_RTS | SerialSignal_DTR);/* byte size and parity */ - +if ((cflag &CSIZE ) !=CS8 ) { + cflag &= ~CSIZE ; + cflag |=CS7 ; + tty->termios.c_cflag = cflag; + } info->params.data_bits =tty_get_char_size (cflag);if (cflag &CSTOPB )
Signature · 1 line
2.30.2