Skip to content

Commit

Permalink
[media] si2165: avoid division by zero
Browse files Browse the repository at this point in the history
When si2165_init fails, the clk values in state are still at zero.
But the dvb-core ignores the return value of init will call tune
afterwards.
This will trigger a division by zero when tuning.
At least check for the variables to be non-zero before dividing.

This happened for a system with WinTV HVR-4400 PCIe-card after suspend-to-disk.
Do suspend-to-disk without accessing the DVB device before.
After wakeup try to tune.
si2165_init fails at checking the chip_mode and aborts.
Then si2165_set_if_freq_shift will fail with div-by-zero.

Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
  • Loading branch information
Matthias Schwarzott authored and Mauro Carvalho Chehab committed Sep 22, 2016
1 parent c0bf09d commit 2df9dda
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/media/dvb-frontends/si2165.c
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,9 @@ static int si2165_set_oversamp(struct si2165_state *state, u32 dvb_rate)
u64 oversamp;
u32 reg_value;

if (!dvb_rate)
return -EINVAL;

oversamp = si2165_get_fe_clk(state);
oversamp <<= 23;
do_div(oversamp, dvb_rate);
Expand All @@ -775,6 +778,9 @@ static int si2165_set_if_freq_shift(struct si2165_state *state)
return -EINVAL;
}

if (!fe_clk)
return -EINVAL;

fe->ops.tuner_ops.get_if_frequency(fe, &IF);
if_freq_shift = IF;
if_freq_shift <<= 29;
Expand Down

0 comments on commit 2df9dda

Please sign in to comment.