From patchwork Thu Jun 29 10:18:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 9816329 X-Patchwork-Delegate: geert@linux-m68k.org 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 EC1E86020A for ; Thu, 29 Jun 2017 10:19:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE8A1285D9 for ; Thu, 29 Jun 2017 10:19:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D218B2869C; Thu, 29 Jun 2017 10:19:32 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 4FF8B285D9 for ; Thu, 29 Jun 2017 10:19:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751974AbdF2KTb (ORCPT ); Thu, 29 Jun 2017 06:19:31 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:36243 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751936AbdF2KTa (ORCPT ); Thu, 29 Jun 2017 06:19:30 -0400 Received: by mail-wm0-f66.google.com with SMTP id y5so1631747wmh.3; Thu, 29 Jun 2017 03:19:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=zlbURuMm0/aBxF0ZMXWng5vpAW4i2nSbht3/u2BZxvo=; b=A3KLtYckzbQEgEF7rIHf7yPSYRAbgIWQvDqgjWAtTd30Cj/MVAu8Uv6Dj2bgu1oEcQ G8FvCy4RqdNbKpgo8vANaRFtV3LV61gE+0n1PG5iN5cptxuoTIIEfKSRgNN6iRPDc7aE wBMK+7eZq4WgaBJ3mJRgHm66sxHMFceXjjVM6ob074pokDcwrt+EHwG1dUwRlFkZqR8a VhDPw0RcQ6qVtkh6y5WxrwRgyX8cYm37zISycogXaRblulnIINXp73uMGjHzAVo9vNOQ yYvuaBgZBM1bmDM8eoRL7MEvxhdTUCCwbGn91PjU6d/bO3hcOnpbH9reBJM27sCNoXgS jelw== 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; bh=zlbURuMm0/aBxF0ZMXWng5vpAW4i2nSbht3/u2BZxvo=; b=TVtRNAdUGjM97KB6b4ymp9mv0dMbplHesTEZ5FWjPebUGazXUili1p99AbU/6VV+/c TU61XRN7Il41g3hw9lpXscnkkckyUDlg9HgLuvuvsjDOPbQJKtoR+RtFF0XN0Y9wVfG4 WrH/v7TOL01HMZM9JZH5qDc5SQYJuHSbqEE9tCTVrWLRNy6vLB40p9yp5KG8I6x99OJy bQsvm5TidL18YiPODzH/JNhVtWwSvdWOgxavnqoqmsW5vwe96fR2SZcwH+ZY9Ps8pPbs b6cpevXIGWIJlM/sGXTX1396cQKTd44FhlDQLitwSZkV1v6Xfsa6Ovs54TJi008qwvrB +2Bg== X-Gm-Message-State: AKS2vOxNVymQdINHI74fh3Y7+PEsXXSAfQEw6QydqUDnDcYhadI4kuRq M7V6nK4JppGLRhxm7UY= X-Received: by 10.28.168.10 with SMTP id r10mr7931485wme.36.1498731568635; Thu, 29 Jun 2017 03:19:28 -0700 (PDT) Received: from chi.lan (cst-prg-169-255.cust.vodafone.cz. [46.135.169.255]) by smtp.gmail.com with ESMTPSA id t74sm7623653wmt.19.2017.06.29.03.19.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Jun 2017 03:19:27 -0700 (PDT) From: Marek Vasut To: linux-clk@vger.kernel.org Cc: Marek Vasut , Stephen Boyd , Alexey Firago , Michael Turquette , Laurent Pinchart , linux-renesas-soc@vger.kernel.org Subject: [PATCH 1/8] clk: vc5: Prevent division by zero on unconfigured outputs Date: Thu, 29 Jun 2017 12:18:44 +0200 Message-Id: <20170629101851.23972-1-marek.vasut@gmail.com> X-Mailer: git-send-email 2.11.0 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Marek Vasut In case the initial values of the FOD registers are not configured in the OTP or by the bootloader, it is possible that the FOD registers will contain zeroes. The code in vc5_fod_recalc_rate() immediately feeds the FOD divider value obtained from the FOD registers into the div64_u64() and if the FOD divider value is zero, triggers division by zero exception. Check if the FOD divider value is zero and return the frequency of the FOD output as 0 Hz if it is so. This prevents the division by zero exception. Signed-off-by: Marek Vasut Cc: Stephen Boyd Cc: Alexey Firago Cc: Michael Turquette Cc: Laurent Pinchart Cc: linux-renesas-soc@vger.kernel.org Tested-by: Laurent Pinchart --- drivers/clk/clk-versaclock5.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/clk/clk-versaclock5.c b/drivers/clk/clk-versaclock5.c index ea7d552a2f2b..60bf4afb51bd 100644 --- a/drivers/clk/clk-versaclock5.c +++ b/drivers/clk/clk-versaclock5.c @@ -426,6 +426,10 @@ static unsigned long vc5_fod_recalc_rate(struct clk_hw *hw, div_frc = (od_frc[0] << 22) | (od_frc[1] << 14) | (od_frc[2] << 6) | (od_frc[3] >> 2); + /* Avoid division by zero if the output is not configured. */ + if ((div_int == 0) && (div_frc == 0)) + return 0; + /* The PLL divider has 12 integer bits and 30 fractional bits */ return div64_u64((u64)f_in << 24ULL, ((u64)div_int << 24ULL) + div_frc); }