]>
Commit | Line | Data |
---|---|---|
9d0aa67b GKH |
1 | From ace965696da2611af759f0284e26342b7b6cec89 Mon Sep 17 00:00:00 2001 |
2 | From: Geert Uytterhoeven <geert+renesas@glider.be> | |
3 | Date: Mon, 1 Apr 2019 13:25:10 +0200 | |
4 | Subject: serial: sh-sci: Fix HSCIF RX sampling point calculation | |
5 | ||
6 | From: Geert Uytterhoeven <geert+renesas@glider.be> | |
7 | ||
8 | commit ace965696da2611af759f0284e26342b7b6cec89 upstream. | |
9 | ||
10 | There are several issues with the formula used for calculating the | |
11 | deviation from the intended rate: | |
12 | 1. While min_err and last_stop are signed, srr and baud are unsigned. | |
13 | Hence the signed values are promoted to unsigned, which will lead | |
14 | to a bogus value of deviation if min_err is negative, | |
15 | 2. Srr is the register field value, which is one less than the actual | |
16 | sampling rate factor, | |
17 | 3. The divisions do not use rounding. | |
18 | ||
19 | Fix this by casting unsigned variables to int, adding one to srr, and | |
20 | using a single DIV_ROUND_CLOSEST(). | |
21 | ||
22 | Fixes: 63ba1e00f178a448 ("serial: sh-sci: Support for HSCIF RX sampling point adjustment") | |
23 | Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> | |
24 | Reviewed-by: Mukesh Ojha <mojha@codeaurora.org> | |
25 | Cc: stable <stable@vger.kernel.org> | |
26 | Reviewed-by: Ulrich Hecht <uli+renesas@fpond.eu> | |
27 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
28 | ||
29 | --- | |
30 | drivers/tty/serial/sh-sci.c | 4 +++- | |
31 | 1 file changed, 3 insertions(+), 1 deletion(-) | |
32 | ||
33 | --- a/drivers/tty/serial/sh-sci.c | |
34 | +++ b/drivers/tty/serial/sh-sci.c | |
35 | @@ -2497,7 +2497,9 @@ done: | |
36 | * center of the last stop bit in sampling clocks. | |
37 | */ | |
38 | int last_stop = bits * 2 - 1; | |
39 | - int deviation = min_err * srr * last_stop / 2 / baud; | |
40 | + int deviation = DIV_ROUND_CLOSEST(min_err * last_stop * | |
41 | + (int)(srr + 1), | |
42 | + 2 * (int)baud); | |
43 | ||
44 | if (abs(deviation) >= 2) { | |
45 | /* At least two sampling clocks off at the |