From patchwork Thu Jul 24 12:02:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime COQUELIN X-Patchwork-Id: 34196 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f200.google.com (mail-pd0-f200.google.com [209.85.192.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 24BBC20C7F for ; Thu, 24 Jul 2014 12:03:59 +0000 (UTC) Received: by mail-pd0-f200.google.com with SMTP id w10sf16806685pde.3 for ; Thu, 24 Jul 2014 05:03:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=PElQPUDbjjMaOWJM+wnW050xHxIkFom5hOtgek4seqM=; b=GsIOg1SMvsL4sdHaTdkNri7s5WaOrsWkxr5bYBVTl1HZx9qz7upoimnniwE8xB8Mje lnlCkgC9bC+t/tAA8Y4Dr+sqXZj209CHds/fdKdVduCGSQeG6eX+uzvZO5z9d7bzuw/u ah9X87G63kpLIbloXngLbe2wWxSL3idcdbxj4T4P7clg4VbCUqn5BiJMaWsWmlyZVZFR inHaqQ0gL5ofF67APAU8fW+eqwF2B1xmZ2ARqZ8iUIZED1HRMlzOoJuFR2WrUWdKQsPy x68vUGG3JMLn+izpO4QYJ7TgJI1XhHvY6g3ReBpAf2j4KeYq6QEgorRMrh/5y+HOUsY1 +JCA== X-Gm-Message-State: ALoCoQlQWSBPuYyaJw69cb/hxLc/HuVjCNtGtBCJ0HD/xZAjVfh0z6UnKfPsi7XDYrxR8LuGFp5R X-Received: by 10.70.102.205 with SMTP id fq13mr4101082pdb.6.1406203438445; Thu, 24 Jul 2014 05:03:58 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.23.19 with SMTP id 19ls103412qgo.59.gmail; Thu, 24 Jul 2014 05:03:58 -0700 (PDT) X-Received: by 10.221.66.67 with SMTP id xp3mr11479662vcb.44.1406203438153; Thu, 24 Jul 2014 05:03:58 -0700 (PDT) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by mx.google.com with ESMTPS id uq10si3936500veb.46.2014.07.24.05.03.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 24 Jul 2014 05:03:58 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.179 as permitted sender) client-ip=209.85.220.179; Received: by mail-vc0-f179.google.com with SMTP id hq11so4549176vcb.24 for ; Thu, 24 Jul 2014 05:03:58 -0700 (PDT) X-Received: by 10.221.34.13 with SMTP id sq13mr11609425vcb.16.1406203437984; Thu, 24 Jul 2014 05:03:57 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp358803vcb; Thu, 24 Jul 2014 05:03:57 -0700 (PDT) X-Received: by 10.70.88.105 with SMTP id bf9mr9867994pdb.54.1406203437017; Thu, 24 Jul 2014 05:03:57 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ds16si2895539pdb.219.2014.07.24.05.03.56 for ; Thu, 24 Jul 2014 05:03:57 -0700 (PDT) Received-SPF: none (google.com: linux-serial-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751833AbaGXMDz (ORCPT + 1 other); Thu, 24 Jul 2014 08:03:55 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:34630 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751084AbaGXMDy (ORCPT ); Thu, 24 Jul 2014 08:03:54 -0400 Received: from pps.filterd (m0046670.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.14.5/8.14.5) with SMTP id s6OBxfJQ015206; Thu, 24 Jul 2014 14:03:22 +0200 Received: from beta.dmz-us.st.com (beta.dmz-us.st.com [167.4.1.35]) by mx07-00178001.pphosted.com with ESMTP id 1naxk9s67t-1 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Thu, 24 Jul 2014 14:03:22 +0200 Received: from zeta.dmz-us.st.com (ns4.st.com [167.4.16.71]) by beta.dmz-us.st.com (STMicroelectronics) with ESMTP id 9378029; Thu, 24 Jul 2014 12:03:18 +0000 (GMT) Received: from mail7.sgp.st.com (unknown [164.129.223.81]) by zeta.dmz-us.st.com (STMicroelectronics) with ESMTP id 9511B65; Thu, 24 Jul 2014 12:03:16 +0000 (GMT) Received: from lmenx29l.lme.st.com ([10.201.23.80]) by mail7.sgp.st.com (MOS 4.3.3-GA) with ESMTP id BZR07648 (AUTH lme00137); Thu, 24 Jul 2014 14:03:11 +0200 From: Maxime COQUELIN To: Greg Kroah-Hartman , Jiri Slaby , Srinivas Kandagatla , Patrice Chotard , linux-arm-kernel@lists.infradead.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Cc: kernel@stlinux.com, maxime.coquelin@st.com Subject: [PATCH 2/2] serial: st-asc: Fix overflow in baudrate calculation Date: Thu, 24 Jul 2014 14:02:56 +0200 Message-Id: <1406203376-18203-3-git-send-email-maxime.coquelin@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1406203376-18203-1-git-send-email-maxime.coquelin@st.com> References: <1406203376-18203-1-git-send-email-maxime.coquelin@st.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.12.52, 1.0.14, 0.0.0000 definitions=2014-07-24_03:2014-07-24, 2014-07-24, 1970-01-01 signatures=0 Sender: linux-serial-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-serial@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: maxime.coquelin@st.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.179 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , In the current calculation, if the required baud rate is above 262143, we get an overflow. This patch uses a 64bits variable to do the maths. Also, we remove the '+1' to avoid a divide by zero if the input clock rate is something unexpected. Indeed, if the input clock rate is zero, it is preferable to be notified, since the UART won't work anyway. Signed-off-by: Maxime Coquelin --- drivers/tty/serial/st-asc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/tty/serial/st-asc.c b/drivers/tty/serial/st-asc.c index 2369bc0..7ac9902 100644 --- a/drivers/tty/serial/st-asc.c +++ b/drivers/tty/serial/st-asc.c @@ -533,12 +533,12 @@ static void asc_set_termios(struct uart_port *port, struct ktermios *termios, * ASCBaudRate = ------------------------ * inputclock * - * However to keep the maths inside 32bits we divide top and - * bottom by 64. The +1 is to avoid a divide by zero if the - * input clock rate is something unexpected. + * To keep maths inside 64bits, we divide inputclock by 16. */ - u32 counter = (baud * 16384) / ((port->uartclk / 64) + 1); - asc_out(port, ASC_BAUDRATE, counter); + u64 dividend = (u64)baud * (1 << 16); + + do_div(dividend, port->uartclk / 16); + asc_out(port, ASC_BAUDRATE, dividend); ctrl_val |= ASC_CTL_BAUDMODE; }