wifi: morsemicro: mm81x: get rid of code duplications
cover wifi: morsemicro: mm81x: get rid of code duplications
Get rid of nth_bit() duplicating the generic fns(), and drop opencoded hweight16() in bit_index().
Yury Norov (2):
wifi: morsemicro: mm81x: switch to use fns()
wifi: morsemicro: mm81x: use hweight16() to calculate bit index
drivers/net/wireless/morsemicro/mm81x/mmrc.c | 34 ++++---------------- 1 file changed, 7 insertions(+), 27 deletions(-)
Signature · 1 line
2.53.0
PATCH 1/2 wifi: morsemicro: mm81x: switch to use fns()
Replace the local nth_bit() helper with fns(), which provides the same zero-based set-bit selection for rate capability masks.
Signed-off-by Yury Norov <[email protected]>
--- drivers/net/wireless/morsemicro/mm81x/mmrc.c | 26 +++++--------------- 1 file changed, 6 insertions(+), 20 deletions(-)
drivers/net/wireless/morsemicro/mm81x/mmrc.c +6 -20
@@ -2,6 +2,8 @@/* * Copyright (c) 2017-2026 Morse Micro */ +#include <linux/bitops.h> +#include "mmrc.h" /*
@@ -198,22 +200,6 @@*/ static const u32 sym_table[10 ] = {24 ,36 ,48 ,72 ,96 ,144 ,192 ,216 ,256 ,288 }; -/* -* Calculate which bit is the nth bit set in an integer based flag. -*/ -static u8 nth_bit (u16 in,u16 index) -{ -u32 i; -u8 count =0 ; - -for (i =0 ; count != index +1 ; i++) { -if (((1u << i) & in) !=0 ) - count++; - } - -return i -1 ; -} -/* * Calculate the input bit's index among all the set bits in an integer * based flag.
@@ -291,19 +277,19 @@ static struct mmrc_rate get_rate_row(struct mmrc_table *tb, u16 index)u16 mcs_index = index / rows;u16 mcs_modulo = index % rows; - mcs =nth_bit (tb->caps.rates, mcs_index); + mcs =fns (tb->caps.rates, mcs_index);/* Find our spatial stream */ rows = rows / streams; - streams =nth_bit (tb->caps.spatial_streams, mcs_modulo / rows); + streams =fns (tb->caps.spatial_streams, mcs_modulo / rows);/* Find our bandwidth */ ss_index = index % rows; rows = rows / bw; - bw =nth_bit (tb->caps.bandwidth, ss_index / rows); + bw =fns (tb->caps.bandwidth, ss_index / rows);/* Find our guard */ - guard =nth_bit (tb->caps.guard, index % guard); + guard =fns (tb->caps.guard, index % guard);/* Add range checks to keep scan-build happy */ if (bw >=MMRC_BW_MAX )
Signature · 1 line
2.53.0
PATCH 2/2 wifi: morsemicro: mm81x: use hweight16() to calculate bit index
In reply to Yury NorovCount the set bits through bit_pos with hweight16() and an inclusive mask. Preserve the zero fallback and zero-based index.
Signed-off-by Yury Norov <[email protected]>
--- drivers/net/wireless/morsemicro/mm81x/mmrc.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/wireless/morsemicro/mm81x/mmrc.c +1 -7
@@ -206,13 +206,7 @@ static const u32 sym_table[10] = { 24, 36, 48, 72, 96, 144, 192, 216, 256, 288 }*/ static u16 bit_index (u16 in,u32 bit_pos) { -u16 i; -u16 index =0 ; - -for (i =0 ; i != bit_pos +1 ; i++) { -if (((1u << i) & in) !=0 ) - index++; - } +u16 index =hweight16 (in &GENMASK (bit_pos,0 ));if (index ==0 ) {/* Could not match bit pos to caps */
Signature · 1 line
2.53.0