All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drxd: fix divide error
@ 2011-08-26 15:59 Edward Sheldrake
  0 siblings, 0 replies; only message in thread
From: Edward Sheldrake @ 2011-08-26 15:59 UTC (permalink / raw)
  To: linux-media

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>
---
 drivers/media/dvb/frontends/drxd_hard.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/media/dvb/frontends/drxd_hard.c b/drivers/media/dvb/frontends/drxd_hard.c
index 2238bf0..bcad01c 100644
--- a/drivers/media/dvb/frontends/drxd_hard.c
+++ b/drivers/media/dvb/frontends/drxd_hard.c
@@ -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;
 		}
-- 
1.7.6


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2011-08-26 15:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-26 15:59 [PATCH] drxd: fix divide error Edward Sheldrake

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.