From patchwork Thu Dec 27 00:14:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Prisk X-Patchwork-Id: 1911641 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 122AEDF230 for ; Thu, 27 Dec 2012 00:18:27 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1To17b-00028i-9p; Thu, 27 Dec 2012 00:14:51 +0000 Received: from server.prisktech.co.nz ([115.188.14.127]) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1To17W-00027S-CH for linux-arm-kernel@lists.infradead.org; Thu, 27 Dec 2012 00:14:47 +0000 Received: from localhost.localdomain (unknown [192.168.0.102]) by server.prisktech.co.nz (Postfix) with ESMTP id A1107FC0A62; Thu, 27 Dec 2012 13:14:45 +1300 (NZDT) From: Tony Prisk To: Mike Turquette Subject: [PATCH 3/3] clk: vt8500: Fix division-by-0 when requested rate=0 Date: Thu, 27 Dec 2012 13:14:31 +1300 Message-Id: <1356567272-3420-4-git-send-email-linux@prisktech.co.nz> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1356567272-3420-1-git-send-email-linux@prisktech.co.nz> References: <1356567272-3420-1-git-send-email-linux@prisktech.co.nz> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121226_191446_739548_E474BAA6 X-CRM114-Status: GOOD ( 12.95 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Tony Prisk , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org A request to vt8500_dclk_(round_rate/set_rate) with rate=0 results in a division-by-0 in the kernel. Signed-off-by: Tony Prisk --- drivers/clk/clk-vt8500.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/clk/clk-vt8500.c b/drivers/clk/clk-vt8500.c index 3306c2b..db7d41f 100644 --- a/drivers/clk/clk-vt8500.c +++ b/drivers/clk/clk-vt8500.c @@ -121,7 +121,12 @@ static long vt8500_dclk_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *prate) { struct clk_device *cdev = to_clk_device(hw); - u32 divisor = *prate / rate; + u32 divisor; + + if (rate == 0) + return 0; + + divisor = *prate / rate; /* If prate / rate would be decimal, incr the divisor */ if (rate * divisor < *prate) @@ -142,9 +147,14 @@ static int vt8500_dclk_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct clk_device *cdev = to_clk_device(hw); - u32 divisor = parent_rate / rate; + u32 divisor; unsigned long flags = 0; + if (rate == 0) + return 0; + + divisor = parent_rate / rate; + /* If prate / rate would be decimal, incr the divisor */ if (rate * divisor < *prate) divisor++;