From: Johannes Berg <johannes@sipsolutions.net>
To: Colin Ian King <colin.king@canonical.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
"linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: Potential invalid ~ operator in net/mac80211/cfg.c
Date: Fri, 05 Feb 2021 19:05:13 +0100 [thread overview]
Message-ID: <15f435a791b0c4b853c8c6b284042c7057d6efaf.camel@sipsolutions.net> (raw)
In-Reply-To: <4bb65f2f-48f9-7d9c-ab2e-15596f15a4d8@canonical.com>
Hi Colin,
> while working through a backlog of older static analysis reports from
> Coverity
So ... yeah. Every time I look at Coverity (not frequently, I must
admit) I see the same thing, and get confused.
> I found an interesting use of the ~ operator that looks
> incorrect to me in function ieee80211_set_bitrate_mask():
>
> for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
> if (~sdata->rc_rateidx_mcs_mask[i][j]) {
> 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]) {
> sdata->rc_has_vht_mcs_mask[i] = true;
> break;
> }
> }
>
> For the ~ operator in both if stanzas, Coverity reports:
>
> Logical vs. bitwise operator (CONSTANT_EXPRESSION_RESULT)
> logical_vs_bitwise:
>
> ~sdata->rc_rateidx_mcs_mask[i][j] is always 1/true regardless of the
> values of its operand. This occurs as the logical operand of if.
> Did you intend to use ! rather than ~?
>
> I've checked the results of this and it does seem that ~ is incorrect
> and always returns true for the if expression. So it probably should be
> !, but I'm not sure if I'm missing something deeper here and wondering
> why this has always worked.
But is it really always true?
I _think_ it was intended to check that it's not 0xffffffff or
something?
https://lore.kernel.org/linux-wireless/516C0C7F.3000204@openwrt.org/
But maybe that isn't actually quite right due to integer promotion?
OTOH, that's a u8, so it should do the ~ in u8 space, and then compare
to 0 also?
johannes
next prev parent reply other threads:[~2021-02-05 18:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-05 17:38 Potential invalid ~ operator in net/mac80211/cfg.c Colin Ian King
2021-02-05 18:05 ` Johannes Berg [this message]
2021-02-05 18:19 ` Colin Ian King
2021-02-05 18:20 ` Colin Ian King
2021-02-12 10:18 ` Johannes Berg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=15f435a791b0c4b853c8c6b284042c7057d6efaf.camel@sipsolutions.net \
--to=johannes@sipsolutions.net \
--cc=colin.king@canonical.com \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox