From patchwork Sun Jul 9 13:28:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 9831783 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 EFDE4602BD for ; Sun, 9 Jul 2017 13:28:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE9B027FB7 for ; Sun, 9 Jul 2017 13:28:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D31EE283D8; Sun, 9 Jul 2017 13:28:40 +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 399A127FB7 for ; Sun, 9 Jul 2017 13:28:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752139AbdGIN2i (ORCPT ); Sun, 9 Jul 2017 09:28:38 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:36182 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750927AbdGIN2h (ORCPT ); Sun, 9 Jul 2017 09:28:37 -0400 Received: by mail-wr0-f193.google.com with SMTP id 77so18765713wrb.3; Sun, 09 Jul 2017 06:28:37 -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=yKW4fgnW8CqGAzHPs8oqXb3+OAtCVDQ2YV7jP4YMGAs=; b=vHtOvg7H9qpi88lzQRuaC0poHyMl5sC9fsotZsg1/QozjuPzBRNOcAK9PMROBUnjjq 5T3v4zoPLn3uWrSvOxPnb/v4X82qte9Eu7AGQhfOOxqR430UAa8mLzztHMBa3m3bJBw2 5VOdy9t5CTIGMeeVz5YpUILP3I1x6AF5SpamfOTxtpjPONF+cI7NUnOJr1NTtMUeTYcH pPE7OIJ1R3f87CQOvWWoV77FQAovvINqWoCJ0xRMgoz/dQzoZsP5LaZ93+jX6ByzFuJK majLcaqgFdC39dJjVkx0s/XwVMn/G0C5VWgq35JFoIjZ06SwUyctATS1eM/uAbtIqd1e byEg== 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=yKW4fgnW8CqGAzHPs8oqXb3+OAtCVDQ2YV7jP4YMGAs=; b=VaFFzoJlLeZenGYqdLYhr+wsL02cYsxHKqumqkCy3HlBGsDkPo6c+6wTkdMXs+BaGA krKMYczVtaHFcwItb3FJalLG3mvy/TxZuf+YaBWVw/YIbzyP5VHfIF9McxQC9lpSbJq7 lVsfb3FvbiMNYFyz3LfCrR0NVD14sWaRvkUE+KmO0qElDCkf6YGQjGpOZ+DXYv96UUjn +j9HACcmEpZ4jNE1sa8FhIBzAOU21Zts6lpzq7m5OsmN/Jplv0WcVqT5ksojCNoyJu52 GllPTCHCgTM6ds843qBKQXfnAZhzf5kzVHxh6BeTkxwHbeOR0nSoLhscnJrnLKQ8k6lj iz6Q== X-Gm-Message-State: AIVw110jRJQKT9TJu/WBknWIcK6H42o03mpNxWLtSw8B6xxZ0a5FkkV6 ETmnC6IOkMv3wzzvNzQ= X-Received: by 10.223.134.16 with SMTP id 16mr5317730wrv.83.1499606915882; Sun, 09 Jul 2017 06:28:35 -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 o197sm8482585wmd.9.2017.07.09.06.28.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Jul 2017 06:28:35 -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 V3 1/8] clk: vc5: Prevent division by zero on unconfigured outputs Date: Sun, 9 Jul 2017 15:28:07 +0200 Message-Id: <20170709132814.2339-1-marek.vasut+renesas@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 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. --- V2: None V3: None --- 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); }