Received: by 2002:a05:6520:2f93:b029:af:d4db:7a05 with SMTP id 19csp2372141lkf; Fri, 5 Feb 2021 11:24:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJyd3xZpp/bJWhfOl5ImtRKRAMhW8ir6DHEBsRO9PCys8Ik2byYp3AXZ42aKi9NEy0uGuiBv X-Received: by 2002:a05:6402:1153:: with SMTP id g19mr517100edw.292.1612553044971; Fri, 05 Feb 2021 11:24:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612553044; cv=none; d=google.com; s=arc-20160816; b=DdPA95pBYsCaRHOpyy/c+ylF0DNLD3LcR2UAV7nicDxsbonaX0b3Ef1ThYan6XKV79 uaJvHUwPQ5jnXN3HLEyzbvrinZaY6sx9XifjleIA/4Hz8ILnIdEUJHs9VKsrOcG5UQxF v41Lg+0Wb+5b+kPiOfScEJKw/30odVsc5GyqDbIcQi9A4pGxj1xH99Vj+fezwGSSRtds xBzk1d5TdOfDbTTV9o92fudzqMXgcp4sYnGR/TFDPs/a7Qy6c11g/TTAVTzbOPQ4bm1r 9b4OOez7ebfYKF0VNAnBLwV4HaH3xQWKgNhNsaWD/dymJoHBnsloaClp0hNdvg1DD06N fPLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:user-agent:date:message-id:subject:from:cc:to; bh=KAb/ZbtGsK+XwnepzwIkxIF5EfFi/+oxdjAb5OfplAk=; b=YVEPKkZfStcK+igKvw9Y29GNj9p3oja2yhIGHOSZ3CpqWLRzRKLKJy8I3ROhwm/5o1 PCb/xs8XVF3Tjukj5jQR+PMONXZSZC9/HT7PWYjl7dBQPzbJSfykvKBwaVtrIWhbmGD5 zfAGFI0XwkS53p8KPrPNs2voGz0A2O91GWgKqMFPe0/QQyK+cPqMA3ANV6QC9Dpl+Pzq Vt9fz3yAdOFrrZSjOzlhd2vWuk4ZXAYqLR1tp74fm/xw1hZLYzbQX+iJX78ocg36AqZ9 UpvlnWS1lZ53TD5MwuLLVhanGcpInkDw4QRYVP+en6LrKVHHq2uhX1r90c5Ck5dE664F I22A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id si4si5399634ejb.258.2021.02.05.11.23.36; Fri, 05 Feb 2021 11:24:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233493AbhBERjc (ORCPT + 99 others); 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