From patchwork Fri Apr 7 15:34:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 9669683 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9FA44602A0 for ; Fri, 7 Apr 2017 15:35:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9070A285E8 for ; Fri, 7 Apr 2017 15:35:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 843B928609; Fri, 7 Apr 2017 15:35:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0B9EC285E8 for ; Fri, 7 Apr 2017 15:35:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=8vVbYiR6X6IxtXrPEcPnUOKwCYGOdx2WtGwII/YFrak=; b=kwpH6FqmorauOtgTymo84tLlKq LOBFPcs1bzm43QrMgxeiGmJiWQar6eWSBGO4lCLtcAsYN2txMkx/1wSSaOq/ZmOfUUgPm8XSgkW+A /BBThnHuFf8PLSWDzT0esCAFfgEs9P/hbkyAnA1S1sSinm0tElblBPeMtu+V1utMLf9nKVGT5wM6N 2cDWRwa1/C5qwSMm4qWINwthRewN2YOl/HM4g65GBuKSi1869B2hvFRnmYm1DZI5cM6Y0YZaTvVCi rVk6vIKjULExhtX8R8OBPgGxbpZzCDONGQj6+fuXdhUVF3OaNPVsqFb5NFtwDvHZiejQzedHF49jP X19E/l9Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cwVvN-0002Xe-Q0; Fri, 07 Apr 2017 15:35:45 +0000 Received: from mail-wm0-x22c.google.com ([2a00:1450:400c:c09::22c]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cwVue-0000RY-Qn for linux-amlogic@lists.infradead.org; Fri, 07 Apr 2017 15:35:04 +0000 Received: by mail-wm0-x22c.google.com with SMTP id w64so1537963wma.0 for ; Fri, 07 Apr 2017 08:34:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zRkAJSUHxoixPWJ5HkKkmDVxA/eM9dMFt+VA+1U2cF8=; b=uk0pEHl7BSxWy3wOXF3PMM6isPFbudKnBlTIdq+6k7UHuCz/bHwCylDQf6cwr9tNx1 SUYNawXbK/na3JTBHPGWSGlh9IFyONihNOFMeEQPOigjgwEP5Tlu04zWf4//tu9VDhd1 h3Dyz0HMBLfA3TkkuHNopU5Pq/w7W7BFwuH4wRaeXKSra00Ol01ZSZqU3YNSc6WlQORA kz+8r+5c5n7RdunGvFBThYprYvNa6Rm3nDwdfuDUVlOno6dwQR39Jen8nqJgCK/RVhFR FaiuWO1uoqg2jvLu4fLpmqX1KBZ7auTnZCaZTeK7Gb4KpI9P5soeGnKwpAeZa0lbFoc8 lA0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zRkAJSUHxoixPWJ5HkKkmDVxA/eM9dMFt+VA+1U2cF8=; b=oZe20zfiYlN96QpvV120VZFwBo6gz86ixI/telLRHv5a8kYkVueaZXAhU2lWaNvcTR VPxcxXkbOYjxOaXYct5n+Rs1oaORdYBidkkG6tOwN/U/1gjqYWwcFqgXBO42C/GbyDmA l7rSHLza0ZTcGwdW/5kgricCjUB2F84T1WQs9Ir434VHtFlszuKG0b0HEU6E3wq/mc4x mn5dBTRcOH0tUXtPZk/Zap6uuj9uu+fzZ/VUIZAG2Wh12umpSHUIfZbgfjdU8qiZ95V5 XVIZaYkvlldgonniP7ugs2wxrQnaS7jztQnTdkXjzlLzdVFZixXgXyHqjynFrG9yEAXw ugJg== X-Gm-Message-State: AFeK/H0d7AtufRAsONxG2pwCbH379gYMRkHdBZLJiarU39o4i/6+4cR6qMoq1+KhLdi4ckDg X-Received: by 10.28.62.212 with SMTP id l203mr19377415wma.110.1491579279007; Fri, 07 Apr 2017 08:34:39 -0700 (PDT) Received: from localhost.localdomain ([90.63.244.31]) by smtp.googlemail.com with ESMTPSA id 82sm3655870wmg.0.2017.04.07.08.34.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Apr 2017 08:34:38 -0700 (PDT) From: Jerome Brunet To: Martin Blumenstingl , Neil Armstrong , Kevin Hilman , Michael Turquette , Stephen Boyd Subject: [PATCH v2 2/2] clk: meson: mpll: use 64bit math in rate_from_params Date: Fri, 7 Apr 2017 17:34:33 +0200 Message-Id: <20170407153433.18640-3-jbrunet@baylibre.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170407153433.18640-1-jbrunet@baylibre.com> References: <20170407153433.18640-1-jbrunet@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170407_083501_015984_C5F0B841 X-CRM114-Status: GOOD ( 10.31 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: carlo@caione.org, linux-amlogic@lists.infradead.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Jerome Brunet MIME-Version: 1.0 Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Martin Blumenstingl On Meson8b the MPLL parent clock (fixed_pll) has a rate of 2550MHz. Multiplying this with SDM_DEN results in a value greater than 32bits. This is not a problem on the 64bit Meson GX SoCs, but it may result in undefined behavior on the older 32bit Meson8b SoC. While rate_from_params was only introduced recently to make the math reusable from _round_rate and _recalc_rate the original bug exists much longer. Fixes: 1c50da4f27 ("clk: meson: add mpll support") Signed-off-by: Martin Blumenstingl [as discussed on the ml, use DIV_ROUND_UP_ULL] Signed-off-by: Jerome Brunet Reviewed-by: Neil Armstrong --- drivers/clk/meson/clk-mpll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/clk/meson/clk-mpll.c b/drivers/clk/meson/clk-mpll.c index d9462b505dcc..39eab69fe51a 100644 --- a/drivers/clk/meson/clk-mpll.c +++ b/drivers/clk/meson/clk-mpll.c @@ -79,7 +79,7 @@ static long rate_from_params(unsigned long parent_rate, if (n2 < N2_MIN) return -EINVAL; - return (parent_rate * SDM_DEN) / divisor; + return DIV_ROUND_UP_ULL((u64)parent_rate * SDM_DEN, divisor); } static void params_from_rate(unsigned long requested_rate,