linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 2/9] serial: digicolor-usart: Don't allow CS5-6
       [not found] <20220519081808.3776-1-ilpo.jarvinen@linux.intel.com>
@ 2022-05-19  8:18 ` Ilpo Järvinen
  2022-05-19  8:18 ` [PATCH v2 3/9] serial: rda-uart: " Ilpo Järvinen
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Ilpo Järvinen @ 2022-05-19  8:18 UTC (permalink / raw)
  To: linux-serial, Greg KH, Jiri Slaby, Shubhrajyoti Datta,
	Baruch Siach, linux-arm-kernel, linux-kernel
  Cc: Ilpo Järvinen

Only 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().

Fixes: 5930cb3511df (serial: driver for Conexant Digicolor USART)
Acked-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/tty/serial/digicolor-usart.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/tty/serial/digicolor-usart.c b/drivers/tty/serial/digicolor-usart.c
index 6d70fea76bb3..65e653eb5026 100644
--- a/drivers/tty/serial/digicolor-usart.c
+++ b/drivers/tty/serial/digicolor-usart.c
@@ -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;
 	}
 
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 3/9] serial: rda-uart: Don't allow CS5-6
       [not found] <20220519081808.3776-1-ilpo.jarvinen@linux.intel.com>
  2022-05-19  8:18 ` [PATCH v2 2/9] serial: digicolor-usart: Don't allow CS5-6 Ilpo Järvinen
@ 2022-05-19  8:18 ` Ilpo Järvinen
  2022-05-19  8:18 ` [PATCH v2 7/9] serial: st-asc: Sanitize CSIZE and correct PARENB for CS7 Ilpo Järvinen
  2022-05-19  8:18 ` [PATCH v2 8/9] serial: stm32-usart: Correct CSIZE, bits, and parity Ilpo Järvinen
  3 siblings, 0 replies; 5+ messages in thread
From: Ilpo Järvinen @ 2022-05-19  8:18 UTC (permalink / raw)
  To: linux-serial, Greg KH, Jiri Slaby, Shubhrajyoti Datta,
	Manivannan Sadhasivam, Andreas Färber, Olof Johansson,
	Arnd Bergmann, linux-arm-kernel, linux-unisoc, linux-kernel
  Cc: Ilpo Järvinen

Only 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().

Cc: Manivannan Sadhasivam <mani@kernel.org>
Fixes: c10b13325ced (tty: serial: Add RDA8810PL UART driver)
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/tty/serial/rda-uart.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/tty/serial/rda-uart.c b/drivers/tty/serial/rda-uart.c
index e5f1fded423a..f556b4955f59 100644
--- a/drivers/tty/serial/rda-uart.c
+++ b/drivers/tty/serial/rda-uart.c
@@ -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;
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 7/9] serial: st-asc: Sanitize CSIZE and correct PARENB for CS7
       [not found] <20220519081808.3776-1-ilpo.jarvinen@linux.intel.com>
  2022-05-19  8:18 ` [PATCH v2 2/9] serial: digicolor-usart: Don't allow CS5-6 Ilpo Järvinen
  2022-05-19  8:18 ` [PATCH v2 3/9] serial: rda-uart: " Ilpo Järvinen
@ 2022-05-19  8:18 ` Ilpo Järvinen
  2022-05-20  6:19   ` Patrice CHOTARD
  2022-05-19  8:18 ` [PATCH v2 8/9] serial: stm32-usart: Correct CSIZE, bits, and parity Ilpo Järvinen
  3 siblings, 1 reply; 5+ messages in thread
From: Ilpo Järvinen @ 2022-05-19  8:18 UTC (permalink / raw)
  To: linux-serial, Greg KH, Jiri Slaby, Shubhrajyoti Datta,
	Patrice Chotard, Srinivas Kandagatla, linux-arm-kernel,
	linux-kernel
  Cc: 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_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().

Cc: Srinivas Kandagatla <srinivas.kandagatla@st.com>
Fixes: c4b058560762 (serial:st-asc: Add ST ASC driver.)
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/tty/serial/st-asc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/tty/serial/st-asc.c b/drivers/tty/serial/st-asc.c
index d7fd692286cf..1b0da603ab54 100644
--- a/drivers/tty/serial/st-asc.c
+++ b/drivers/tty/serial/st-asc.c
@@ -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;
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 8/9] serial: stm32-usart: Correct CSIZE, bits, and parity
       [not found] <20220519081808.3776-1-ilpo.jarvinen@linux.intel.com>
                   ` (2 preceding siblings ...)
  2022-05-19  8:18 ` [PATCH v2 7/9] serial: st-asc: Sanitize CSIZE and correct PARENB for CS7 Ilpo Järvinen
@ 2022-05-19  8:18 ` Ilpo Järvinen
  3 siblings, 0 replies; 5+ messages in thread
From: Ilpo Järvinen @ 2022-05-19  8:18 UTC (permalink / raw)
  To: linux-serial, Greg KH, Jiri Slaby, Shubhrajyoti Datta,
	Maxime Coquelin, Alexandre Torgue, Erwan Le Ray, linux-stm32,
	linux-arm-kernel, linux-kernel
  Cc: Ilpo Järvinen

Add 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().

Cc: Erwan Le Ray <erwan.leray@st.com>
Fixes: c8a9d043947b (serial: stm32: fix word length configuration)
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/tty/serial/stm32-usart.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
index 87b5cd4c9743..3c551fd4f3ff 100644
--- a/drivers/tty/serial/stm32-usart.c
+++ b/drivers/tty/serial/stm32-usart.c
@@ -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 &&
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 7/9] serial: st-asc: Sanitize CSIZE and correct PARENB for CS7
  2022-05-19  8:18 ` [PATCH v2 7/9] serial: st-asc: Sanitize CSIZE and correct PARENB for CS7 Ilpo Järvinen
@ 2022-05-20  6:19   ` Patrice CHOTARD
  0 siblings, 0 replies; 5+ messages in thread
From: Patrice CHOTARD @ 2022-05-20  6:19 UTC (permalink / raw)
  To: Ilpo Järvinen, linux-serial, Greg KH, Jiri Slaby,
	Shubhrajyoti Datta, Srinivas Kandagatla, linux-arm-kernel,
	linux-kernel

Hi Ilpo

On 5/19/22 10:18, Ilpo Järvinen wrote:
> Only 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().
> 
> Cc: Srinivas Kandagatla <srinivas.kandagatla@st.com>
> Fixes: c4b058560762 (serial:st-asc: Add ST ASC driver.)
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> ---
>  drivers/tty/serial/st-asc.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/tty/serial/st-asc.c b/drivers/tty/serial/st-asc.c
> index d7fd692286cf..1b0da603ab54 100644
> --- a/drivers/tty/serial/st-asc.c
> +++ b/drivers/tty/serial/st-asc.c
> @@ -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;

Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>

Thanks
Patrice

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2022-05-20  6:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20220519081808.3776-1-ilpo.jarvinen@linux.intel.com>
2022-05-19  8:18 ` [PATCH v2 2/9] serial: digicolor-usart: Don't allow CS5-6 Ilpo Järvinen
2022-05-19  8:18 ` [PATCH v2 3/9] serial: rda-uart: " Ilpo Järvinen
2022-05-19  8:18 ` [PATCH v2 7/9] serial: st-asc: Sanitize CSIZE and correct PARENB for CS7 Ilpo Järvinen
2022-05-20  6:19   ` Patrice CHOTARD
2022-05-19  8:18 ` [PATCH v2 8/9] serial: stm32-usart: Correct CSIZE, bits, and parity Ilpo Järvinen

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).