From patchwork Fri Aug 26 15:59:30 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Sheldrake X-Patchwork-Id: 1102552 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p7QFxhSo016183 for ; Fri, 26 Aug 2011 15:59:43 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754572Ab1HZP7m (ORCPT ); Fri, 26 Aug 2011 11:59:42 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]:48183 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754556Ab1HZP7l (ORCPT ); Fri, 26 Aug 2011 11:59:41 -0400 Received: by wwf5 with SMTP id 5so3652488wwf.1 for ; Fri, 26 Aug 2011 08:59:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=date:from:to:subject:message-id:user-agent:mime-version :content-type; bh=VWVY8ShBe6Ypu8rYPX8w+ZVpJHc/wJhKNDa6LkK7974=; b=OzeZ0rF8ZfAqUYMNeQQBB+2xtn7AhwY7JOWFUHZx1cZkfqo/K00DZ7ZdzDlgHdnSdA EEGYbrDeGgT9/AdTlFdWsNAPyNSjEXjqNJLsPeHAsLhsQbBtFSjB18slQDj7T2M+B7nC Alo2D7U8SwyqoZXOW6QhKboap2DdyanGFBf1c= Received: by 10.216.137.22 with SMTP id x22mr1032555wei.88.1314374380418; Fri, 26 Aug 2011 08:59:40 -0700 (PDT) Received: from [192.168.0.101] ([87.115.185.74]) by mx.google.com with ESMTPS id h62sm1126196wee.32.2011.08.26.08.59.36 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 26 Aug 2011 08:59:37 -0700 (PDT) Date: Fri, 26 Aug 2011 16:59:30 +0100 (BST) From: Edward Sheldrake To: linux-media@vger.kernel.org Subject: [PATCH] drxd: fix divide error Message-ID: User-Agent: Alpine 2.02 (LFD 1266 2009-07-14) MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Fri, 26 Aug 2011 15:59:43 +0000 (UTC) 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 --- 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; }