From patchwork Sat Apr 1 13:02:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 9657831 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 13A5860353 for ; Sat, 1 Apr 2017 13:02:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7E3127B2F for ; Sat, 1 Apr 2017 13:02:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC8502856C; Sat, 1 Apr 2017 13:02:33 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B4C627B2F for ; Sat, 1 Apr 2017 13:02:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751359AbdDANCd (ORCPT ); Sat, 1 Apr 2017 09:02:33 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:35592 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751124AbdDANCc (ORCPT ); Sat, 1 Apr 2017 09:02:32 -0400 Received: by mail-wr0-f196.google.com with SMTP id p52so23973404wrc.2 for ; Sat, 01 Apr 2017 06:02:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VL/6v5fiRsYWaSjUMsJI41ZZizs6KVUBjv8xhWW0a0s=; b=rxbKVqhNvsfwFw+lY+CqDtcqVgDphbMbVf5EvUyrlOwEMoMyXPqJpSUbjPHe61xCgZ jndKqPQW6OonW6Uy0F3x/VE/1PNP8of1GNTo1Znf/LgFoljc03F3g5bxu2gQLqItdJiE AZ6buqp8/ORlsFelFt6wGAQMm3E4R+fyK84aXB6MrFs+ChMCwLxFkprZ0+rZjc4Zr2I6 LcOzWk+Kip6ScExmlbjPNvwy2CVZaY+05UkmkvrBTl19bbsGNCmXg7EKhcUJAELDq/iS SLluat7CWnqUZmwaPpdZtq/f7xkp9K6LfA0dUdnq0MLeUhRqub5cwhHykKu/RZ1soF06 lAzQ== 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=VL/6v5fiRsYWaSjUMsJI41ZZizs6KVUBjv8xhWW0a0s=; b=UWmANQ5snyU2yen3bVpxGxLer8LYIjVHTR19UMuvsPl1EUm0QqV2pYQFvUDZ3RTilI NKActXyvWXioLF6cJLDPnCB3trT+cAgEr41oo0sYn2cKyZjBOkicDR15z3yu1D7z1I6r PfGE9oKP8iRzPXyR3ecUqCUJ2sOoCc6g8n+uGP0U5PTSmlXxIKQNRMfTrwpi6biPHp3u 95vazMcF7RoTJ7iKgeAbPrODg1CyzYZQuKar7aowRIbnpwcdz54DeppHCgYcQ8Ad9e3C kp1X+Dq7B0CgV59/tR38DqWxBDebxoYIeE7l+hAIlZaD13iPMyEVLSv0YMIjjRy4FUGN OcNQ== X-Gm-Message-State: AFeK/H0OjOwDRc56zx1GvNQ+6KMDLPPge4S6IdCX8YKErgzoYCROvE9qymg5dAH6mg61aQ== X-Received: by 10.223.164.83 with SMTP id e19mr7610801wra.154.1491051751363; Sat, 01 Apr 2017 06:02:31 -0700 (PDT) Received: from blackbox.darklights.net (p5DE38642.dip0.t-ipconnect.de. [93.227.134.66]) by smtp.googlemail.com with ESMTPSA id f135sm2749073wmd.7.2017.04.01.06.02.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Apr 2017 06:02:30 -0700 (PDT) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, linux-clk@vger.kernel.org, jbrunet@baylibre.com, sboyd@codeaurora.org, mturquette@baylibre.com, narmstrong@baylibre.com Cc: linux-arm-kernel@lists.infradead.org, khilman@baylibre.com, carlo@caione.org, Martin Blumenstingl Subject: [PATCH 2/2] clk: meson: mpll: use 64bit math in rate_from_params Date: Sat, 1 Apr 2017 15:02:25 +0200 Message-Id: <20170401130225.8811-3-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.12.1 In-Reply-To: <20170401130225.8811-1-martin.blumenstingl@googlemail.com> References: <20170401130225.8811-1-martin.blumenstingl@googlemail.com> Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/clk/meson/clk-mpll.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/clk/meson/clk-mpll.c b/drivers/clk/meson/clk-mpll.c index 551aa2a5b291..4306ad833a4f 100644 --- a/drivers/clk/meson/clk-mpll.c +++ b/drivers/clk/meson/clk-mpll.c @@ -62,6 +62,7 @@ */ #include +#include #include "clkc.h" #define SDM_DEN 16384 @@ -81,7 +82,7 @@ static unsigned long rate_from_params(unsigned long parent_rate, if (divisor == 0) return 0; else - return (parent_rate * SDM_DEN) / divisor; + return mul_u64_u32_div(parent_rate, SDM_DEN, divisor); } static void params_from_rate(unsigned long requested_rate,