Message ID | 1410789610-23059-3-git-send-email-frans.klaver@xsens.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c index ae935ce..7d3f557 100644 --- a/drivers/tty/serial/omap-serial.c +++ b/drivers/tty/serial/omap-serial.c @@ -246,8 +246,12 @@ static inline int calculate_baud_abs_diff(struct uart_port *port, unsigned int baud, unsigned int mode) { unsigned int n = port->uartclk / (mode * baud); - int abs_diff = baud - (port->uartclk / (mode * n)); + int abs_diff; + if (n == 0) + n = 1; + + abs_diff = baud - (port->uartclk / (mode * n)); if (abs_diff < 0) abs_diff = -abs_diff;
If the chosen baud rate is large enough (e.g. 3.5 megabaud), the calculated n values in calculate_baud_abs_diff may become 0. This causes a division by zero when calculating the difference between calculated and desired baud rates. To prevent this, cap n on 1. Signed-off-by: Frans Klaver <frans.klaver@xsens.com> --- drivers/tty/serial/omap-serial.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)