Skip to content

Commit 1aa1329

Browse files
ribaldamchehab
authored andcommitted
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/[email protected] Reported-by: Dan Carpenter <[email protected]> Signed-off-by: Ricardo Ribalda <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent d777313 commit 1aa1329

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/media/dvb-frontends/tda10048.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ static int tda10048_set_if(struct dvb_frontend *fe, u32 bw)
410410
struct tda10048_config *config = &state->config;
411411
int i;
412412
u32 if_freq_khz;
413+
u64 sample_freq;
413414

414415
dprintk(1, "%s(bw = %d)\n", __func__, bw);
415416

@@ -451,9 +452,11 @@ static int tda10048_set_if(struct dvb_frontend *fe, u32 bw)
451452
dprintk(1, "- pll_pfactor = %d\n", state->pll_pfactor);
452453

453454
/* Calculate the sample frequency */
454-
state->sample_freq = state->xtal_hz * (state->pll_mfactor + 45);
455-
state->sample_freq /= (state->pll_nfactor + 1);
456-
state->sample_freq /= (state->pll_pfactor + 4);
455+
sample_freq = state->xtal_hz;
456+
sample_freq *= state->pll_mfactor + 45;
457+
do_div(sample_freq, state->pll_nfactor + 1);
458+
do_div(sample_freq, state->pll_pfactor + 4);
459+
state->sample_freq = sample_freq;
457460
dprintk(1, "- sample_freq = %d\n", state->sample_freq);
458461

459462
/* Update the I/F */

0 commit comments

Comments
 (0)