From: Nick Kossifidis Date: Fri, 25 Nov 2011 18:40:31 +0000 (+0200) Subject: ath5k: Optimize ath5k_cw_validate X-Git-Tag: v3.3-rc1~182^2~44^2~284 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9a3916910548e419f4da438406f84af9e05f72eb;p=platform%2Fupstream%2Fkernel-adaptation-pc.git 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 Signed-off-by: John W. Linville --- diff --git a/drivers/net/wireless/ath/ath5k/qcu.c b/drivers/net/wireless/ath/ath5k/qcu.c index e50e64d..30b50f9 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 #include "ath5k.h" #include "reg.h" #include "debug.h" +#include /** * 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) static u16 ath5k_cw_validate(u16 cw_req) { - u32 cw = 1; cw_req = min(cw_req, (u16)1023); - while (cw < cw_req) - cw = (cw << 1) | 1; + /* Check if cw_req + 1 a power of 2 */ + if (is_power_of_2(cw_req + 1)) + return cw_req; - return cw; + /* Check if cw_req is a power of 2 */ + if (is_power_of_2(cw_req)) + return cw_req - 1; + + /* If none of the above is correct + * find the closest power of 2 */ + cw_req = (u16) roundup_pow_of_two(cw_req) - 1; + + return cw_req; } /**