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: 9657837 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 F1A4860353 for ; Sat, 1 Apr 2017 13:03:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1E9527B2F for ; Sat, 1 Apr 2017 13:03:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6BD228481; Sat, 1 Apr 2017 13:03:20 +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_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM 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 7B5F127B2F for ; Sat, 1 Apr 2017 13:03: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=SyUE1geLWxaPT90Gwxn+JhNt2xCWzRwLI8VF8q1jEm4=; b=NKqo7pIs9QQGh9h7nyUSVbes9K 3YSq4tqB0MMrexFsQknNunVJDbjpraruYH+EqqgQeDDrSmapfHqS8R1a0QLUvncRKDkXS5BwZSNtt 9+yJWeXHdnyZuiMSJvEw1hnG2OosEMh/CiulNuWA86ir84jkjZ9nj0uWcUTkzK3TZzUDOrLPmBjXY Wy7v4+V6R86k0BXNPEo1yJKabsMxwdrtdMSJBxPye7azmqDagY3/0sVFmGpm26FNJID/mc6W8dJae mzY/3UzUNhsbQJsQ/9uKksI0IS8mOhfRmwZnnLvgdhHgGUbpLiZU1UhAkJyH46bY+Dt9EvniTEG/m VCNTENoQ==; 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 1cuIgZ-0005cY-Lg; Sat, 01 Apr 2017 13:03:19 +0000 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cuIg8-00053J-Vj; Sat, 01 Apr 2017 13:02:55 +0000 Received: by mail-wr0-x243.google.com with SMTP id w43so23902915wrb.1; 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=qjfaxqXUjaLdsvna8HjO2YkVtXGxn7f2i1I8Tg/etcUqZsIr3JeExIc6YoJv6uOcrg elgbvZQixUz0KKaHJNLCF6CJJ7Ziw8Xdp9T9oPqXOipcvctcaqabwar5pKhWhtew6ocg Wj6SuHm1rg8JrVxTbAV0IhDMAdxVxM2KTQ2RQMPKpw8B+00aBCx+6WaJSoXBCuuL1jQQ Yz/97Gq06d7YhzlbM35JiZf38Io2DpB2qHTfgJKjK6+7QbfyAaj3t7GdQtHNgzahvg6r UBfn35WgHqN1C3uBRQHvuVJHqsm3cuzeeAwAqtQMBfywo7YuGBMkYk3/ajsBN7fjUeq1 r9rA== X-Gm-Message-State: AFeK/H3BFTJnhmCO/vRgGkgj68eO+kd+2rtSErhJZcCVX8hP75/S2ImKKh5AZpfVTqCS5g== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170401_060253_177727_47C06643 X-CRM114-Status: GOOD ( 11.79 ) 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, khilman@baylibre.com, Martin Blumenstingl , linux-arm-kernel@lists.infradead.org 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 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,