All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/9] tty/serial: Termios flag fixes
@ 2022-05-19  8:17 Ilpo Järvinen
  2022-05-19  8:18 ` [PATCH v2 1/9] serial: uartlite: Fix BRKINT clearing Ilpo Järvinen
                   ` (8 more replies)
  0 siblings, 9 replies; 17+ messages in thread
From: Ilpo Järvinen @ 2022-05-19  8:17 UTC (permalink / raw)
  To: linux-serial, Greg KH, Jiri Slaby, Shubhrajyoti Datta; +Cc: Ilpo Järvinen

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

-- 
2.30.2


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

* [PATCH v2 1/9] serial: uartlite: Fix BRKINT clearing
  2022-05-19  8:17 [PATCH v2 0/9] tty/serial: Termios flag fixes Ilpo Järvinen
@ 2022-05-19  8:18 ` Ilpo Järvinen
  2022-05-19  8:18   ` Ilpo Järvinen
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 17+ messages in thread
From: Ilpo Järvinen @ 2022-05-19  8:18 UTC (permalink / raw)
  To: linux-serial, Greg KH, Jiri Slaby, Shubhrajyoti Datta,
	Peter Korsgaard, Sean Anderson, linux-kernel
  Cc: Ilpo Järvinen

BRKINT is within c_iflag rather than c_cflag.

Fixes: ea017f5853e9 (tty: serial: uartlite: Prevent changing fixed parameters)
Reviewed-by: Sean Anderson <sean.anderson@seco.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/tty/serial/uartlite.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/uartlite.c b/drivers/tty/serial/uartlite.c
index 007db67292a2..880e2afbb97b 100644
--- a/drivers/tty/serial/uartlite.c
+++ b/drivers/tty/serial/uartlite.c
@@ -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);
 
-- 
2.30.2


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

* [PATCH v2 2/9] serial: digicolor-usart: Don't allow CS5-6
  2022-05-19  8:17 [PATCH v2 0/9] tty/serial: Termios flag fixes Ilpo Järvinen
@ 2022-05-19  8:18   ` Ilpo Järvinen
  2022-05-19  8:18   ` Ilpo Järvinen
                     ` (7 subsequent siblings)
  8 siblings, 0 replies; 17+ 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


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

* [PATCH v2 2/9] serial: digicolor-usart: Don't allow CS5-6
@ 2022-05-19  8:18   ` Ilpo Järvinen
  0 siblings, 0 replies; 17+ 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] 17+ messages in thread

* [PATCH v2 3/9] serial: rda-uart: Don't allow CS5-6
  2022-05-19  8:17 [PATCH v2 0/9] tty/serial: Termios flag fixes Ilpo Järvinen
@ 2022-05-19  8:18   ` Ilpo Järvinen
  2022-05-19  8:18   ` Ilpo Järvinen
                     ` (7 subsequent siblings)
  8 siblings, 0 replies; 17+ 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


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

* [PATCH v2 3/9] serial: rda-uart: Don't allow CS5-6
@ 2022-05-19  8:18   ` Ilpo Järvinen
  0 siblings, 0 replies; 17+ 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] 17+ messages in thread

* [PATCH v2 4/9] serial: txx9: Don't allow CS5-6
  2022-05-19  8:17 [PATCH v2 0/9] tty/serial: Termios flag fixes Ilpo Järvinen
                   ` (2 preceding siblings ...)
  2022-05-19  8:18   ` Ilpo Järvinen
@ 2022-05-19  8:18 ` Ilpo Järvinen
  2022-05-19  8:18 ` [PATCH v2 5/9] serial: sh-sci: " Ilpo Järvinen
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 17+ messages in thread
From: Ilpo Järvinen @ 2022-05-19  8:18 UTC (permalink / raw)
  To: linux-serial, Greg KH, Jiri Slaby, Shubhrajyoti Datta, linux-kernel
  Cc: Ilpo Järvinen

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

Fixes: 1da177e4c3f4 (Linux-2.6.12-rc2)
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/tty/serial/serial_txx9.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/tty/serial/serial_txx9.c b/drivers/tty/serial/serial_txx9.c
index 2213e6b841d3..228e380db080 100644
--- a/drivers/tty/serial/serial_txx9.c
+++ b/drivers/tty/serial/serial_txx9.c
@@ -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;
 	}
 
-- 
2.30.2


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

* [PATCH v2 5/9] serial: sh-sci: Don't allow CS5-6
  2022-05-19  8:17 [PATCH v2 0/9] tty/serial: Termios flag fixes Ilpo Järvinen
                   ` (3 preceding siblings ...)
  2022-05-19  8:18 ` [PATCH v2 4/9] serial: txx9: " Ilpo Järvinen
@ 2022-05-19  8:18 ` Ilpo Järvinen
  2022-05-19  8:18   ` Ilpo Järvinen
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 17+ messages in thread
From: Ilpo Järvinen @ 2022-05-19  8:18 UTC (permalink / raw)
  To: linux-serial, Greg KH, Jiri Slaby, Shubhrajyoti Datta, linux-kernel
  Cc: Ilpo Järvinen

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

Fixes: 1da177e4c3f4 (Linux-2.6.12-rc2)
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/tty/serial/sh-sci.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 0f9b8bd23500..0075a1420005 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -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)
-- 
2.30.2


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

* [PATCH v2 6/9] serial: sifive: Sanitize CSIZE and c_iflag
  2022-05-19  8:17 [PATCH v2 0/9] tty/serial: Termios flag fixes Ilpo Järvinen
@ 2022-05-19  8:18   ` Ilpo Järvinen
  2022-05-19  8:18   ` Ilpo Järvinen
                     ` (7 subsequent siblings)
  8 siblings, 0 replies; 17+ messages in thread
From: Ilpo Järvinen @ 2022-05-19  8:18 UTC (permalink / raw)
  To: linux-serial, Greg KH, Jiri Slaby, Shubhrajyoti Datta,
	Palmer Dabbelt, Paul Walmsley, linux-riscv, linux-kernel
  Cc: Ilpo Järvinen

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

Cc: Paul Walmsley <paul.walmsley@sifive.com>
Fixes: 45c054d0815b (tty: serial: add driver for the SiFive UART)
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/tty/serial/sifive.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/sifive.c b/drivers/tty/serial/sifive.c
index f5ac14c384c4..c1c0fb9c1822 100644
--- a/drivers/tty/serial/sifive.c
+++ b/drivers/tty/serial/sifive.c
@@ -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;
-- 
2.30.2


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

* [PATCH v2 6/9] serial: sifive: Sanitize CSIZE and c_iflag
@ 2022-05-19  8:18   ` Ilpo Järvinen
  0 siblings, 0 replies; 17+ messages in thread
From: Ilpo Järvinen @ 2022-05-19  8:18 UTC (permalink / raw)
  To: linux-serial, Greg KH, Jiri Slaby, Shubhrajyoti Datta,
	Palmer Dabbelt, Paul Walmsley, linux-riscv, linux-kernel
  Cc: Ilpo Järvinen

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

Cc: Paul Walmsley <paul.walmsley@sifive.com>
Fixes: 45c054d0815b (tty: serial: add driver for the SiFive UART)
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/tty/serial/sifive.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/sifive.c b/drivers/tty/serial/sifive.c
index f5ac14c384c4..c1c0fb9c1822 100644
--- a/drivers/tty/serial/sifive.c
+++ b/drivers/tty/serial/sifive.c
@@ -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;
-- 
2.30.2


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

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

* [PATCH v2 7/9] serial: st-asc: Sanitize CSIZE and correct PARENB for CS7
  2022-05-19  8:17 [PATCH v2 0/9] tty/serial: Termios flag fixes Ilpo Järvinen
@ 2022-05-19  8:18   ` Ilpo Järvinen
  2022-05-19  8:18   ` Ilpo Järvinen
                     ` (7 subsequent siblings)
  8 siblings, 0 replies; 17+ 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


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

* [PATCH v2 7/9] serial: st-asc: Sanitize CSIZE and correct PARENB for CS7
@ 2022-05-19  8:18   ` Ilpo Järvinen
  0 siblings, 0 replies; 17+ 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] 17+ messages in thread

* [PATCH v2 8/9] serial: stm32-usart: Correct CSIZE, bits, and parity
  2022-05-19  8:17 [PATCH v2 0/9] tty/serial: Termios flag fixes Ilpo Järvinen
@ 2022-05-19  8:18   ` Ilpo Järvinen
  2022-05-19  8:18   ` Ilpo Järvinen
                     ` (7 subsequent siblings)
  8 siblings, 0 replies; 17+ 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


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

* [PATCH v2 8/9] serial: stm32-usart: Correct CSIZE, bits, and parity
@ 2022-05-19  8:18   ` Ilpo Järvinen
  0 siblings, 0 replies; 17+ 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] 17+ messages in thread

* [PATCH v2 9/9] pcmcia: synclink_cs: Don't allow CS5-6
  2022-05-19  8:17 [PATCH v2 0/9] tty/serial: Termios flag fixes Ilpo Järvinen
                   ` (7 preceding siblings ...)
  2022-05-19  8:18   ` Ilpo Järvinen
@ 2022-05-19  8:18 ` Ilpo Järvinen
  8 siblings, 0 replies; 17+ messages in thread
From: Ilpo Järvinen @ 2022-05-19  8:18 UTC (permalink / raw)
  To: linux-serial, Greg KH, Jiri Slaby, Shubhrajyoti Datta,
	Arnd Bergmann, linux-kernel
  Cc: Ilpo Järvinen

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

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/char/pcmcia/synclink_cs.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index 78baba55a8b5..d0572bbe8832 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -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)
-- 
2.30.2


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

* Re: [PATCH v2 7/9] serial: st-asc: Sanitize CSIZE and correct PARENB for CS7
  2022-05-19  8:18   ` Ilpo Järvinen
@ 2022-05-20  6:19     ` Patrice CHOTARD
  -1 siblings, 0 replies; 17+ 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

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

* Re: [PATCH v2 7/9] serial: st-asc: Sanitize CSIZE and correct PARENB for CS7
@ 2022-05-20  6:19     ` Patrice CHOTARD
  0 siblings, 0 replies; 17+ 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] 17+ messages in thread

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

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-19  8:17 [PATCH v2 0/9] tty/serial: Termios flag fixes Ilpo Järvinen
2022-05-19  8:18 ` [PATCH v2 1/9] serial: uartlite: Fix BRKINT clearing Ilpo Järvinen
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 3/9] serial: rda-uart: " Ilpo Järvinen
2022-05-19  8:18   ` Ilpo Järvinen
2022-05-19  8:18 ` [PATCH v2 4/9] serial: txx9: " Ilpo Järvinen
2022-05-19  8:18 ` [PATCH v2 5/9] serial: sh-sci: " Ilpo Järvinen
2022-05-19  8:18 ` [PATCH v2 6/9] serial: sifive: Sanitize CSIZE and c_iflag 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   ` Ilpo Järvinen
2022-05-20  6:19   ` Patrice CHOTARD
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
2022-05-19  8:18   ` Ilpo Järvinen
2022-05-19  8:18 ` [PATCH v2 9/9] pcmcia: synclink_cs: Don't allow CS5-6 Ilpo Järvinen

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.