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: 9657833 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 9C22960353 for ; Sat, 1 Apr 2017 13:03:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7BF1627B2F for ; Sat, 1 Apr 2017 13:03:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 70C5E28617; Sat, 1 Apr 2017 13:03:03 +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 07F9527B2F for ; Sat, 1 Apr 2017 13:03:03 +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=EbDK4sicRgf8ijeQORunr9b6oA4tsc3SYmBOnNyWhJk=; b=eBA8fqnBJg8eu8mr+Y/J9ugOjE qxvMumHuYEMc6EAqgqD2rjBGDONv6NOWvN9NmBsERSqUICMg5i2y8PPbkkJGvhwtMi6R1izvf0oON FUxKWAmr2JIXaJotPq8pey9Ux6LJX98+W6SHZz1yDGhRaul8OflkKMfV1FnZDV4VLBODQq9fZntwD tRTLDoY+ROgxDCxTxcpHiuzmaDjfWlB3/GqlwE/im4JDJSgW7Tsw+NjfWfyfmtKMYGVLIktgltJdU BlkRZ9o3jq+kSebCdqWw1zYagIO9JpbJaMRXSMo+wKwabTG9aAy8WDtUZ5aW0aBFydYUJcd36Mhgn 3TSVao3w==; 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 1cuIgA-00054r-WD; Sat, 01 Apr 2017 13:02:55 +0000 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cuIg6-000539-Lq; Sat, 01 Apr 2017 13:02:52 +0000 Received: by mail-wr0-x242.google.com with SMTP id k6so22631708wre.3; Sat, 01 Apr 2017 06:02:31 -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=Nym/AAaznIQkL8w0Cuoj3bFna9EVaoNlR1flMNmoEiRXO1Ns0kvdKsy6aBURtRfX8R yIwvH1CmN6HABLU+62J8dbjt4IjjzxB7dE0fu1SKzQnEUiQePHBrhy9LeGbTqtwlmhhe ngt9VkxADEuzeKD8W0HjYliMP/7xY0BKQG3ezD6EIzidL5kX3lDy185ZpwYrZ4Anv6hW AvGjtzLoomxB8ZtDSz+17mpqFTwoCwgeT2vHcJhO9vnuo4/vfVakeWTaSm+qHo6NhWvt qzyGSbzm23C65hniprTo9pY5ZqfIK2ptrfpAFFdwYaz/2+2kRugY49htesywpSGZK6wi FiMg== X-Gm-Message-State: AFeK/H13AqzTFg1ErtHqVNlU2b10ej/xGVRXI8dLAINJncrGFTDQxD8eQGvSsGwiE15tvQ== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170401_060250_890400_E13717AC X-CRM114-Status: GOOD ( 11.60 ) 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 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,