staging: vt6656: Refactor the vnt_ofdm_min_rate function
PATCH 1/1 staging: vt6656: Refactor the vnt_ofdm_min_rate function
Replace the for loop by a ternary operator whose condition is an AND bitmask against the priv->basic_rates variable.
The purpose of the for loop was to check if any of bits from RATE_54M to RATE_6M was set, but it's not necessary to check every individual bit. The same result can be achieved using only one single mask which comprises all the commented bits.
This way avoid the iteration over an unnecessary for loop.
Also change the return type to bool because it's the type that this function returns.
--- drivers/staging/vt6656/card.c | 11 ++--------- drivers/staging/vt6656/card.h | 2 +- 2 files changed, 3 insertions(+), 10 deletions(-)
drivers/staging/vt6656/card.c +2 -9
@@ -248,16 +248,9 @@ void vnt_update_top_rates(struct vnt_private *priv) priv->top_cck_basic_rate = top_cck; } -int vnt_ofdm_min_rate (struct vnt_private *priv) +bool vnt_ofdm_min_rate (struct vnt_private *priv) { -int ii; - -for (ii =RATE_54M ; ii >=RATE_6M ; ii--) { -if ((priv->basic_rates) & ((u16 )BIT (ii))) -return true; - } - -return false; +return priv->basic_rates &GENMASK (RATE_54M ,RATE_6M ) ? true : false; }u8 vnt_get_pkt_type (struct vnt_private *priv)
drivers/staging/vt6656/card.h +1 -1
@@ -29,7 +29,7 @@ void vnt_set_channel(struct vnt_private *priv, u32 connection_channel);void vnt_set_rspinf (struct vnt_private *priv,u8 bb_type);void vnt_update_ifs (struct vnt_private *priv);void vnt_update_top_rates (struct vnt_private *priv); -int vnt_ofdm_min_rate (struct vnt_private *priv); +bool vnt_ofdm_min_rate (struct vnt_private *priv);void vnt_adjust_tsf (struct vnt_private *priv,u8 rx_rate,u64 time_stamp,u64 local_tsf);bool vnt_get_current_tsf (struct vnt_private *priv,u64 *current_tsf);
--
2.20.1
Hi Oscar,
Quoted 29 lines · On Sat, 18 Apr 2020 15:45:53 +0200 Oscar Carter <[email protected]> wrote:
Replace the for loop by a ternary operator whose condition is an AND bitmask against the
priv->basic_ratesvariable.The purpose of the for loop was to check if any of bits from
RATE_54MtoRATE_6Mwas set, but it's not necessary to check every individual bit. The same result can be achieved using only one single mask which comprises all the commented bits.This way avoid the iteration over an unnecessary for loop.
Also change the return type to bool because it's the type that this function returns.
Signed-off-by Oscar Carter <[email protected]>--- drivers/staging/vt6656/card.c | 11 ++--------- drivers/staging/vt6656/card.h | 2 +- 2 files changed, 3 insertions(+), 10 deletions(-)drivers/staging/vt6656/card.c +1
-1@@ -248,16 +248,9 @@ void vnt_update_top_rates(struct vnt_private *priv) priv->top_cck_basic_rate = top_cck; } -int vnt_ofdm_min_rate (struct vnt_private *priv) +bool vnt_ofdm_min_rate (struct vnt_private *priv)
drivers/staging/vt6656/card.c void vnt_update_top_rates(struct vnt_private *priv) · line 253
Quoted 10 lines
drivers/staging/vt6656/card.c +1
-8{ -int ii; - -for (ii =RATE_54M ; ii >=RATE_6M ; ii--) { -if ((priv->basic_rates) & ((u16 )BIT (ii))) -return true; - } - -return false; +return priv->basic_rates &GENMASK (RATE_54M ,RATE_6M ) ? true : false;
priv->basic_rates & GENMASK(RATE_54M, RATE_6M) is already true if non-zero and false otherwise. Note that I haven't checked if the rest is correct.
Signature · 1 line
Stefano
Hi all
Quoted 12 lines · Stefano Brivio
Hi Oscar,
Quoted 7 lines · On Sat, 18 Apr 2020 15:45:53 +0200 Oscar Carter <[email protected]> wrote:
Replace the for loop by a ternary operator whose condition is an AND bitmask against the
priv->basic_ratesvariable.The purpose of the for loop was to check if any of bits from
RATE_54MtoRATE_6Mwas set, but it's not necessary to check every individual bit. The same result can be achieved using only one single mask which comprises all the commented bits.
<snip>
Quoted 18 lines
drivers/staging/vt6656/card.c void vnt_update_top_rates(struct vnt_private *priv) · line 253
Quoted 13 lines
drivers/staging/vt6656/card.c +2
-9-int vnt_ofdm_min_rate (struct vnt_private *priv) +bool vnt_ofdm_min_rate (struct vnt_private *priv) { -int ii; - -for (ii =RATE_54M ; ii >=RATE_6M ; ii--) { -if ((priv->basic_rates) & ((u16 )BIT (ii))) -return true; - } - -return false; +return priv->basic_rates &GENMASK (RATE_54M ,RATE_6M ) ? true : false;
priv->basic_rates&GENMASK(RATE_54M, RATE_6M)is already true if non-zero and false otherwise. Note that I haven't checked if the rest is correct.
Yes only 1 or more needs to be true and it is false when none present.
I have run-time checked the patch and it does function as before.
Regards
Malcolm.