ASoC: fsl_spdif: Fix integer overflow when calculating divisors
authorAnssi Hannula <anssi.hannula@iki.fi>
Mon, 9 Jun 2014 16:16:43 +0000 (19:16 +0300)
committerMark Brown <broonie@linaro.org>
Mon, 9 Jun 2014 20:00:42 +0000 (21:00 +0100)
The calculation code does
u64 = (u32 - u32) * 100000;

The 64 bits are of no help here as the type is casted only after the
multiplication, and therefore the result may overflow, possibly causing
inoptimal or wrong clock setup in an unfortunate case (the maximum
result value of the first substraction is currently 47999).

Fix the code to cast before multiplication.

Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
Acked-by: Nicolin Chen <Guangyu.Chen@freescale.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
sound/soc/fsl/fsl_spdif.c

index 9ea2dd471172cc4ab6c1be192f4ed70ea6d185d7..d7a60614dd211ce4934b4d04e5bf5a8f214a51af 100644 (file)
@@ -1076,7 +1076,7 @@ static u32 fsl_spdif_txclk_caldiv(struct fsl_spdif_priv *spdif_priv,
                                goto out;
                        } else if (arate / rate[index] == 1) {
                                /* A little bigger than expect */
-                               sub = (arate - rate[index]) * 100000;
+                               sub = (u64)(arate - rate[index]) * 100000;
                                do_div(sub, rate[index]);
                                if (sub >= savesub)
                                        continue;
@@ -1086,7 +1086,7 @@ static u32 fsl_spdif_txclk_caldiv(struct fsl_spdif_priv *spdif_priv,
                                spdif_priv->txrate[index] = arate;
                        } else if (rate[index] / arate == 1) {
                                /* A little smaller than expect */
-                               sub = (rate[index] - arate) * 100000;
+                               sub = (u64)(rate[index] - arate) * 100000;
                                do_div(sub, rate[index]);
                                if (sub >= savesub)
                                        continue;
This page took 0.028343 seconds and 5 git commands to generate.