ASoC: cx2072x: fix integer overflow on unsigned int multiply

In the case where frac_div larger than 96 the result of an unsigned
multiplication overflows an unsigned int.  For example, this can
happen when the sample_rate is 192000 and pll_input is 122.  Fix
this by casing the first term of the mutiply to a u64. Also remove
the extraneous parentheses around the expression.

Addresses-Coverity: ("Unintentional integer overflow")
Fixes: a497a43637 ("ASoC: Add support for Conexant CX2072X CODEC")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Colin Ian King 2019-05-24 23:25:51 +01:00 committed by Mark Brown
parent eb5b12843b
commit be0461048b
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
1 changed files with 1 additions and 1 deletions

View File

@ -627,7 +627,7 @@ static int cx2072x_config_pll(struct cx2072x_priv *cx2072x)
if (frac_div) { if (frac_div) {
frac_div *= 1000; frac_div *= 1000;
frac_div /= pll_input; frac_div /= pll_input;
frac_num = ((4000 + frac_div) * ((1 << 20) - 4)); frac_num = (u64)(4000 + frac_div) * ((1 << 20) - 4);
do_div(frac_num, 7); do_div(frac_num, 7);
frac = ((u32)frac_num + 499) / 1000; frac = ((u32)frac_num + 499) / 1000;
} }