From patchwork Sat Jul 1 20:04:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 9820953 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 2DC0D602CC for ; Sat, 1 Jul 2017 20:05:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20996269E2 for ; Sat, 1 Jul 2017 20:05:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1540B2845D; Sat, 1 Jul 2017 20:05:38 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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 782F22844B for ; Sat, 1 Jul 2017 20:05:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751944AbdGAUFe (ORCPT ); Sat, 1 Jul 2017 16:05:34 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:35766 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751911AbdGAUFd (ORCPT ); Sat, 1 Jul 2017 16:05:33 -0400 Received: by mail-wm0-f65.google.com with SMTP id u23so13598377wma.2; Sat, 01 Jul 2017 13:05:32 -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=kuWZ+kWs3UOLfRHioUAywfz1wS+rQUlh4Un4M8IcQjM=; b=PcDIhbe29qOTS9cWDfAv6oSxbFOT3VVX8hEgYqA7jp1rf3LFyJyc26+Iqjd7hizHoZ FlmSRV3K38XOh0qZTha6QTKktWE08HFucd/tDMjOSB67DYYPNcVth0BMdPXX1flVHO4z YHX+HYeROFBvKhVexiHW3o2sQmTF1ic/c1ONvmNbpk4PQoaVy1zDDEFGaNCeBHsKA61U M6Ct6HT8SRE4NivNh5xBaVZL27PUpJ965ytyrRy3pjAlyj+Nx/DVw3/Iq18YACLSxKzs waQfiWSFQEPVY+nNxv1wFdB6PcQJGsyYqEzLqjuqFzzzCoZqJXptONU/UhuCrzNaGuCd eBZQ== 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=kuWZ+kWs3UOLfRHioUAywfz1wS+rQUlh4Un4M8IcQjM=; b=g8tiO+J5BgPh3BZ9Qi9VlfW/YUIQVy03IpfUxg+oJ7cXdlkWw27bjhjEUqte9adYlp 7uCRjnlwPTWEWwnEdy7s06RCkfzhn9Q/z2ehvdlA3XYjCZ54voKD6ubKLmasKEKqtZcY ctGLmk/Dpmy6M8cLV5QO1jtP6yh9QCOBsSVqEGhdM/j9fFvwmJgk6bVsNqwJPZNo993u 4JvloODrUPvZRcg1qh4qudh+/03jWShyniGtRhYZU4K246XVmSbXqe+hxO6cRkePlAnb MA67OAnV4vA0m30R9au+fSVKnWJHlowSIQj6ihhVsYf9sUIfRMID4qCmh4ruOHUU/bLG cL4g== X-Gm-Message-State: AKS2vOyJTIGiqRcRUqPVIJzAfQZumJ/dqAKeVLee1w62IozSRFBkr8yG H8VsScsInf9n3inRa9Y= X-Received: by 10.28.234.193 with SMTP id g62mr20590491wmi.24.1498939531670; Sat, 01 Jul 2017 13:05:31 -0700 (PDT) Received: from kurokawa.lan (ip-86-49-107-50.net.upcbroadband.cz. [86.49.107.50]) by smtp.gmail.com with ESMTPSA id s30sm18150137wrc.13.2017.07.01.13.05.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Jul 2017 13:05:30 -0700 (PDT) From: Marek Vasut X-Google-Original-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: Sat, 1 Jul 2017 22:04:51 +0200 Message-Id: <20170701200459.11505-1-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.11.0 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 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 on Salvator-XS with the display LVDS output. Reviewed-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); }