summaryrefslogtreecommitdiff
path: root/drivers/tty
diff options
context:
space:
mode:
authorMaxime COQUELIN <maxime.coquelin@st.com>2014-07-24 16:02:56 +0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-07-27 22:05:08 +0400
commit1d6ba284dff546baca58e78546da46be3b48462a (patch)
treeb2455df55830e09ef16570289e5bc741bfbf75cf /drivers/tty
parent5b4e79ae452613a9d391cf1e5ab7e9a49241ad28 (diff)
downloadlinux-1d6ba284dff546baca58e78546da46be3b48462a.tar.xz
serial: st-asc: Fix overflow in baudrate calculation
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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty')
-rw-r--r--drivers/tty/serial/st-asc.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/drivers/tty/serial/st-asc.c b/drivers/tty/serial/st-asc.c
index 4e9f4f29f3ce..8b2d7356611d 100644
--- a/drivers/tty/serial/st-asc.c
+++ b/drivers/tty/serial/st-asc.c
@@ -527,12 +527,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;
}