Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp181574yba; Mon, 1 Apr 2019 04:26:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqyQm9HGGqHdxjBnrF0qkfIaPzD583r56+eZBmEMUBxfDkT2TqM+sQT/xmsJ6hTlU1kC0LRM X-Received: by 2002:a17:902:7247:: with SMTP id c7mr44618355pll.255.1554117972308; Mon, 01 Apr 2019 04:26:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554117972; cv=none; d=google.com; s=arc-20160816; b=eLJTMSh6zlu495LTV4Gbt/9xW6rZND4EztYJ+pIrHBpnmsDl23Sy9wiX9oh38ve9B3 Kg9CxRMr6dEuKWatcyfdAvD1HCJ85zqyRhg5HmHIFF2rgPcX1O3qFtlwbIVWfkCMc5aS 5g0Pj8/mV2TMSrIsghzNrVohJz95HgYmtLwyyngcQnWEUcrM21gwWUKSMsacB18mjbMO HPkKPNK4RMO8h+gIkdXM5WwQW4UDe+f6TPqXapGFTxNwLb+THMx5QMjMHpJUV0Aj+Rna lEFVjgJQ87WSgug75KXRg/RPltu2GfOHUraoodwDA1Y3WRC/FDuWWbay+1WZ4jmaPGsB xdxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=DH2ZVXC7+ZQ/7tcbjZvELetevyDuhz9JZsJLJEwFYAo=; b=fzv//UofqC++OOMjwMFWyAFronFxE3IMmz4Vxt5Z4gQ6Sl0E8ZMxwWmPurqzFuxm+u wv2pEYMEovetFgTuI6spBbCSa2O59+QV5oVI2L0Fg5XpupMmTEpASFA/Lj9bNSXaq/VN kCdBsbYoB1DurqrghsN25SdZV2fcslV4pkCOuhzJej+uTMe6q9NNqbubF/KyD7JyKT0q EaO9+f18Y+qK2GQNDuNYb9oB145jrGGjnZVKjr3PrsHnzbffL9hJjYRP3zO1FkDm0Oyw PmV67GwrwdRBV/nRLF/FLOXRI/p91Vt6of/oNe6AJxkzb0wHiT0OwlSinGD2FHBquWF4 Qf1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d6si8600735plr.246.2019.04.01.04.25.57; Mon, 01 Apr 2019 04:26:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726565AbfDALZR (ORCPT + 99 others); Mon, 1 Apr 2019 07:25:17 -0400 Received: from michel.telenet-ops.be ([195.130.137.88]:35146 "EHLO michel.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725895AbfDALZQ (ORCPT ); Mon, 1 Apr 2019 07:25:16 -0400 Received: from ramsan ([84.194.111.163]) by michel.telenet-ops.be with bizsmtp id uzRD1z00E3XaVaC06zRDhs; Mon, 01 Apr 2019 13:25:14 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1hAv3x-0003Yp-9v; Mon, 01 Apr 2019 13:25:13 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1hAv3x-000622-6k; Mon, 01 Apr 2019 13:25:13 +0200 From: Geert Uytterhoeven To: Greg Kroah-Hartman , Jiri Slaby , Ulrich Hecht Cc: Eugeniu Rosca , Dirk Behme , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] serial: sh-sci: Fix HSCIF RX sampling point calculation Date: Mon, 1 Apr 2019 13:25:10 +0200 Message-Id: <20190401112510.23145-1-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are several issues with the formula used for calculating the deviation from the intended rate: 1. While min_err and last_stop are signed, srr and baud are unsigned. Hence the signed values are promoted to unsigned, which will lead to a bogus value of deviation if min_err is negative, 2. Srr is the register field value, which is one less than the actual sampling rate factor, 3. The divisions do not use rounding. Fix this by casting unsigned variables to int, adding one to srr, and using a single DIV_ROUND_CLOSEST(). Fixes: 63ba1e00f178a448 ("serial: sh-sci: Support for HSCIF RX sampling point adjustment") Signed-off-by: Geert Uytterhoeven --- Anyone with a good test setup for verifying this feature actually works as advertised? --- drivers/tty/serial/sh-sci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 2bdaeba5d527a6ce..8dea59edde34c224 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -2522,7 +2522,9 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios, * center of the last stop bit in sampling clocks. */ int last_stop = bits * 2 - 1; - int deviation = min_err * srr * last_stop / 2 / baud; + int deviation = DIV_ROUND_CLOSEST(min_err * last_stop * + (int)(srr + 1), + 2 * (int)baud); if (abs(deviation) >= 2) { /* At least two sampling clocks off at the -- 2.17.1