From patchwork Mon Jul 14 07:09:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nobuhiro Iwamatsu X-Patchwork-Id: 4542951 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D0DF49F295 for ; Mon, 14 Jul 2014 07:10:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0E1BB20172 for ; Mon, 14 Jul 2014 07:10:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5F5FD20149 for ; Mon, 14 Jul 2014 07:10:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753092AbaGNHKU (ORCPT ); Mon, 14 Jul 2014 03:10:20 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:47357 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751899AbaGNHKT (ORCPT ); Mon, 14 Jul 2014 03:10:19 -0400 Received: by mail-pa0-f50.google.com with SMTP id bj1so4844757pad.23 for ; Mon, 14 Jul 2014 00:10:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=2k8hwikWRYDtD9S5cupzcUX+AgMsLfS6D6TxpVfNQ90=; b=MbUxRl7PSgu+4s5UFfid1ZwhyN71vjKHr22AppjRoZyw1q7/ofxw0oWt9FJFapalpI XrufZUQaXZcAWgypPPb1jzfaZDw/UNcw/N08IlrwB07vPuxHushZMjhK5iUS9hUgNnTa jHCT2e5SaSK9uLB/dmP9uiD+heBtZc9pE1+//7XYEDYOY19FvSGeUUBLv4ZjrpX1qXn6 /5tfo5E1czAQr0Oav95qZLWu9ea6grBnC+58XhKlSI0d/nVOqjqJ2TJTJ7wr6cFprosa xp0PlY1+3qhcQan+cXGV4v8K4O6+uOIdYyq+7mCqojWVMa7cMz7q63X553WEW0lsYdhU 8Z5Q== X-Gm-Message-State: ALoCoQn4H1D0qwiMNoLrq9y2Xre3pS9oKC3gc1Jn/a3q9JpAr398ydx2bNz+BoUs1ZfcXcuJ8AGT X-Received: by 10.70.92.9 with SMTP id ci9mr15275564pdb.24.1405321818687; Mon, 14 Jul 2014 00:10:18 -0700 (PDT) Received: from xps-iwamatsu.renesas.com (49.14.32.202.bf.2iij.net. [202.32.14.49]) by mx.google.com with ESMTPSA id gi1sm9792864pbd.15.2014.07.14.00.10.16 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 Jul 2014 00:10:17 -0700 (PDT) From: Nobuhiro Iwamatsu To: linux-sh@vger.kernel.org Cc: gregkh@linuxfoundation.org, linux-serial@vger.kernel.org, horms+renesas@verge.net.au, magnus.damm@gmail.com, Nobuhiro Iwamatsu Subject: [PATCH 2/3] serial: sh-sci: Fix range check of bit-rate for HSCIF Date: Mon, 14 Jul 2014 16:09:59 +0900 Message-Id: <1405321800-18114-2-git-send-email-nobuhiro.iwamatsu.yj@renesas.com> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1405321800-18114-1-git-send-email-nobuhiro.iwamatsu.yj@renesas.com> References: <1405321800-18114-1-git-send-email-nobuhiro.iwamatsu.yj@renesas.com> Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If bit-rate calculation result of HSCIF is expect 255 from 0, driver does not calculate error bit. However, we need to round the value to calculate error bit in the case of negative value. This rounds the value of bit-rate using clamp(), and bit-rate is the case of negative value, it enables the calculation of the error bit. Signed-off-by: Nobuhiro Iwamatsu --- drivers/tty/serial/sh-sci.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index ce80137..7f571a8 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -1798,8 +1798,7 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, /* integerized formulas from HSCIF documentation */ br = DIV_ROUND_CLOSEST(freq, (sr * (1 << (2 * c + 1)) * bps)) - 1; - if (br < 0 || br > 255) - continue; + br = clamp(br, 0, 255); err = DIV_ROUND_CLOSEST(freq, ((br + 1) * bps * sr * (1 << (2 * c + 1)) / 1000)) - 1000;