Optimize ath5k_cw_validate by using the classic (X & (X - 1)) == 0 check to see if a number is power of 2.
Signed-off-by: Nick Kossifidis <mickfl...@gmail.com> --- drivers/net/wireless/ath/ath5k/qcu.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-) diff --git a/drivers/net/wireless/ath/ath5k/qcu.c b/drivers/net/wireless/ath/ath5k/qcu.c index e50e64d..cdbaad7 100644 --- a/drivers/net/wireless/ath/ath5k/qcu.c +++ b/drivers/net/wireless/ath/ath5k/qcu.c @@ -111,6 +111,16 @@ ath5k_cw_validate(u16 cw_req) u32 cw = 1; cw_req = min(cw_req, (u16)1023); + /* Check if cw_req + 1 a power of 2 */ + if (!((cw_req + 1) & cw_req)) + return cw_req; + + /* Check if cw_req is a power of 2 */ + if (!(cw_req & (cw_req - 1))) + return cw_req - 1; + + /* If none of the above is correct + * find the closest power of 2 */ while (cw < cw_req) cw = (cw << 1) | 1; -- 1.7.8.rc1 _______________________________________________ ath5k-devel mailing list ath5k-devel@lists.ath5k.org https://lists.ath5k.org/mailman/listinfo/ath5k-devel