diff mbox series

mac80211: fix rate mask reset

Message ID 20210212112213.36b38078f569.I8546a20c80bc1669058eb453e213630b846e107b@changeid (mailing list archive)
State Accepted
Delegated to: Johannes Berg
Headers show
Series mac80211: fix rate mask reset | expand

Commit Message

Johannes Berg Feb. 12, 2021, 10:22 a.m. UTC
From: Johannes Berg <johannes.berg@intel.com>

Coverity reported the strange "if (~...)" condition that's
always true. It suggested that ! was intended instead of ~,
but upon further analysis I'm convinced that what really was
intended was a comparison to 0xff/0xffff (in HT/VHT cases
respectively), since this indicates that all of the rates
are enabled.

Change the comparison accordingly.

I'm guessing this never really mattered because a reset to
not having a rate mask is basically equivalent to having a
mask that enables all rates.

Reported-by: Colin Ian King <colin.king@canonical.com>
Fixes: 2ffbe6d33366 ("mac80211: fix and optimize MCS mask handling")
Fixes: b119ad6e726c ("mac80211: add rate mask logic for vht rates")
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 net/mac80211/cfg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Colin King Feb. 12, 2021, 10:34 a.m. UTC | #1
On 12/02/2021 10:22, Johannes Berg wrote:
> From: Johannes Berg <johannes.berg@intel.com>
> 
> Coverity reported the strange "if (~...)" condition that's
> always true. It suggested that ! was intended instead of ~,
> but upon further analysis I'm convinced that what really was
> intended was a comparison to 0xff/0xffff (in HT/VHT cases
> respectively), since this indicates that all of the rates
> are enabled.
> 
> Change the comparison accordingly.
> 
> I'm guessing this never really mattered because a reset to
> not having a rate mask is basically equivalent to having a
> mask that enables all rates.
> 
> Reported-by: Colin Ian King <colin.king@canonical.com>
> Fixes: 2ffbe6d33366 ("mac80211: fix and optimize MCS mask handling")
> Fixes: b119ad6e726c ("mac80211: add rate mask logic for vht rates")
> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
> ---
>  net/mac80211/cfg.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
> index c4c70e30ad7f..68a0de02b561 100644
> --- a/net/mac80211/cfg.c
> +++ b/net/mac80211/cfg.c
> @@ -2950,14 +2950,14 @@ static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
>  			continue;
>  
>  		for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
> -			if (~sdata->rc_rateidx_mcs_mask[i][j]) {
> +			if (sdata->rc_rateidx_mcs_mask[i][j] != 0xff) {
>  				sdata->rc_has_mcs_mask[i] = true;
>  				break;
>  			}
>  		}
>  
>  		for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
> -			if (~sdata->rc_rateidx_vht_mcs_mask[i][j]) {
> +			if (sdata->rc_rateidx_vht_mcs_mask[i][j] != 0xffff) {
>  				sdata->rc_has_vht_mcs_mask[i] = true;
>  				break;
>  			}
> 

Looks good to me, thanks Johannes.

Reviewed-by: Colin Ian King <colin.king@canonical.com>
diff mbox series

Patch

diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index c4c70e30ad7f..68a0de02b561 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -2950,14 +2950,14 @@  static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
 			continue;
 
 		for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
-			if (~sdata->rc_rateidx_mcs_mask[i][j]) {
+			if (sdata->rc_rateidx_mcs_mask[i][j] != 0xff) {
 				sdata->rc_has_mcs_mask[i] = true;
 				break;
 			}
 		}
 
 		for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
-			if (~sdata->rc_rateidx_vht_mcs_mask[i][j]) {
+			if (sdata->rc_rateidx_vht_mcs_mask[i][j] != 0xffff) {
 				sdata->rc_has_vht_mcs_mask[i] = true;
 				break;
 			}