Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5810170ybl; Tue, 27 Aug 2019 09:57:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqzVBQirJmkMK44Q0/osc/KahtPYaStBMHHHQ0LBuJVC0OIymnLr4JlcslBHV0Pa5yq+SsXa X-Received: by 2002:a63:2157:: with SMTP id s23mr22722191pgm.167.1566925034550; Tue, 27 Aug 2019 09:57:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566925034; cv=none; d=google.com; s=arc-20160816; b=JlmEIqskqAegKTxBmsDsGi1Og6k+t8lw3jFFOc/82+Q8OJ6BirHBAOpUn62c92PUaA zmd1g2zStwuRNXq0WL/MMEjZO2Bn5hfgWS5VC2KJUO0X2+9SS5HUqXgzJdTd7Y3rqbV6 wertIXzfaipBzxgfmgFoTfWdu6s+Gv2fiHNmTAL8MJRE/8gNWMp1j1GPsk4hqQhjp4xh +OnrTe3tiPyf7xvBVy/k5qxffncaDlJN+IKZaf6ExBfItCqs0deJNnwmk/rQWRufs/Hk Ai+mlvuDHclJuqGSu83nTbH1cF01MkTWmRyZO0vIRyAyMQyEs9sdAkAjh6FUexox46fd U/1g== 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=nJ6Yhnmx0Z0m7upWdz8dDf2ghGkiqwiluwv7s0RuRzw=; b=SCft1z9rrWFV7VSmNVQd1+x34ZAmIPBlEy7KB758vp9WRE2dexU1hnHY9XI81Td0Xn uWBHLKC9BWVU3n773Afd9Y94iKaJYVzkpbmfSbQTA2zOL8Xza5XbTc7eH0SF8b/84kNP zPOJmT/p18FdqNiJ552s9oGneLh8QD+QPNyUdhoJaurm+aJZQB8CsWz1BVfe01Up8CTt tubFnYeKR6SOidnFbUtYlPhDPegXlOoAvd8BjL1B7oYW9SkXMcODS682oiZHkph671We 6l91n85g/bmwj5SJxHMru7xawfA7uL2XAZlNWShMrrW/DKMpoH8x/4e9AsaqXmuwAYg4 9Yuw== 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 h65si13913112pfe.216.2019.08.27.09.56.59; Tue, 27 Aug 2019 09:57:14 -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 S1730360AbfH0QzZ (ORCPT + 99 others); Tue, 27 Aug 2019 12:55:25 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:43661 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727138AbfH0QzY (ORCPT ); Tue, 27 Aug 2019 12:55:24 -0400 Received: by mail-wr1-f68.google.com with SMTP id y8so19516778wrn.10 for ; Tue, 27 Aug 2019 09:55:23 -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=nJ6Yhnmx0Z0m7upWdz8dDf2ghGkiqwiluwv7s0RuRzw=; b=r/1/FW9K/xvuA1EMuhXiOewETkY57LpLS0iNzP2MBWFvZaZGgakmL3A0ibspVZjUfj lCqhLhprFwz9oPl5SQrIH5jTABPpvu08gW32+JOnjOfN+yWz0Sr02qjSjrgMfDjsl2Kt YXLCqSjTmy1E9gwIyqStd+/NdVIbnWtBBZ2F6z2HLhvEhV+KFy3DL9cdbhyMSQiZvqww CGd2A03GLxXqEWnzeHhkaCeyIT6TLTX35LUy129/cmnoYJe6YSCzKsBw66gt/KAdwBf+ kNBQySxpywFBr9HY6o4uaEal2gXF+Oq252cmS5PiFt9w0YtDYoweQm3guGFTiI8sUlLE yZUQ== X-Gm-Message-State: APjAAAXwM8MmhYSdK5QcLHq8I5MZVPONwRXTLhY96biUv2GQ+nbDUw7K T50lvqg3/S/mmNro+IJQhTA= X-Received: by 2002:a05:6000:1186:: with SMTP id g6mr31711139wrx.17.1566924922812; Tue, 27 Aug 2019 09:55:22 -0700 (PDT) Received: from green.intra.ispras.ru (bran.ispras.ru. [83.149.199.196]) by smtp.googlemail.com with ESMTPSA id n14sm54925295wra.75.2019.08.27.09.55.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2019 09:55:22 -0700 (PDT) From: Denis Efremov To: Andy Whitcroft , Joe Perches Cc: Denis Efremov , linux-kernel@vger.kernel.org Subject: [PATCH] checkpatch: check for nested (un)?likely calls Date: Tue, 27 Aug 2019 19:55:15 +0300 Message-Id: <20190827165515.21668-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 IS_ERR, IS_ERR_OR_NULL, IS_ERR_VALUE already contain unlikely optimization internally. Thus, there is no point in calling these functions under likely/unlikely. This check is based on the coccinelle rule developed by Enrico Weigelt https://lore.kernel.org/lkml/1559767582-11081-1-git-send-email-info@metux.net/ Signed-off-by: Denis Efremov --- scripts/checkpatch.pl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 93a7edfe0f05..81dace5ceea5 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -6480,6 +6480,13 @@ sub process { "Using $1 should generally have parentheses around the comparison\n" . $herecurr); } +# nested likely/unlikely calls + if ($perl_version_ok && + $line =~ /\b(?:(?:un)?likely)\s*\(!?\s*(IS_ERR(?:_OR_NULL|_VALUE)?)\s*${balanced_parens}\s*\)/) { + WARN("LIKELY_MISUSE", + "nested (un)?likely calls, unlikely already used in $1 internally\n" . $herecurr); + } + # whine mightly about in_atomic if ($line =~ /\bin_atomic\s*\(/) { if ($realfile =~ m@^drivers/@) { -- 2.21.0