From patchwork Sat Apr 1 13:02:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 9657829 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 3F70A60353 for ; Sat, 1 Apr 2017 13:02:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2022A27B2F for ; Sat, 1 Apr 2017 13:02:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1507528481; 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 B84B527B2F for ; Sat, 1 Apr 2017 13:02:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751353AbdDANCc (ORCPT ); Sat, 1 Apr 2017 09:02:32 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:35588 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751124AbdDANCb (ORCPT ); Sat, 1 Apr 2017 09:02:31 -0400 Received: by mail-wr0-f196.google.com with SMTP id p52so23973374wrc.2 for ; Sat, 01 Apr 2017 06:02:30 -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=GZeHAkVJp4N+eqGrwvigcJZu7tZj85PKDiFBsLGu4nA=; b=kYlDoVz9G4rfhDt+qf+ibEK5FKtTet5YafLugZ/DOQROerVSJh4XgqJ0hbjbXBYHll 4U8imgQSTMIzLG4Gkdkie1xwwZP0k1tqjO7RLqAhOK5dzowR6CN2XW/eW5KKNnypDUE7 87s3EXrmquj60yzGguvMWX3w+PeO0kYT1krY0XQjtAQ/jpkmwb1NCR+yvsIAnEbSSrsp CS6puFewMY2OU3vCLhDLeXfpL1CBPEAU7kOzuwKYoI2MEgwOPOZ4zyoIEGYSumxgRSvv JrhzhBOmWrgVYrwh1OfSHjAlXqHQw34SJy0Px1kRh8GKX2yOXGOEOtDFh7OOCtYywEif JauQ== 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=GZeHAkVJp4N+eqGrwvigcJZu7tZj85PKDiFBsLGu4nA=; b=pSLCW8WMJgIv8WLByRKuUNYAL4kuU2UHGfGuU6e6DWY9OeZBfxEPHbsLStcIwOXZ7t LMI29fcgC6v1TIB8fKPmK0P2p/7lFpZkcFJjaPjnHYwzEZhdcDbP7eDM9nlNJpRm/nR4 fY2HkUJ7duE8s5dHDQDIamzHdT7z7HK+U5SPao44YiYvu0b7R2Mc4di+2Znnmf0Sq3BG vT+KEw6+x6fM4Bp0MqUri3f/s/lnz2h21KOlGG10nXHc/u3+Z3kxb0GGMAYL4Y7CVfml Vdqx6PG3amEyYTt4YMZp3qzWhOqWXpMo3dgR23xHdWLomCTWiki6RO/eAO4IlDs1Q2xO q98Q== X-Gm-Message-State: AFeK/H2qXplOB+Cin4GTKkpxugArcHSCB6VCBK3nM7NIxDuZfq4JtQw1gUK1qVy13+RQIw== X-Received: by 10.223.148.193 with SMTP id 59mr7274429wrr.135.1491051750070; Sat, 01 Apr 2017 06:02:30 -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.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Apr 2017 06:02:29 -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 1/2] clk: meson: mpll: fix division by zero in rate_from_params Date: Sat, 1 Apr 2017 15:02:24 +0200 Message-Id: <20170401130225.8811-2-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 According to the public datasheet all register bits in HHI_MPLL_CNTL7, HHI_MPLL_CNTL8 and HHI_MPLL_CNTL9 default to zero. On all GX SoCs these seem to be initialized by the bootloader to some default value. However, on my Meson8 board they are not initialized, leading to a division by zero in rate_from_params as the math is: (parent_rate * SDM_DEN) / ((SDM_DEN * 0) + 0) Although the rate_from_params function was only introduced recently the original bug has been there for much longer. It was only exposed recently when the MPLL clocks were added to the Meson8b clock driver. Fixes: 1c50da4f27 ("clk: meson: add mpll support") Signed-off-by: Martin Blumenstingl --- drivers/clk/meson/clk-mpll.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/clk/meson/clk-mpll.c b/drivers/clk/meson/clk-mpll.c index 540dabe5adad..551aa2a5b291 100644 --- a/drivers/clk/meson/clk-mpll.c +++ b/drivers/clk/meson/clk-mpll.c @@ -76,7 +76,12 @@ static unsigned long rate_from_params(unsigned long parent_rate, unsigned long sdm, unsigned long n2) { - return (parent_rate * SDM_DEN) / ((SDM_DEN * n2) + sdm); + unsigned long divisor = (SDM_DEN * n2) + sdm; + + if (divisor == 0) + return 0; + else + return (parent_rate * SDM_DEN) / divisor; } static void params_from_rate(unsigned long requested_rate,