linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] serial: st-asc: Couple of fixes
@ 2014-07-24 12:02 Maxime COQUELIN
  2014-07-24 12:02 ` [PATCH 1/2] serial: st-asc: Don't call BUG in asc_console_setup() Maxime COQUELIN
  2014-07-24 12:02 ` [PATCH 2/2] serial: st-asc: Fix overflow in baudrate calculation Maxime COQUELIN
  0 siblings, 2 replies; 3+ messages in thread
From: Maxime COQUELIN @ 2014-07-24 12:02 UTC (permalink / raw)
  To: linux-arm-kernel

This series contains two fixes for ST's ASC driver.

The first issue addressed is a Kernel BUG when using the console on a different
ASC instance than the one being probed.

The second one is an overflow during buad rate calculation when requested rate
is higher than about 262Kbauds.

Maxime Coquelin (2):
  serial: st-asc: Don't call BUG in asc_console_setup()
  serial: st-asc: Fix overflow in baudrate calculation

 drivers/tty/serial/st-asc.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

-- 
1.9.1

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

* [PATCH 1/2] serial: st-asc: Don't call BUG in asc_console_setup()
  2014-07-24 12:02 [PATCH 0/2] serial: st-asc: Couple of fixes Maxime COQUELIN
@ 2014-07-24 12:02 ` Maxime COQUELIN
  2014-07-24 12:02 ` [PATCH 2/2] serial: st-asc: Fix overflow in baudrate calculation Maxime COQUELIN
  1 sibling, 0 replies; 3+ messages in thread
From: Maxime COQUELIN @ 2014-07-24 12:02 UTC (permalink / raw)
  To: linux-arm-kernel

In order to prevent an asc instance to be used as early console, BUG_ON is
used on either mapbase or membase being NULL.

Problem is that this condition is also true when we set console to be a ttyASx
different to the first asc instance being probed.

Instead of calling BUG_ON, it now returns -ENXIO when either mapbase or
membase is NULL.

Signed-off-by: Maxime Coquelin <maxime.coquelin@st.com>
---
 drivers/tty/serial/st-asc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/st-asc.c b/drivers/tty/serial/st-asc.c
index f48b1cc..2369bc0 100644
--- a/drivers/tty/serial/st-asc.c
+++ b/drivers/tty/serial/st-asc.c
@@ -849,7 +849,8 @@ static int asc_console_setup(struct console *co, char *options)
 	 * this to be called during the uart port registration when the
 	 * driver gets probed and the port should be mapped at that point.
 	 */
-	BUG_ON(ascport->port.mapbase == 0 || ascport->port.membase == NULL);
+	if (ascport->port.mapbase == 0 || ascport->port.membase == NULL)
+		return -ENXIO;
 
 	if (options)
 		uart_parse_options(options, &baud, &parity, &bits, &flow);
-- 
1.9.1

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

* [PATCH 2/2] serial: st-asc: Fix overflow in baudrate calculation
  2014-07-24 12:02 [PATCH 0/2] serial: st-asc: Couple of fixes Maxime COQUELIN
  2014-07-24 12:02 ` [PATCH 1/2] serial: st-asc: Don't call BUG in asc_console_setup() Maxime COQUELIN
@ 2014-07-24 12:02 ` Maxime COQUELIN
  1 sibling, 0 replies; 3+ messages in thread
From: Maxime COQUELIN @ 2014-07-24 12:02 UTC (permalink / raw)
  To: linux-arm-kernel

In the current calculation, if the required baud rate is above 262143,
we get an overflow.

This patch uses a 64bits variable to do the maths.
Also, we remove the '+1' to avoid a divide by zero if the input clock
rate is something unexpected.
Indeed, if the input clock rate is zero, it is preferable to be notified,
since the UART won't work anyway.

Signed-off-by: Maxime Coquelin <maxime.coquelin@st.com>
---
 drivers/tty/serial/st-asc.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/serial/st-asc.c b/drivers/tty/serial/st-asc.c
index 2369bc0..7ac9902 100644
--- a/drivers/tty/serial/st-asc.c
+++ b/drivers/tty/serial/st-asc.c
@@ -533,12 +533,12 @@ static void asc_set_termios(struct uart_port *port, struct ktermios *termios,
 		 * ASCBaudRate =   ------------------------
 		 *                          inputclock
 		 *
-		 * However to keep the maths inside 32bits we divide top and
-		 * bottom by 64. The +1 is to avoid a divide by zero if the
-		 * input clock rate is something unexpected.
+		 * To keep maths inside 64bits, we divide inputclock by 16.
 		 */
-		u32 counter = (baud * 16384) / ((port->uartclk / 64) + 1);
-		asc_out(port, ASC_BAUDRATE, counter);
+		u64 dividend = (u64)baud * (1 << 16);
+
+		do_div(dividend, port->uartclk / 16);
+		asc_out(port, ASC_BAUDRATE, dividend);
 		ctrl_val |= ASC_CTL_BAUDMODE;
 	}
 
-- 
1.9.1

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

end of thread, other threads:[~2014-07-24 12:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-24 12:02 [PATCH 0/2] serial: st-asc: Couple of fixes Maxime COQUELIN
2014-07-24 12:02 ` [PATCH 1/2] serial: st-asc: Don't call BUG in asc_console_setup() Maxime COQUELIN
2014-07-24 12:02 ` [PATCH 2/2] serial: st-asc: Fix overflow in baudrate calculation Maxime COQUELIN

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