2022-05-19 14:57:40

by Ilpo Järvinen

[permalink] [raw]
Subject: [PATCH v2 7/9] serial: st-asc: Sanitize CSIZE and correct PARENB for CS7

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 <[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(+)

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



2022-05-23 06:50:27

by Patrice CHOTARD

[permalink] [raw]
Subject: Re: [PATCH v2 7/9] serial: st-asc: Sanitize CSIZE and correct PARENB for CS7

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 <[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(+)
>
> 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 <[email protected]>

Thanks
Patrice