aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@s-opensource.com>2017-11-01 17:06:03 -0400
committerMauro Carvalho Chehab <mchehab@s-opensource.com>2017-12-11 13:04:54 -0500
commitf303810cf189144a613a7efa991816655e6467ea (patch)
tree52e5f65350e6dbfa322979b7b8e6f0ef6e390136
parentmedia: mb86a16: be more resilient if I2C fails on sync (diff)
downloadlinux-dev-f303810cf189144a613a7efa991816655e6467ea.tar.xz
linux-dev-f303810cf189144a613a7efa991816655e6467ea.zip
media: mb86a16: avoid division by zero
As warned by smatch: drivers/media/dvb-frontends/mb86a16.c:1690 mb86a16_read_ber() error: uninitialized symbol 'timer'. drivers/media/dvb-frontends/mb86a16.c:1706 mb86a16_read_ber() error: uninitialized symbol 'timer'. There is a potential risk of doing a division by zero if timer is not handled well. Enforce it by setting a bit mask for the values used to select the timer. It should be noticed that I don't have mb86a16 datasheet. So, the bitmask was guessed based on the existing checks for the field. At worse case scenario, it will just show a badly calculated bit error rate, but it won't crash. While here, optimize the logic to prevent uneeded tests. Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
-rw-r--r--drivers/media/dvb-frontends/mb86a16.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/drivers/media/dvb-frontends/mb86a16.c b/drivers/media/dvb-frontends/mb86a16.c
index f1aad52094c3..5d2bb76bc07a 100644
--- a/drivers/media/dvb-frontends/mb86a16.c
+++ b/drivers/media/dvb-frontends/mb86a16.c
@@ -1677,15 +1677,15 @@ static int mb86a16_read_ber(struct dvb_frontend *fe, u32 *ber)
* the deinterleaver output.
* monitored BER is expressed as a 20 bit output in total
*/
- ber_rst = ber_mon >> 3;
+ ber_rst = (ber_mon >> 3) & 0x03;
*ber = (((ber_msb << 8) | ber_mid) << 8) | ber_lsb;
if (ber_rst == 0)
timer = 12500000;
- if (ber_rst == 1)
+ else if (ber_rst == 1)
timer = 25000000;
- if (ber_rst == 2)
+ else if (ber_rst == 2)
timer = 50000000;
- if (ber_rst == 3)
+ else /* ber_rst == 3 */
timer = 100000000;
*ber /= timer;
@@ -1697,11 +1697,11 @@ static int mb86a16_read_ber(struct dvb_frontend *fe, u32 *ber)
* QPSK demodulator output.
* monitored BER is expressed as a 24 bit output in total
*/
- ber_tim = ber_mon >> 1;
+ ber_tim = (ber_mon >> 1) & 0x01;
*ber = (((ber_msb << 8) | ber_mid) << 8) | ber_lsb;
if (ber_tim == 0)
timer = 16;
- if (ber_tim == 1)
+ else /* ber_tim == 1 */
timer = 24;
*ber /= 2 ^ timer;