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: 9669679 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 8DBE6602A0 for ; Fri, 7 Apr 2017 15:35:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7EE12285E8 for ; Fri, 7 Apr 2017 15:35:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7327728609; Fri, 7 Apr 2017 15:35:21 +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 E8592285E8 for ; Fri, 7 Apr 2017 15:35:20 +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=kFgCu25PszxtyhEK8IVirV3pl/4zMXG5mtrYIfqQ9HY=; b=FYrOk7kXzcr3mKCISESNKKCd7j WEfW+rm3ijcP42yh4S0Rjbe+qI5lFVA+V1/CXK6c0fUCgKwVd89jxVkN5PWzIYXJ1XlJD5X2LFOO3 amCW1d5QDD7QuTRwqDzBuFNxBYLu0LnrEz1B+eTcoh4cjriaob7JNKlynsQ7YGFCScvzdFJ0QWokO 4MPyaX2Cuhy3ovGG0hLgiOSvwrZvb4mvUcsNbwh/6m2CfRC4URVQEnyfhqUQlY4IFUmw4VAPWMzFN rmhceFa72ZK8V9P0cvoDe1RNvxOHcS2PtlXb6xvYQ41TLUw9pmBp0Qby8MfCZtfqUrzfIDTkNwl7v +zUPkHJg==; 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 1cwVux-0001v4-G0; Fri, 07 Apr 2017 15:35:19 +0000 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cwVue-0000RX-Fm for linux-arm-kernel@lists.infradead.org; Fri, 07 Apr 2017 15:35:03 +0000 Received: by mail-wm0-x22a.google.com with SMTP id t189so10484656wmt.1 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=FRr+Yd7JASx6JUQI8wEMYHDev9NyYc486Kwq2zZW1jQkm5UJ1d5H4t5hBuWaXV0gwL ZLk0WX7aiOd+O969LEVahSHqA5preh9kGXqlNfLxiNZPV+qwOV9u1rt6dqJ+p64VIxN+ 4BAs1/Ck6mSe8cmfBpVvvftbMYZV+PvNSIR1VMRhIKsjSM0ME+slPZ6hG5GoFflPnwBD IwNqFu7Tq0F+t0ZSCMvC78h0+CdtNT/aH8t3SzflboLSoVOua0tKZnEUPVpUNgSQB1fn cwZch0jMlhZ+F2bsqEbNyIJmJMlGMfnxSp9o5Umty9WAcnBb/l2hzt/B6/5oL76YOzmC cLZA== X-Gm-Message-State: AFeK/H3QKZFomhP0w+msbL58Izi8Pp7Huf6w1rWUK1JytytirMOMxPn9HC8x3GbTZEvcNsq8 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_083500_671973_166C6A95 X-CRM114-Status: GOOD ( 11.74 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=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,