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>
This commit is contained in:
Maxime COQUELIN 2014-07-24 14:02:56 +02:00 коммит произвёл Greg Kroah-Hartman
Родитель 5b4e79ae45
Коммит 1d6ba284df
1 изменённых файлов: 5 добавлений и 5 удалений

Просмотреть файл

@ -527,12 +527,12 @@ static void asc_set_termios(struct uart_port *port, struct ktermios *termios,
* ASCBaudRate = ------------------------ * ASCBaudRate = ------------------------
* inputclock * inputclock
* *
* However to keep the maths inside 32bits we divide top and * To keep maths inside 64bits, we divide inputclock by 16.
* bottom by 64. The +1 is to avoid a divide by zero if the
* input clock rate is something unexpected.
*/ */
u32 counter = (baud * 16384) / ((port->uartclk / 64) + 1); u64 dividend = (u64)baud * (1 << 16);
asc_out(port, ASC_BAUDRATE, counter);
do_div(dividend, port->uartclk / 16);
asc_out(port, ASC_BAUDRATE, dividend);
ctrl_val |= ASC_CTL_BAUDMODE; ctrl_val |= ASC_CTL_BAUDMODE;
} }