Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2972153ybl; Sun, 25 Aug 2019 06:07:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqwPmBjeUEJ8OaBx6y6e9QTP7+SKe32x4AHM7yTABFDpeMvJuRDkzr87FK/OlV0AOxVAhTGB X-Received: by 2002:a17:90a:ab01:: with SMTP id m1mr14234069pjq.69.1566738447712; Sun, 25 Aug 2019 06:07:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566738447; cv=none; d=google.com; s=arc-20160816; b=mmoTRVtBBPoxF3vkrlT9a/zV6wJmaeK+ScYpslffzSKYw27t6kAVmOY9TToKNC2L1I 1U4tUf3sYkbMT3A2rZ0Tmu8RXnsR2qKefVrnrFzYxA+o0l6RPbCORati3YiLWrS6QZRq 1wtVjD+IzcjEK+NWCZ57eHRiHs4oweYT4EPgtT2FZnHGlHmvTIBM2L8SpHxPa59VHog5 cdZLzzHBzX3NMxqwtDcJp9UIfdAoDtTsZFou0UjCf9okjbJPfAvJjZckbPh5Hbhiphc6 j/xupbOhuU1lcjuKr/60GB4ZXzORJAsH2/4vLb2lFCb/lGp2ZgRBjyXAo/cLBPun7nsy NxEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=/j+2bGL/nR+i9Xm5hiU1Y/6lXm9nJXiz/ro+F+BnBt0=; b=bS9O8hViQ3iHbCNurD5OOPhIdXicn1Kz2Uq+dIsByjmF5UxcI7kudUki+ZLVI20kMq gR5aOQ47GOPXyb3u0odBmjeAsozRdg8DJqdj10B0AW55rAwljB6ChCDZhCwcy+VUYv2u Gy5Uo909WK8Fzjut6RMY11IcZcwUoTMv5I2AMm5MH0q8HtXEFHjIWClJMhvKs9BTM72G WII+MJzpdEvpuNJVgkynKGt6UUJUp1m2NuDQ6VL2vIZreTEYNshnMxa6KSyjadUmkWGV lbZrL4ual/oxxVgvo37C3ol7ibtxbu54yt7n3vNmfqyFklmJuiIhZTmGCNsLO+SI2j0x EmKg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f6si6847004plt.195.2019.08.25.06.07.12; Sun, 25 Aug 2019 06:07:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727426AbfHYNFt (ORCPT + 99 others); Sun, 25 Aug 2019 09:05:49 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:39408 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726182AbfHYNFt (ORCPT ); Sun, 25 Aug 2019 09:05:49 -0400 Received: by mail-wm1-f66.google.com with SMTP id i63so13301476wmg.4 for ; Sun, 25 Aug 2019 06:05:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/j+2bGL/nR+i9Xm5hiU1Y/6lXm9nJXiz/ro+F+BnBt0=; b=cpyYSURFXmj2NG52iJu9iQgLZBCuImYIB+0SkdZ6Q19JUfD2NdXvHGRJgf4JpLJHUH NrLO2NWNfwY69ShjbZ0gtCqszzWWCKSfssc7hYn3hNKC5AJ5Lfr/MqEybF3vS1VI3Q8X 03GbUy6oK0tZXT0wHD4bbTZvmeROI2FGXL+c87Uk/t/IqXvCt7hHcr4COSYLtEjKuihA vLeQJzhtVM/kzQ+UVYG9bMWYGpxu67qVTNJfl2jjA9Ooo5jcd69p/n8hWuQQ2M7QrnHU 80vhJFkrHL3O0/tv9KolIwjdpxoLHZ93uFNFYFU37JRA36z9bSc5itp3K80bVA9nNClY ZSvQ== X-Gm-Message-State: APjAAAXBOdnYqbQ48em9CWTmt622RbCGk53a+jUr2005dJvYE053JARn 2JDehLG40x5bnzvLgMQsDps= X-Received: by 2002:a1c:8187:: with SMTP id c129mr15897769wmd.32.1566738347190; Sun, 25 Aug 2019 06:05:47 -0700 (PDT) Received: from green.intra.ispras.ru (bran.ispras.ru. [83.149.199.196]) by smtp.googlemail.com with ESMTPSA id z12sm7832841wrt.92.2019.08.25.06.05.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Aug 2019 06:05:46 -0700 (PDT) From: Denis Efremov To: cocci@systeme.lip6.fr Cc: Denis Efremov , linux-kernel@vger.kernel.org, Julia Lawall , Gilles Muller , Nicolas Palix , Michal Marek Subject: [PATCH] scripts: coccinelle: check for !(un)?likely usage Date: Sun, 25 Aug 2019 16:05:36 +0300 Message-Id: <20190825130536.14683-1-efremov@linux.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds coccinelle script for detecting !likely and !unlikely usage. It's better to use unlikely instead of !likely and vice versa. Signed-off-by: Denis Efremov --- scripts/coccinelle/misc/unlikely.cocci | 70 ++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 scripts/coccinelle/misc/unlikely.cocci diff --git a/scripts/coccinelle/misc/unlikely.cocci b/scripts/coccinelle/misc/unlikely.cocci new file mode 100644 index 000000000000..88278295d76a --- /dev/null +++ b/scripts/coccinelle/misc/unlikely.cocci @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0-only +/// Use unlikely instead of !likely and likely instead of !unlikely. +/// +// Confidence: High +// Copyright: (C) 2019 Denis Efremov, ISPRAS. +// Options: --include-headers + +virtual patch +virtual context +virtual org +virtual report + +//---------------------------------------------------------- +// For context mode +//---------------------------------------------------------- + +@depends on context disable unlikely@ +expression E; +@@ + +( +* !likely(E) +| +* !unlikely(E) +) + +//---------------------------------------------------------- +// For patch mode +//---------------------------------------------------------- + +@depends on patch disable unlikely@ +expression E; +@@ + +( +-!likely(E) ++unlikely(E) +| +-!unlikely(E) ++likely(E) +) + +//---------------------------------------------------------- +// For org and report mode +//---------------------------------------------------------- + +@r depends on (org || report) disable unlikely@ +expression E; +position p; +@@ + +( + !likely@p(E) +| + !unlikely@p(E) +) + +@script:python depends on org@ +p << r.p; +@@ + +coccilib.org.print_todo(p[0], "WARNING use unlikely instead of !likely") + +@script:python depends on report@ +p << r.p; +@@ + +msg="WARNING: Use unlikely instead of !likely" +coccilib.report.print_report(p[0], msg) + -- 2.21.0