lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  PHC 
Open Source and information security mailing list archives
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 14 May 2013 03:41:37 +0300
From:	Ruslan Bilovol <>
Subject: [PATCH] checkpatch: add check for wrong "if (IS_ERR_OR_NULL(<foo>)) return PTR_ERR(<foo>)" uses

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.

Quoting Russell:
| Well, the whole reasoning here is that IS_ERR_OR_NULL() is far too easy
| to get wrong - there are too many of this kind of crap in the kernel:
| 	foo = some_func();
| 	if (IS_ERR_OR_NULL(foo))
| 		return PTR_ERR(foo);
| which is wrong, because if foo _is_ NULL, the function doesn't return an
| error, it returns success instead.  Of course, if some_func() never ever
| returns NULL in the first place, that can't happen, but then the additional
| test there for a NULL pointer is, to put it bluntly, total bollocks.

The full discussion may be found here:

Tested on:
+	if (IS_ERR_OR_NULL(soc_dev))
+		return PTR_ERR(soc_dev);
+	if (IS_ERR_OR_NULL(soc_dev))
+		return soc_dev ? PTR_ERR(soc_dev) : -ENODEV;

The result is:

WARNING: Use of IS_ERR_OR_NULL is usually wrong: see
+	if (IS_ERR_OR_NULL(soc_dev))
+		return PTR_ERR(soc_dev);

Signed-off-by: Ruslan Bilovol <>

I'm not very experienced in the perl, so feel free to
comment this patch or fix it :)

 scripts/ |    9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/scripts/ b/scripts/
index b954de5..6ec71bd 100755
--- a/scripts/
+++ b/scripts/
@@ -3262,6 +3262,15 @@ sub process {
+# check for wrong "if (IS_ERR_OR_NULL(<foo>)) return PTR_ERR(<foo>)" uses
+		if ($prevline =~ /\bif\s*\(\s*IS_ERR_OR_NULL\s*\(\s*($Lval)\s*\)\s*\)/) {
+			my $expr = '\s*\(\s*' . quotemeta($1) . '\s*\)\s*;';
+			if ($line =~ /\b(\s*PTR_ERR)$expr/) {
+				     "Use of IS_ERR_OR_NULL is usually wrong: see\n" . $hereprev);
+			}
+		}
 # prefer usleep_range over udelay
 		if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) {
 			# ignore udelay's < 10, however

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

Powered by blists - more mailing lists