Skip to contentSkip to conversation

iwl3945-base.c: fix off-by-one errors

PATCH In review Adrian Bunk 2 participants 2 messages Feb 2, 2008 Networking drivers (wireless)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iwl3945-base.c: fix off-by-one errors

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

---

I remember having fixed exactly the same bug in iwl4965-base.c some time ago - it might perhaps be possible to share some of the duplicated code between the two drivers?

drivers/net/wireless/iwlwifi/iwl3945-base.c +4 -4
@@ -4207,13 +4207,13 @@ static u8 ratio2dB[100] = {
  * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
 int iwl3945_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 */
#1 lore raw
Quoted 10 lines · Adrian Bunk

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

---

I remember having fixed exactly the same bug in iwl4965-base.c some time ago - it might perhaps be possible to share some of the duplicated code between the two drivers?

We are working on it.

Quoted 23 lines
drivers/net/wireless/iwlwifi/iwl3945-base.c +4 -5
@@ -4207,13 +4207,13 @@ static u8 ratio2dB[100] = {
  * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
 int iwl3945_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 */
 
-
Quoted 4 lines

To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

ACK

Thanks
Tomas