From patchwork Fri Mar 20 21:13:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Howard Mitchell X-Patchwork-Id: 6061001 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BF515BF90F for ; Fri, 20 Mar 2015 21:15:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 084A620519 for ; Fri, 20 Mar 2015 21:15:40 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 1AF7620483 for ; Fri, 20 Mar 2015 21:15:39 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id BE1F826573D; Fri, 20 Mar 2015 22:15:37 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NO_DNS_FOR_FROM, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 434D52650BC; Fri, 20 Mar 2015 22:15:29 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 5D6D22650DB; Fri, 20 Mar 2015 22:15:28 +0100 (CET) Received: from avasout02.plus.net (avasout02.plus.net [212.159.14.17]) by alsa0.perex.cz (Postfix) with ESMTP id 01503265071 for ; Fri, 20 Mar 2015 22:15:20 +0100 (CET) Received: from howard-VirtualBox.lan ([212.159.100.40]) by avasout02 with smtp id 5xFC1q0030sHRKG01xFKHF; Fri, 20 Mar 2015 21:15:20 +0000 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=IsmQcdPg c=1 sm=1 tr=0 a=VGUxJGZ/H8UixBFj6Q9CRg==:117 a=VGUxJGZ/H8UixBFj6Q9CRg==:17 a=0Bzu9jTXAAAA:8 a=eIRpCU4CAAAA:8 a=ixmt6SZPQnldqEYNvRAA:9 a=IXO3vdhQb4j3c8yR:21 a=_B-qOsasA85vUZrR:21 X-AUTH: oscars+hm@:2500 From: Howard Mitchell To: broonie@kernel.org, peda@axentia.se Date: Fri, 20 Mar 2015 21:13:45 +0000 Message-Id: <1426886025-10731-1-git-send-email-hm@hmbedded.co.uk> X-Mailer: git-send-email 1.7.9.5 Cc: alsa-devel@alsa-project.org, corbet@lwn.net, tiwai@suse.de, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, lgirdwood@gmail.com, Howard Mitchell Subject: [alsa-devel] [PATCH] ASoC:pcm512x: Fix divide by zero issue. X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP If den=1 and pllin_rate>20MHz then den and num are adjusted to 0 causing a divide by zero error a few lines further on. Therefore this patch correctly scales num and den such that pllin_rate/den < 20MHz as required in the device data sheet. Signed-off-by: Howard Mitchell Acked-by: Peter Rosin --- sound/soc/codecs/pcm512x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c index 5301c4a..8472099 100644 --- a/sound/soc/codecs/pcm512x.c +++ b/sound/soc/codecs/pcm512x.c @@ -713,8 +713,8 @@ static int pcm512x_find_pll_coeff(struct snd_soc_dai *dai, /* pllin_rate / P (or here, den) cannot be greater than 20 MHz */ if (pllin_rate / den > 20000000 && num < 8) { - num *= 20000000 / (pllin_rate / den); - den *= 20000000 / (pllin_rate / den); + num *= DIV_ROUND_UP(pllin_rate / den, 20000000); + den *= DIV_ROUND_UP(pllin_rate / den, 20000000); } dev_dbg(dev, "num / den = %lu / %lu\n", num, den);