mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Ruslan Bilovol <ruslan.bilovol@ti.com>
Cc: apw@canonical.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] checkpatch: add check for wrong "if (IS_ERR_OR_NULL(<foo>)) return PTR_ERR(<foo>)" uses
Date: Mon, 13 May 2013 21:36:50 -0700	[thread overview]
Message-ID: <1368506210.17660.11.camel@joe-AO722> (raw)
In-Reply-To: <1368492098-3140-1-git-send-email-ruslan.bilovol@ti.com>

On Tue, 2013-05-14 at 03:41 +0300, Ruslan Bilovol wrote:
> This was many times discussed by Russell King
> and I also was about wrong usage of IS_ERR_OR_NULL()
> in my patch. So I added this check and other people will
> be at least warned about potentially wrong usage
> of mentioned macro.
[]
> Tested on:
> +	if (IS_ERR_OR_NULL(soc_dev))
> +		return PTR_ERR(soc_dev);
> +
> +	if (IS_ERR_OR_NULL(soc_dev))en
> +		return soc_dev ? PTR_ERR(soc_dev) : -ENODEV;

I did a grep for IS_ERR_OR_NULL and this misses variants like:

		if (unlikely(IS_ERR_OR_NULL(etc...

Perhaps something like this?
---
 scripts/checkpatch.pl | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index b954de5..18c7d8c 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2184,6 +2184,15 @@ sub process {
 				WARN("SUSPECT_CODE_INDENT",
 				     "suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n");
 			}
+
+# check for misuses of IS_ERR_OR_NULL
+			if ($stat =~ /^\+.*\bIS_ERR_OR_NULL\s*\(\s*($Lval)\s*\)/) {
+				my $test = $1;
+				if ($stat =~ /\bPTR_ERR\s*\(\s*${test}\s*\)/) {
+					WARN("IS_ERR_OR_NULL",
+					     "Use of IS_ERR_OR_NULL($test) with PTR_ERR($test) is usually wrong: see http://permalink.gmane.org/gmane.linux.ports.arm.omap/97874\n" . $herecurr . "$stat_real\n");
+				}
+			}
 		}
 
 		# Track the 'values' across context and added lines.



  reply	other threads:[~2013-05-14  4:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-14  0:41 Ruslan Bilovol
2013-05-14  4:36 ` Joe Perches [this message]
2013-05-23 13:10   ` Ruslan Bilovol

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=1368506210.17660.11.camel@joe-AO722 \
    --to=joe@perches.com \
    --cc=apw@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ruslan.bilovol@ti.com \
    /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®