[media] drxd: fix divide error
authorEdward Sheldrake <ejsheldrake@gmail.com>
Fri, 26 Aug 2011 15:59:30 +0000 (12:59 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Sun, 4 Sep 2011 14:17:11 +0000 (11:17 -0300)
Fix division by zero in drxd triggered by running "femon" before any DVB
tuning has been done (by "scandvb" or anything else).

Signed-off-by: Edward Sheldrake <ejsheldrake@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/dvb/frontends/drxd_hard.c

index 2238bf0be95936320feccbfc65f30c1503167e08..bcad01ca1a131a841da7dbf00cb1466fb2c51d91 100644 (file)
@@ -889,10 +889,15 @@ static int ReadIFAgc(struct drxd_state *state, u32 * pValue)
                        u32 R2 = state->if_agc_cfg.R2;
                        u32 R3 = state->if_agc_cfg.R3;
 
-                       u32 Vmax = (3300 * R2) / (R1 + R2);
-                       u32 Rpar = (R2 * R3) / (R3 + R2);
-                       u32 Vmin = (3300 * Rpar) / (R1 + Rpar);
-                       u32 Vout = Vmin + ((Vmax - Vmin) * Value) / 1024;
+                       u32 Vmax, Rpar, Vmin, Vout;
+
+                       if (R2 == 0 && (R1 == 0 || R3 == 0))
+                               return 0;
+
+                       Vmax = (3300 * R2) / (R1 + R2);
+                       Rpar = (R2 * R3) / (R3 + R2);
+                       Vmin = (3300 * Rpar) / (R1 + Rpar);
+                       Vout = Vmin + ((Vmax - Vmin) * Value) / 1024;
 
                        *pValue = Vout;
                }