Netdev List
 help / color / mirror / Atom feed
From: Colin Ian King <colin.king@canonical.com>
To: Johannes Berg <johannes.berg@intel.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: Potential invalid ~ operator in net/mac80211/cfg.c
Date: Fri, 5 Feb 2021 17:38:47 +0000	[thread overview]
Message-ID: <4bb65f2f-48f9-7d9c-ab2e-15596f15a4d8@canonical.com> (raw)

Hi there,

while working through a backlog of older static analysis reports from
Coverity 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.

Colin

             reply	other threads:[~2021-02-05 19:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-05 17:38 Colin Ian King [this message]
2021-02-05 18:05 ` Potential invalid ~ operator in net/mac80211/cfg.c Johannes Berg
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=4bb65f2f-48f9-7d9c-ab2e-15596f15a4d8@canonical.com \
    --to=colin.king@canonical.com \
    --cc=davem@davemloft.net \
    --cc=johannes.berg@intel.com \
    --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