aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnssi Hannula <anssi.hannula@iki.fi>2014-06-09 12:16:43 -0400
committerMark Brown <broonie@linaro.org>2014-06-09 16:00:42 -0400
commitc89c7e94bb7d89b39471c79034e3ba1b25d817f5 (patch)
tree66d54740aadc7a1baf67aba55c843748bf2f6ed8
parente9b383dc940f4cba6876887ecb47df3082ec925e (diff)
ASoC: fsl_spdif: Fix integer overflow when calculating divisors
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>
-rw-r--r--sound/soc/fsl/fsl_spdif.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/sound/soc/fsl/fsl_spdif.c b/sound/soc/fsl/fsl_spdif.c
index 9ea2dd471172..d7a60614dd21 100644
--- a/sound/soc/fsl/fsl_spdif.c
+++ b/sound/soc/fsl/fsl_spdif.c
@@ -1076,7 +1076,7 @@ static u32 fsl_spdif_txclk_caldiv(struct fsl_spdif_priv *spdif_priv,
1076 goto out; 1076 goto out;
1077 } else if (arate / rate[index] == 1) { 1077 } else if (arate / rate[index] == 1) {
1078 /* A little bigger than expect */ 1078 /* A little bigger than expect */
1079 sub = (arate - rate[index]) * 100000; 1079 sub = (u64)(arate - rate[index]) * 100000;
1080 do_div(sub, rate[index]); 1080 do_div(sub, rate[index]);
1081 if (sub >= savesub) 1081 if (sub >= savesub)
1082 continue; 1082 continue;
@@ -1086,7 +1086,7 @@ static u32 fsl_spdif_txclk_caldiv(struct fsl_spdif_priv *spdif_priv,
1086 spdif_priv->txrate[index] = arate; 1086 spdif_priv->txrate[index] = arate;
1087 } else if (rate[index] / arate == 1) { 1087 } else if (rate[index] / arate == 1) {
1088 /* A little smaller than expect */ 1088 /* A little smaller than expect */
1089 sub = (rate[index] - arate) * 100000; 1089 sub = (u64)(rate[index] - arate) * 100000;
1090 do_div(sub, rate[index]); 1090 do_div(sub, rate[index]);
1091 if (sub >= savesub) 1091 if (sub >= savesub)
1092 continue; 1092 continue;