Skip to contentSkip to conversation

ath5k: Simplify loop when setting up channels

PATCH In review Bruno Randolf 2 participants 2 messages Jan 21, 2011 – Jan 22, 2011 Atheros ATH5K wireless driver

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 ath5k: Simplify loop when setting up channels

Simplify confusing code and get rid of an unnecessary variable.

---

v3: Bob pointed out another wrong check: count <= max.
The loop really was confusing _me_...

---
 drivers/net/wireless/ath/ath5k/base.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
drivers/net/wireless/ath/ath5k/base.c +3 -4
index 6850112..69ec878 100644
@@ -261,7 +261,7 @@ ath5k_copy_channels(struct ath5k_hw *ah,
 		unsigned int mode,
 		unsigned int max)
 {
-	unsigned int i, count, size, chfreq, freq, ch;
+	unsigned int count, size, chfreq, freq, ch;
 	enum ieee80211_band band;
 
 	if (!test_bit(mode, ah->ah_modes))
@@ -285,8 +285,8 @@ ath5k_copy_channels(struct ath5k_hw *ah,
 		return 0;
 	}
 
-	for (i = 0, count = 0; i < size && max > 0; i++) {
-		ch = i + 1 ;
+	count = 0;
+	for (ch = 1; ch <= size && count < max; ch++) {
 		freq = ieee80211_channel_to_frequency(ch, band);
 
 		if (freq == 0) /* mapping failed - not a standard channel */
@@ -312,7 +312,6 @@ ath5k_copy_channels(struct ath5k_hw *ah,
 		}
 
 		count++;
-		max--;
 	}
 
 	return count;