Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp219277yba; Mon, 1 Apr 2019 05:13:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqwtKUSWG1kFmK1VFNPMaoXRO+bYE+gfgsX+i1YSWiiUQ+a2Xhk/RZpMGvqhF/IiOnTztByL X-Received: by 2002:a65:414a:: with SMTP id x10mr46201331pgp.237.1554120803165; Mon, 01 Apr 2019 05:13:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554120803; cv=none; d=google.com; s=arc-20160816; b=lupLxgBjLVvLC5byu4ynU1sDPdpuT+qbV+9jV6pHwTP6JZbH6If7swTXXy9QdChhCy 2DLy8eSVT+gywdMa8Ee6BMciFw7O5vaLLDuOYtGNUzlNMBQHUqL+mQ6b9isABQyDfTEo Do5+K9ta2Ci+QaaykbnPav3C/azsjlDFPKZyhVMBRggZPS8ZPNNQcBFMtyR89XUHxBgj 2Sb0Y4pZ065LZVie2ZX6lz90XC1vrGdDAQtvJ+32MkHVn50/cRaAyx9j9yJGTEKxh7m2 tGFiQThS8LQqKTMm/BUB9kByStsozjzwMOGA7bML3ota1K0JpnvM7M5tdObeknCK5X1a SP5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dmarc-filter :dkim-signature:dkim-signature; bh=7PjlXtV4Y2z7xxXnB5g1KFTL2FXmW4gPEC/CqFzXx7Q=; b=GJC993rNmU7Xyr8OSrER/HKQoZo+tK11CwxjytGxBFyn34d4udAAGnDpOI/7elvk3C H2tq1zpgcY2DLxyzs6dYiEtfCIDY5A0MJv/sUZSWdrDYomcefao5lYR6HNhjnIU5mL1C ae9A2E11D7uN+wOdrZ1jXTU1kzSRwA0rLQT8E0UngAaObmeKJvGG0UkNQJ8Kr6A2zx// h0X9eDlYba3+KY2ozrJ/W8hL/JTYjRBV2WkNiRYPJJkCX08r3RDwupg47C5/+Yx5Kyq/ 75Un5dYnRfWjEYStTbmnzrXU5r0qUa2nZXW/ClolqKePRFaZ0ZM/aSIghC5GLUgoONE1 danA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=UpgawT9v; dkim=pass header.i=@codeaurora.org header.s=default header.b=UFt6IEPN; 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 h6si8463407pfn.229.2019.04.01.05.13.06; Mon, 01 Apr 2019 05:13:23 -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; dkim=pass header.i=@codeaurora.org header.s=default header.b=UpgawT9v; dkim=pass header.i=@codeaurora.org header.s=default header.b=UFt6IEPN; 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 S1726617AbfDAMMa (ORCPT + 99 others); Mon, 1 Apr 2019 08:12:30 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:40008 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726284AbfDAMMa (ORCPT ); Mon, 1 Apr 2019 08:12:30 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 84FC76079C; Mon, 1 Apr 2019 12:12:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1554120748; bh=63lf0uKIjQ4rX5WBWvMIiH8gLdAuxrN0svjXwnrOCiM=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=UpgawT9vNKRWXRhR7FzL2L7c4nJIrj36F73r3lGr/jMN1Sz6WdRmsoZDMAWGCSY0M 3c5kM0N1p7yKDrG6eBRHfi4XR6fIl0VfJnsVqfmcJEk6PNKu7KNIlndxJifrmV70vJ +dybDm7ISEWf88Fz7Fv2SjqToV0YexBaCHKkh2ew= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.0 Received: from [10.204.79.83] (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mojha@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id C32E56079C; Mon, 1 Apr 2019 12:12:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1554120745; bh=63lf0uKIjQ4rX5WBWvMIiH8gLdAuxrN0svjXwnrOCiM=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=UFt6IEPNjQqobcPV4gyJ/CXjL1k4wREl+gUmb2PxrYPtBWhTNmn6OLBn15xFfL2kT JIjkrCIRtRRHLOnacVL4Yo9CQd+xN9o6g72IefendWUIubacTBc0R+Q0EiQ7FrOgtP W14y17KA4Oq2z6ZL88gUnv0SXAX6fBxTunO/kbik= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org C32E56079C Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=mojha@codeaurora.org Subject: Re: [PATCH] serial: sh-sci: Fix HSCIF RX sampling point calculation To: Geert Uytterhoeven , Greg Kroah-Hartman , Jiri Slaby , Ulrich Hecht Cc: Eugeniu Rosca , Dirk Behme , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org References: <20190401112510.23145-1-geert+renesas@glider.be> From: Mukesh Ojha Message-ID: <3361fcd0-12e6-aaf8-33c2-54a99bac1900@codeaurora.org> Date: Mon, 1 Apr 2019 17:42:17 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190401112510.23145-1-geert+renesas@glider.be> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/1/2019 4:55 PM, Geert Uytterhoeven wrote: > 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 Reviewed-by: Mukesh Ojha Cheers, -Mukesh > --- > 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