Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: dvb-frontends: tda10048: Fix integer overflow

state->xtal_hz can be up to 16M, so it can overflow a 32 bit integer
when multiplied by pll_mfactor.

Create a new 64 bit variable to hold the calculations.

Link: https://lore.kernel.org/linux-media/20240429-fix-cocci-v3-25-3c4865f5a4b0@chromium.org
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>

authored by

Ricardo Ribalda and committed by
Mauro Carvalho Chehab
1aa1329a d7773138

+6 -3
+6 -3
drivers/media/dvb-frontends/tda10048.c
··· 410 410 struct tda10048_config *config = &state->config; 411 411 int i; 412 412 u32 if_freq_khz; 413 + u64 sample_freq; 413 414 414 415 dprintk(1, "%s(bw = %d)\n", __func__, bw); 415 416 ··· 452 451 dprintk(1, "- pll_pfactor = %d\n", state->pll_pfactor); 453 452 454 453 /* Calculate the sample frequency */ 455 - state->sample_freq = state->xtal_hz * (state->pll_mfactor + 45); 456 - state->sample_freq /= (state->pll_nfactor + 1); 457 - state->sample_freq /= (state->pll_pfactor + 4); 454 + sample_freq = state->xtal_hz; 455 + sample_freq *= state->pll_mfactor + 45; 456 + do_div(sample_freq, state->pll_nfactor + 1); 457 + do_div(sample_freq, state->pll_pfactor + 4); 458 + state->sample_freq = sample_freq; 458 459 dprintk(1, "- sample_freq = %d\n", state->sample_freq); 459 460 460 461 /* Update the I/F */