mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Denis Efremov <efremov@linux.com>, Andy Whitcroft <apw@canonical.com>
Cc: linux-kernel@vger.kernel.org, Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] checkpatch: check for nested (un)?likely calls
Date: Tue, 27 Aug 2019 10:21:01 -0700	[thread overview]
Message-ID: <94f293d3d31e9f686e601e2e3c972ae371a40585.camel@perches.com> (raw)
In-Reply-To: <20190827165515.21668-1-efremov@linux.com>

On Tue, 2019-08-27 at 19:55 +0300, Denis Efremov wrote:
> 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/
[]
> diff --git 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);
> +		}
> +

Couple things:

1:

Are you going to submit patches for the just 10 instances that exist?

$ git grep -P -n '\b(?:(?:un)?likely)\s*\(!?\s*(IS_ERR(?:_OR_NULL|_VALUE)?)\s*\([^\)]+\)\s*\)'
arch/x86/kernel/irq.c:246:      if (likely(!IS_ERR_OR_NULL(desc))) {
drivers/infiniband/hw/hfi1/verbs.c:1044:        if (unlikely(IS_ERR_OR_NULL(pbuf))) {
drivers/input/mouse/alps.c:1479:        } else if (unlikely(IS_ERR_OR_NULL(priv->dev3))) {
fs/ntfs/mft.c:74:       if (likely(!IS_ERR(page))) {
fs/ntfs/mft.c:157:      if (likely(!IS_ERR(m)))
fs/ntfs/mft.c:274:              if (likely(!IS_ERR(m))) {
fs/ntfs/mft.c:1779:             if (likely(!IS_ERR(rl2)))
fs/ntfs/namei.c:118:            if (likely(!IS_ERR(dent_inode))) {
fs/ntfs/runlist.c:954:  if (likely(!IS_ERR(old_rl)))
include/net/udp.h:483:  if (unlikely(IS_ERR_OR_NULL(segs))) {

2:

This will not warn about code like:

fs/ntfs/mft.c:  if (unlikely(IS_ERR(rl) || !rl->length || rl->lcn < 0)) {

that could probably be better written as:

		if (IS_ERR(rl) || unlikely(!rl->length || rl->lcn < 0)) {



  reply	other threads:[~2019-08-27 17:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-27 16:55 Denis Efremov
2019-08-27 17:21 ` Joe Perches [this message]
2019-08-27 17:32   ` Denis Efremov
2019-08-28 13:32 ` [PATCH v2] checkpatch: check for nested unlikely calls Denis Efremov
2019-08-28 15:36   ` Denis Efremov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=94f293d3d31e9f686e601e2e3c972ae371a40585.camel@perches.com \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=apw@canonical.com \
    --cc=efremov@linux.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®