]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/5.0.10/serial-sh-sci-fix-hscif-rx-sampling-point-calculation.patch
Fixes for 4.19
[thirdparty/kernel/stable-queue.git] / releases / 5.0.10 / serial-sh-sci-fix-hscif-rx-sampling-point-calculation.patch
CommitLineData
9d0aa67b
GKH
1From ace965696da2611af759f0284e26342b7b6cec89 Mon Sep 17 00:00:00 2001
2From: Geert Uytterhoeven <geert+renesas@glider.be>
3Date: Mon, 1 Apr 2019 13:25:10 +0200
4Subject: serial: sh-sci: Fix HSCIF RX sampling point calculation
5
6From: Geert Uytterhoeven <geert+renesas@glider.be>
7
8commit ace965696da2611af759f0284e26342b7b6cec89 upstream.
9
10There are several issues with the formula used for calculating the
11deviation 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
19Fix this by casting unsigned variables to int, adding one to srr, and
20using a single DIV_ROUND_CLOSEST().
21
22Fixes: 63ba1e00f178a448 ("serial: sh-sci: Support for HSCIF RX sampling point adjustment")
23Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
24Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>
25Cc: stable <stable@vger.kernel.org>
26Reviewed-by: Ulrich Hecht <uli+renesas@fpond.eu>
27Signed-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