lkml.org 
[lkml]   [2014]   [Jul]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/3] tty: omap-serial: prevent division by zero
Sorry, missed some CC's in git send-email.

On Tue, Jul 29, 2014 at 04:52:55PM +0200, Frans Klaver wrote:
> If the chosen baud rate is large enough (e.g. 3.5 megabaud), the
> calculated n13 and n16 values in serial_omap_baud_is_mode16 may become
> 0. This causes a division by zero when calculating the difference
> between calculated and desired baud rates. To prevent this, cap n13 and
> n16 on 1.
>
> Signed-off-by: Frans Klaver <frans.klaver@xsens.com>
> ---
> drivers/tty/serial/omap-serial.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
> index d017cec..e454b7c 100644
> --- a/drivers/tty/serial/omap-serial.c
> +++ b/drivers/tty/serial/omap-serial.c
> @@ -254,8 +254,16 @@ serial_omap_baud_is_mode16(struct uart_port *port, unsigned int baud)
> {
> unsigned int n13 = port->uartclk / (13 * baud);
> unsigned int n16 = port->uartclk / (16 * baud);
> - int baudAbsDiff13 = baud - (port->uartclk / (13 * n13));
> - int baudAbsDiff16 = baud - (port->uartclk / (16 * n16));
> + int baudAbsDiff13;
> + int baudAbsDiff16;
> +
> + if (n13 == 0)
> + n13 = 1;
> + if (n16 == 0)
> + n16 = 1;
> +
> + baudAbsDiff13 = baud - (port->uartclk / (13 * n13));
> + baudAbsDiff16 = baud - (port->uartclk / (16 * n16));
> if (baudAbsDiff13 < 0)
> baudAbsDiff13 = -baudAbsDiff13;
> if (baudAbsDiff16 < 0)
> --
> 1.9.3
>


\
 
 \ /
  Last update: 2014-07-29 17:41    [W:0.151 / U:0.268 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site