* [PATCH] ASoC:pcm512x: Fix divide by zero issue.
@ 2015-03-20 21:13 Howard Mitchell
2015-03-22 16:19 ` Mark Brown
2015-03-22 21:16 ` Peter Rosin
0 siblings, 2 replies; 3+ messages in thread
From: Howard Mitchell @ 2015-03-20 21:13 UTC (permalink / raw)
To: broonie, peda
Cc: tiwai, lgirdwood, perex, corbet, alsa-devel, linux-doc,
linux-kernel, Howard Mitchell
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 <hm@hmbedded.co.uk>
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ASoC:pcm512x: Fix divide by zero issue.
2015-03-20 21:13 [PATCH] ASoC:pcm512x: Fix divide by zero issue Howard Mitchell
@ 2015-03-22 16:19 ` Mark Brown
2015-03-22 21:16 ` Peter Rosin
1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2015-03-22 16:19 UTC (permalink / raw)
To: Howard Mitchell
Cc: peda, tiwai, lgirdwood, perex, corbet, alsa-devel, linux-doc,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 332 bytes --]
On Fri, Mar 20, 2015 at 09:13:45PM +0000, 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.
Applied, thanks.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] ASoC:pcm512x: Fix divide by zero issue.
2015-03-20 21:13 [PATCH] ASoC:pcm512x: Fix divide by zero issue Howard Mitchell
2015-03-22 16:19 ` Mark Brown
@ 2015-03-22 21:16 ` Peter Rosin
1 sibling, 0 replies; 3+ messages in thread
From: Peter Rosin @ 2015-03-22 21:16 UTC (permalink / raw)
To: Howard Mitchell, broonie
Cc: tiwai, lgirdwood, perex, corbet, alsa-devel, linux-doc, linux-kernel
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 <hm@hmbedded.co.uk>
Acked-by: Peter Rosin <peda@axentia.se>
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-03-23 5:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-20 21:13 [PATCH] ASoC:pcm512x: Fix divide by zero issue Howard Mitchell
2015-03-22 16:19 ` Mark Brown
2015-03-22 21:16 ` Peter Rosin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.