From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751939AbbCVVQk (ORCPT ); Sun, 22 Mar 2015 17:16:40 -0400 Received: from axentia.se ([87.96.186.132]:26918 "EHLO EMAIL.axentia.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751813AbbCVVQj convert rfc822-to-8bit (ORCPT ); Sun, 22 Mar 2015 17:16:39 -0400 From: Peter Rosin To: Howard Mitchell , "broonie@kernel.org" CC: "tiwai@suse.de" , "lgirdwood@gmail.com" , "perex@perex.cz" , "corbet@lwn.net" , "alsa-devel@alsa-project.org" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH] ASoC:pcm512x: Fix divide by zero issue. Thread-Topic: [PATCH] ASoC:pcm512x: Fix divide by zero issue. Thread-Index: AQHQY1L/UipEqwMokEujYMWjSFGiSJ0pA20w Date: Sun, 22 Mar 2015 21:16:10 +0000 Message-ID: References: <1426886025-10731-1-git-send-email-hm@hmbedded.co.uk> In-Reply-To: <1426886025-10731-1-git-send-email-hm@hmbedded.co.uk> Accept-Language: en-US, sv-SE Content-Language: sv-SE X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [192.168.2.1] x-gfi-smtp-submission: 1 x-gfi-smtp-hellodomain: EMAIL.axentia.se x-gfi-smtp-remoteip: 192.168.2.5 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Howard Mitchell wrote; > 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. Yep, the old code is plain broken and never actually ran, we have been using 16MHz pllin_rate, and I apparently never hit this code path. > Signed-off-by: Howard Mitchell Acked-by: Peter Rosin Cheers, Peter > --- > 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); > > -- > 1.7.9.5