]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ASoC: pcm512x: Fix divide by zero issue
authorHoward Mitchell <hm@hmbedded.co.uk>
Fri, 20 Mar 2015 21:13:45 +0000 (21:13 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 6 May 2015 20:03:56 +0000 (22:03 +0200)
commit f073faa73626f41db7050a69edd5074c53ce6d6c upstream.

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>
Signed-off-by: Mark Brown <broonie@sirena.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
sound/soc/codecs/pcm512x.c

index b48624cf995fb8cf52ed75913b7b4c3ac93a26ff..8c09e3ffdcaa5c5944d7e31e633c2a1f2c691763 100644 (file)
@@ -576,8 +576,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);