diff options
author | Nick Kossifidis <mickflemm@gmail.com> | 2011-11-25 13:40:31 -0500 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2011-11-28 14:44:23 -0500 |
commit | 9a3916910548e419f4da438406f84af9e05f72eb (patch) | |
tree | 2b40d8c0eb5467cddb7a8fda615bb4343cd1614f | |
parent | b4cfb5d574cd9e23e41462061941f6ac68a41c80 (diff) |
ath5k: Optimize ath5k_cw_validate
Optimize ath5k_cw_validate by using the classic (X & (X - 1)) == 0
check to see if a number is power of 2.
v2: Use functions from log2.h instead
Signed-off-by: Nick Kossifidis <mickflemm@gmail.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r-- | drivers/net/wireless/ath/ath5k/qcu.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/drivers/net/wireless/ath/ath5k/qcu.c b/drivers/net/wireless/ath/ath5k/qcu.c index e50e64d2a876..30b50f934172 100644 --- a/drivers/net/wireless/ath/ath5k/qcu.c +++ b/drivers/net/wireless/ath/ath5k/qcu.c | |||
@@ -23,6 +23,7 @@ Queue Control Unit, DCF Control Unit Functions | |||
23 | #include "ath5k.h" | 23 | #include "ath5k.h" |
24 | #include "reg.h" | 24 | #include "reg.h" |
25 | #include "debug.h" | 25 | #include "debug.h" |
26 | #include <linux/log2.h> | ||
26 | 27 | ||
27 | /** | 28 | /** |
28 | * DOC: Queue Control Unit (QCU)/DCF Control Unit (DCU) functions | 29 | * DOC: Queue Control Unit (QCU)/DCF Control Unit (DCU) functions |
@@ -108,13 +109,21 @@ ath5k_hw_release_tx_queue(struct ath5k_hw *ah, unsigned int queue) | |||
108 | static u16 | 109 | static u16 |
109 | ath5k_cw_validate(u16 cw_req) | 110 | ath5k_cw_validate(u16 cw_req) |
110 | { | 111 | { |
111 | u32 cw = 1; | ||
112 | cw_req = min(cw_req, (u16)1023); | 112 | cw_req = min(cw_req, (u16)1023); |
113 | 113 | ||
114 | while (cw < cw_req) | 114 | /* Check if cw_req + 1 a power of 2 */ |
115 | cw = (cw << 1) | 1; | 115 | if (is_power_of_2(cw_req + 1)) |
116 | return cw_req; | ||
116 | 117 | ||
117 | return cw; | 118 | /* Check if cw_req is a power of 2 */ |
119 | if (is_power_of_2(cw_req)) | ||
120 | return cw_req - 1; | ||
121 | |||
122 | /* If none of the above is correct | ||
123 | * find the closest power of 2 */ | ||
124 | cw_req = (u16) roundup_pow_of_two(cw_req) - 1; | ||
125 | |||
126 | return cw_req; | ||
118 | } | 127 | } |
119 | 128 | ||
120 | /** | 129 | /** |