From patchwork Fri Mar 4 15:31:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weiguo Li X-Patchwork-Id: 108541 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8D4BAA034E; Fri, 4 Mar 2022 16:32:28 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1598F427CA; Fri, 4 Mar 2022 16:32:28 +0100 (CET) Received: from out203-205-251-73.mail.qq.com (out203-205-251-73.mail.qq.com [203.205.251.73]) by mails.dpdk.org (Postfix) with ESMTP id 2C262427A9 for ; Fri, 4 Mar 2022 16:32:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1646407942; bh=mFosLx1vM/eT+xRPAlEv5N6NbHz22pRBsd7zRgxPS5I=; h=From:To:Cc:Subject:Date; b=Kvt5RgPO8FX5K68IS2Dc1n/wL9ZK1nIr66KFm8XaObfikvYjcXErRZfBuGevngf5a v9YFfCfGSHRIBv+3sjyH2gAL8SrI3HfJHPvt51DNLIJPpHe2fAwjEdYYoUaVFuuoE/ 2AW2D34fl7NVzGyC3GjEn0LxiLmcHseFpHWp/els= Received: from localhost.localdomain ([111.193.130.237]) by newxmesmtplogicsvrsza8.qq.com (NewEsmtp) with SMTP id 7F61569A; Fri, 04 Mar 2022 23:31:54 +0800 X-QQ-mid: xmsmtpt1646407914tpen7imhs Message-ID: X-QQ-XMAILINFO: NMGzQWUSIfvTrbSLDTxA6B+o2mVdZv9t74wFAQhyNlb/zVxTyv4ElnnW5R8Ngx k4/6aav/Q9Rt7eAjyUi0XBHpyyUz0TDDYvO5Y8+LSNSqdFwGAaB2i6HDWGeh6bx+E2xlHusBgiRv rXXuLa7KGO7tepTX2222XSB2kiG8okHWzaBwd9ngMJVHtYEY79oOgU23mL69Zq18g6YnCMFrTtx/ /VpGZfi3KeGjWXX77EJgHy0KuG8YGo119rJBb9MpEQCapy6pnd8bf9emknjHXDd+AghoWUdE5le5 TVfZg/3Z6+eYOcAfWyx2NjtyZMDU145ceyze924y3mPK9ZJdHhmJYDwbJEDtv89sYqCz4NOhlgds UNFnl+ekDEo1NFSCKTbndL75kwadsv9K8w4X/HSYCpNrM2/VEdmo2sgrj7vJBx2jD5LzMCALhenM 948uSDuIJjzYDhNaXFAu+SuCay3wiLsp3be97+DNkLgCeKv5XWG+83RJ+Klj+hgtTshfEn16KGrz 1pdqowa9tDSrdplhaq9dIHGDg56JP466GeckuBvLh8sLQN97vbIoofGL2ZVZcKEg5XC56ULi0Toh eV1jYlJWKb7QkXjeI8j1esIDqb1TWRszV+u2cLkuUyZpf6yFK7yG/jSk3oLa+lW0UgUhn5BMDXYz UkpE4bAK89t2RdzNUp4RIbschFgWqTbofaeZWUTdRCzy55IPMaPjqmR3JfZ+ASy7cqXGUp+ulehA B2BDnK9RcjYwdMs4/4i5gLfrJ7h9ZfypePiy1GjswPlqUaHTPAwAtqU3iaqwtHpmyLp+yV5WUa3H FpruwYB/2b/vC6JmowmFvEfWoiD97s/zxw3dA1AB7ieza7QUcNL8wNyD87xYG11+l41yZOFRAJdm S3W9sa0PnvOQxPtJS2Tw+TeIhaiCX/0DtcvR9qpVjw From: Weiguo Li To: dev@dpdk.org, stephen@networkplumber.org Cc: ferruh.yigit@intel.com Subject: [PATCH] devtools/cocci: change boolean negation to bitwise negation Date: Fri, 4 Mar 2022 23:31:53 +0800 X-OQ-MSGID: <20220304153153.38015-1-liwg06@foxmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Combining boolean operator with bitwise operator is suspicious. When this happens, it has a chance that the bitwise negation operation is mistakenly written as a boolean negation operation. This script is used to find this kind of problems. example: if (x & !BITS_MASK) changed to: if (x & ~BITS_MASK) The idea came from a demo script in coccinelle website: https://coccinelle.gitlabpages.inria.fr/website/rules/notand.html Signed-off-by: Weiguo Li --- devtools/cocci/bitwise_negation.cocci | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 devtools/cocci/bitwise_negation.cocci diff --git a/devtools/cocci/bitwise_negation.cocci b/devtools/cocci/bitwise_negation.cocci new file mode 100644 index 0000000000..78fc677e4e --- /dev/null +++ b/devtools/cocci/bitwise_negation.cocci @@ -0,0 +1,18 @@ +// +// The bitwise negation operation is easy to be mistakenly written as a boolean +// negation operation, this script is used to find this kind of problem. +// +// Note: If it is confirmed to be a boolean negation operation, it is recommended +// that change & to && to avoid false positives. +// +@@ expression E; constant C; @@ +( + !E & !C +| +- !E & C ++ !(E & C) +| +- E & !C ++ E & ~C +) +