Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp864674yba; Wed, 24 Apr 2019 10:51:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqygDKWkGjLMpvSwqLOv3oYA0LhwPbXmK9h5xbsRmcmwBxWyyfJlYoETW5qrY7Qkx1miSUQF X-Received: by 2002:a63:e751:: with SMTP id j17mr6948181pgk.300.1556128261469; Wed, 24 Apr 2019 10:51:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556128261; cv=none; d=google.com; s=arc-20160816; b=SEbKCzmZD7dofSdKOOhnmcBTe1NXDDeO5XKWxNGl5VRhA6vtdOClyEBl/D5/mKtjqD AYnQlkJxoJNxFEk5tSyinxCTBubj+KZcHUYyGTVoF4Zg7AcdSnhM/5NLcC/vtcTe4/bF pOkkJuhLvRafvtsNMnre8Xn7vZFbyPrI5635Tg1TlxYHKKxL2HIHtkPk4BS9tI9ymi57 J1rjZmmWVXThpx14WLYYZq0KWF8UrF758PcENO6bu4OmvBEHi2S1XGD9sBy/ZoDVq5rZ v4qxFdT/Se0RC+XR14hWP1lZSnRQVo6fPCHfCWoKOIxekMkSB4CS+ebITUPNenzyBVk/ 1CKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=IZoKIFJtDFpLBsEDLII1QJEMD/mt9tR9qgGOK4q/gTw=; b=dNb3+/GhtYYAYRND5LSdMBls5/NIbcuhmbcQd94ZmpD6jRK/WI6DIfrZWLIQA390pg gNThZK2faNUMjLhPc8RcPbJQct7EW3PTvH1moJw34I2u+JvhQhlSLhC28Tr4UWJIe/or uOpp34yl69xfVOOLFLS2XWPMSLHmvHoCSHzIoSvKVLjMzGvepVK/nB1Zdz0ysqG+4iUg eOzGgj06nte0h8tAHK5hADGXGkdOEOqB6jl1PZG2pTDQ8nbYxXNqW3lXEbProO948tFh T/5GNAn9QgEyn4Chb94gJmS2H8Yk+62UrDXg4Ef+RrjAirUCk1/aZ02Jhg2jI2FkDwc5 39jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eMC78qt4; 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 cb16si20946900plb.227.2019.04.24.10.50.46; Wed, 24 Apr 2019 10:51:01 -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=@kernel.org header.s=default header.b=eMC78qt4; 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 S2391135AbfDXRb0 (ORCPT + 99 others); Wed, 24 Apr 2019 13:31:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:57880 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403789AbfDXRbY (ORCPT ); Wed, 24 Apr 2019 13:31:24 -0400 Received: from localhost (62-193-50-229.as16211.net [62.193.50.229]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D454D20811; Wed, 24 Apr 2019 17:31:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556127083; bh=JXrIYMk1HEm5HgsJ5WYaBiGjp44leD+iI1UzFa86uAk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eMC78qt4o2LAQKIFHbIZpCOKo4S9u6S4l3HePREv/iOmWhkx3aebTHOILD6N3/WLl Oh5YdcmpUtbtvy8izS0LsjoRserJPPfqREjQPgWJm9/oRaiyzpQOUVJfh8PkgFUOMd PgT5igUMJfcENwpDlj+WHxA9IpyYVAYiV9WnKomQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Geert Uytterhoeven , Mukesh Ojha , Ulrich Hecht Subject: [PATCH 4.19 56/96] serial: sh-sci: Fix HSCIF RX sampling point calculation Date: Wed, 24 Apr 2019 19:10:01 +0200 Message-Id: <20190424170923.545229462@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190424170919.829037226@linuxfoundation.org> References: <20190424170919.829037226@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Geert Uytterhoeven commit ace965696da2611af759f0284e26342b7b6cec89 upstream. 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 Cc: stable Reviewed-by: Ulrich Hecht Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/sh-sci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -2497,7 +2497,9 @@ done: * 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