All of lore.kernel.org
 help / color / mirror / Atom feed
From: Adrian Bunk <bunk@kernel.org>
To: yi.zhu@intel.com
Cc: linux-wireless@vger.kernel.org,
	ipw3945-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Subject: [2.6 patch] iwl4965-base.c: fix off-by-one errors
Date: Sun, 14 Oct 2007 19:51:15 +0200	[thread overview]
Message-ID: <20071014175115.GL4211@stusta.de> (raw)

This patch fixes two off-by-one errors resulting in array overflows 
spotted by the Coverity checker.

Signed-off-by: Adrian Bunk <bunk@kernel.org>

---

 drivers/net/wireless/iwlwifi/iwl4965-base.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

--- linux-2.6/drivers/net/wireless/iwlwifi/iwl4965-base.c.old	2007-10-14 16:52:21.000000000 +0200
+++ linux-2.6/drivers/net/wireless/iwlwifi/iwl4965-base.c	2007-10-14 16:59:37.000000000 +0200
@@ -4489,23 +4489,23 @@ static u8 ratio2dB[100] = {
 	39, 39, 39, 39, 39, 40, 40, 40, 40, 40  /* 90 - 99 */
 };
 
 /* Calculates a relative dB value from a ratio of linear
  *   (i.e. not dB) signal levels.
  * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
 int iwl_calc_db_from_ratio(int sig_ratio)
 {
-	/* Anything above 1000:1 just report as 60 dB */
-	if (sig_ratio > 1000)
+	/* 1000:1 or higher just report as 60 dB */
+	if (sig_ratio >= 1000)
 		return 60;
 
-	/* Above 100:1, divide by 10 and use table,
+	/* 100:1 or higher, divide by 10 and use table,
 	 *   add 20 dB to make up for divide by 10 */
-	if (sig_ratio > 100)
+	if (sig_ratio >= 100)
 		return (20 + (int)ratio2dB[sig_ratio/10]);
 
 	/* We shouldn't see this */
 	if (sig_ratio < 1)
 		return 0;
 
 	/* Use table for ratios 1:1 - 99:1 */
 	return (int)ratio2dB[sig_ratio];


             reply	other threads:[~2007-10-14 17:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-14 17:51 Adrian Bunk [this message]
2007-10-17  7:33 ` [2.6 patch] iwl4965-base.c: fix off-by-one errors Zhu Yi
2007-10-18 14:35 ` Cahill, Ben M

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071014175115.GL4211@stusta.de \
    --to=bunk@kernel.org \
    --cc=ipw3945-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=yi.zhu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.