From: Felipe Balbi <balbi@ti.com>
To: Alexey Pelykh <alexey.pelykh@gmail.com>
Cc: balbi@ti.com, Tony Lindgren <tony@atomide.com>,
Greg KH <gregkh@linuxfoundation.org>,
Linux OMAP Mailing List <linux-omap@vger.kernel.org>,
linux-serial@vger.kernel.org,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: commit 5fe212364 causes division by zero with large bauds
Date: Wed, 11 Sep 2013 14:00:33 -0500 [thread overview]
Message-ID: <20130911190033.GD10105@radagast> (raw)
In-Reply-To: <CAOmKuSpJ4rX0p0a1gGvc3fVazTg=+43tDfTFiJSrxmAxXihf-A@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3142 bytes --]
On Wed, Sep 11, 2013 at 09:48:13PM +0300, Alexey Pelykh wrote:
> On Wed, Sep 11, 2013 at 9:38 PM, Felipe Balbi <balbi@ti.com> wrote:
> > Hi,
> >
> > On Wed, Sep 11, 2013 at 09:22:26AM +0300, Alexey Pelykh wrote:
> >> Hi Felipe,
> >>
> >> Thanks for finding this issue. Indeed, there is a bug on 3M+ baud
> >> rates. First patch is close to a complete fix, but still contains
> >> div-by-zero issue. Here is my version:
> >>
> >> diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
> >> index 816d1a2..808a880 100644
> >> --- a/drivers/tty/serial/omap-serial.c
> >> +++ b/drivers/tty/serial/omap-serial.c
> >> @@ -240,8 +240,8 @@ 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 = n13 ? (baud - (port->uartclk / (13 * n13))) : INT_MAX;
> >> + int baudAbsDiff16 = n16 ? (baud - (port->uartclk / (16 * n16))) : INT_MAX;
> >
> > IOW:
> >
> > int baudAbsDiff13 = 0;
> >
> > if (n13)
> > baudAbsDiff13 = (baud - (port->uartclk / (13 * n13)));
>
> Not quite same code, INT_MAX instead of 0. With 0 a div-by-zero
> exception will still occur on 3686400.
why, there's no division after that point, right ? Besides,
serial_omap_baud_is_mode16() is supposed to return a boolean value.
Setting baudAbsDiff1[36] to 0 will cause no problems, you're only using
that value with a boolean expression, no divisions whatsoever. Division
is done after using serial_omap_baud_is_mode16() to initialize divisor
to 13 or 16 (which is a misnamer, since that's the oversampling
parameter).
> > which is exactly what my patch did. I fail to see where division by zero
> > would be coming from.
> >
> >> if(baudAbsDiff13 < 0)
> >> baudAbsDiff13 = -baudAbsDiff13;
> >> if(baudAbsDiff16 < 0)
> >>
> >>
> >> With 48MHz UART clock, it will give
> >> 300: divisor = 12307 (13), real rate 300 (0.000000%)
> >> 600: divisor = 6153 (13), real rate 600 (0.000000%)
> >> 1200: divisor = 3076 (13), real rate 1200 (0.000000%)
> >> 2400: divisor = 1538 (13), real rate 2400 (0.000000%)
> >
> > TRM has these all set with oversampling of 16. In fact only 460800,
> > 921600, 1843200 and 3686400 should be using oversampling of 13.
> >
>
> That's true, but TRM anyways does not contain all possible baud rates
> (1M e.g.). IMO, as long as error rate is the same as in TRM,
> it makes no difference what combination of (mode, divisor) to use.
>
> > --
> > balbi
>
> A complex solution may be implemented: use LUT for baud rates that TRM
> defines explicitly, and use calculation if lookup failed.
why would you try calculating anything if there is nothing in the table
which can support it ? Whatever is in the lookup table, are the only
baud rates the SoC supports, right ?
cheers
--
balbi
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
WARNING: multiple messages have this Message-ID (diff)
From: Felipe Balbi <balbi@ti.com>
To: Alexey Pelykh <alexey.pelykh@gmail.com>
Cc: <balbi@ti.com>, Tony Lindgren <tony@atomide.com>,
Greg KH <gregkh@linuxfoundation.org>,
Linux OMAP Mailing List <linux-omap@vger.kernel.org>,
<linux-serial@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: commit 5fe212364 causes division by zero with large bauds
Date: Wed, 11 Sep 2013 14:00:33 -0500 [thread overview]
Message-ID: <20130911190033.GD10105@radagast> (raw)
In-Reply-To: <CAOmKuSpJ4rX0p0a1gGvc3fVazTg=+43tDfTFiJSrxmAxXihf-A@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3142 bytes --]
On Wed, Sep 11, 2013 at 09:48:13PM +0300, Alexey Pelykh wrote:
> On Wed, Sep 11, 2013 at 9:38 PM, Felipe Balbi <balbi@ti.com> wrote:
> > Hi,
> >
> > On Wed, Sep 11, 2013 at 09:22:26AM +0300, Alexey Pelykh wrote:
> >> Hi Felipe,
> >>
> >> Thanks for finding this issue. Indeed, there is a bug on 3M+ baud
> >> rates. First patch is close to a complete fix, but still contains
> >> div-by-zero issue. Here is my version:
> >>
> >> diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
> >> index 816d1a2..808a880 100644
> >> --- a/drivers/tty/serial/omap-serial.c
> >> +++ b/drivers/tty/serial/omap-serial.c
> >> @@ -240,8 +240,8 @@ 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 = n13 ? (baud - (port->uartclk / (13 * n13))) : INT_MAX;
> >> + int baudAbsDiff16 = n16 ? (baud - (port->uartclk / (16 * n16))) : INT_MAX;
> >
> > IOW:
> >
> > int baudAbsDiff13 = 0;
> >
> > if (n13)
> > baudAbsDiff13 = (baud - (port->uartclk / (13 * n13)));
>
> Not quite same code, INT_MAX instead of 0. With 0 a div-by-zero
> exception will still occur on 3686400.
why, there's no division after that point, right ? Besides,
serial_omap_baud_is_mode16() is supposed to return a boolean value.
Setting baudAbsDiff1[36] to 0 will cause no problems, you're only using
that value with a boolean expression, no divisions whatsoever. Division
is done after using serial_omap_baud_is_mode16() to initialize divisor
to 13 or 16 (which is a misnamer, since that's the oversampling
parameter).
> > which is exactly what my patch did. I fail to see where division by zero
> > would be coming from.
> >
> >> if(baudAbsDiff13 < 0)
> >> baudAbsDiff13 = -baudAbsDiff13;
> >> if(baudAbsDiff16 < 0)
> >>
> >>
> >> With 48MHz UART clock, it will give
> >> 300: divisor = 12307 (13), real rate 300 (0.000000%)
> >> 600: divisor = 6153 (13), real rate 600 (0.000000%)
> >> 1200: divisor = 3076 (13), real rate 1200 (0.000000%)
> >> 2400: divisor = 1538 (13), real rate 2400 (0.000000%)
> >
> > TRM has these all set with oversampling of 16. In fact only 460800,
> > 921600, 1843200 and 3686400 should be using oversampling of 13.
> >
>
> That's true, but TRM anyways does not contain all possible baud rates
> (1M e.g.). IMO, as long as error rate is the same as in TRM,
> it makes no difference what combination of (mode, divisor) to use.
>
> > --
> > balbi
>
> A complex solution may be implemented: use LUT for baud rates that TRM
> defines explicitly, and use calculation if lookup failed.
why would you try calculating anything if there is nothing in the table
which can support it ? Whatever is in the lookup table, are the only
baud rates the SoC supports, right ?
cheers
--
balbi
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
next prev parent reply other threads:[~2013-09-11 19:00 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-10 19:09 commit 5fe212364 causes division by zero with large bauds Felipe Balbi
2013-09-10 19:09 ` Felipe Balbi
2013-09-11 6:22 ` Alexey Pelykh
2013-09-11 18:38 ` Felipe Balbi
2013-09-11 18:38 ` Felipe Balbi
2013-09-11 18:48 ` Alexey Pelykh
2013-09-11 19:00 ` Felipe Balbi [this message]
2013-09-11 19:00 ` Felipe Balbi
2013-09-11 19:19 ` Alexey Pelykh
2013-09-11 20:47 ` Felipe Balbi
2013-09-11 20:47 ` Felipe Balbi
2013-09-12 4:32 ` Alexey Pelykh
2013-09-12 4:37 ` Alexey Pelykh
2013-09-12 12:21 ` Felipe Balbi
2013-09-12 12:21 ` Felipe Balbi
2013-09-12 14:38 ` Alexey Pelykh
2013-09-12 12:17 ` Felipe Balbi
2013-09-12 12:17 ` Felipe Balbi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130911190033.GD10105@radagast \
--to=balbi@ti.com \
--cc=alexey.pelykh@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=tony@atomide.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.