From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49D0CC433DB for ; Fri, 5 Feb 2021 19:22:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E9E6064E2E for ; Fri, 5 Feb 2021 19:22:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233493AbhBERjc (ORCPT ); Fri, 5 Feb 2021 12:39:32 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:39402 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233435AbhBEP5X (ORCPT ); Fri, 5 Feb 2021 10:57:23 -0500 Received: from 1.general.cking.uk.vpn ([10.172.193.212]) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1l854C-0003cO-Bn; Fri, 05 Feb 2021 17:38:48 +0000 To: Johannes Berg Cc: "David S. Miller" , Jakub Kicinski , "linux-wireless@vger.kernel.org" , "netdev@vger.kernel.org" From: Colin Ian King Subject: Potential invalid ~ operator in net/mac80211/cfg.c Message-ID: <4bb65f2f-48f9-7d9c-ab2e-15596f15a4d8@canonical.com> Date: Fri, 5 Feb 2021 17:38:47 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org 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