lists.openwall.net   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  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 19 Dec 2011 14:24:23 +0100
From:	Lars-Peter Clausen <lars@...afoo.de>
To:	Julia Lawall <julia@...u.dk>,
	Gilles Muller <Gilles.Muller@...6.fr>,
	Nicolas Palix <npalix.work@...il.com>
CC:	<cocci@...u.dk>, <linux-kernel@...r.kernel.org>,
	Lars-Peter Clausen <lars@...afoo.de>
Subject: [PATCH 2/2] coccinelle: Add patch for replacing open-coded IS_ERR_OR_NULL

The IS_ERR_OR_NULL function returns true if the passed parameter is either a
ERR_PTR or NULL. This patch adds a semantic patch which finds open-coded
instances of this check and replaces them.

Signed-off-by: Lars-Peter Clausen <lars@...afoo.de>
---
 scripts/coccinelle/api/is_err_or_null.cocci |   98 +++++++++++++++++++++++++++
 1 files changed, 98 insertions(+), 0 deletions(-)
 create mode 100644 scripts/coccinelle/api/is_err_or_null.cocci

diff --git a/scripts/coccinelle/api/is_err_or_null.cocci b/scripts/coccinelle/api/is_err_or_null.cocci
new file mode 100644
index 0000000..04afd1e
--- /dev/null
+++ b/scripts/coccinelle/api/is_err_or_null.cocci
@@ -0,0 +1,98 @@
+///
+/// Use IS_ERR_OR_NULL function instead of open coding it
+///
+// Confidence: High
+// Options:
+//
+// Keywords: IS_ERR, IS_ERR_OR_NULL
+// Version min: 2.6.33
+//
+
+virtual context
+virtual patch
+virtual org
+virtual report
+
+// Since the logical or operator by itself is not commutative we need rules for
+// both cases as well as for their De Morgan equivalents.
+
+@...ends on context@
+expression x;
+@@
+*(IS_ERR(x) || !x)
+
+@...ends on context@
+expression x;
+@@
+*(!x || IS_ERR(x))
+
+@...ends on context@
+expression x;
+@@
+*(!IS_ERR(x) && x)
+
+@...ends on context@
+expression x;
+@@
+*(x && !IS_ERR(x))
+
+@...ends on patch@
+expression x;
+@@
+-(IS_ERR(x) || !x)
++IS_ERR_OR_NULL(x)
+
+@...ends on patch@
+expression x;
+@@
+-(!x || IS_ERR(x))
++IS_ERR_OR_NULL(x)
+
+@...ends on patch@
+expression x;
+@@
+-(!IS_ERR(x) && x)
++ !IS_ERR_OR_NULL(x)
+
+@...ends on patch@
+expression x;
+@@
+-(x && !IS_ERR(x))
++ !IS_ERR_OR_NULL(x)
+
+@r depends on org || report@
+expression x;
+position p;
+statement S;
+@@
+// We'll probably miss some some cases with this, but the if gives us an anchor
+// and we do not have to write a indivual rule for each case. patch and context
+// mode will report all cases
+ if(@p
+(
+ IS_ERR(x) || !x
+|
+ !x || IS_ERR(x)
+|
+ !IS_ERR(x) && x
+|
+ x && !IS_ERR(x)
+)
+ ) S
+
+@...ipt:python depends on org@
+p << r.p;
+x << r.x;
+@@
+
+msg="IS_ERR_OR_NULL can be used with %s" % (x)
+msg_safe=msg.replace("[","@(").replace("]",")")
+coccilib.org.print_todo(p[0], msg_safe)
+
+@...ipt:python depends on report@
+p << r.p;
+x << r.x;
+@@
+
+msg="IS_ERR_OR_NULL can be used with %s" % (x)
+coccilib.report.print_report(p[0], msg)
-- 
1.7.7.3


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ