aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/coccinelle/tests/odd_ptr_err.cocci
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-11-10 21:11:58 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2015-11-10 21:11:58 -0800
commit5dfe5b2c714a5bea0908c1e00da0e8e00535f55c (patch)
tree421470738aac64e438218da770c2775d1041ca01 /scripts/coccinelle/tests/odd_ptr_err.cocci
parentMerge branch 'kconfig' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild (diff)
parentcoccinelle: Improve checking for missing NULL terminators (diff)
downloadlinux-dev-5dfe5b2c714a5bea0908c1e00da0e8e00535f55c.tar.xz
linux-dev-5dfe5b2c714a5bea0908c1e00da0e8e00535f55c.zip
Merge branch 'misc' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild
Pull misc kbuild updates from Michal Marek: "This is the non-critical part of kbuild: - several coccinelle updates - make deb-pkg creates an armhf package if CONFIG_VFP=y - make tags understands some more powerpc macros" * 'misc' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild: coccinelle: Improve checking for missing NULL terminators coccinelle: ifnullfree: handle various destroy functions coccinelle: ifnullfree: various cleanups cocinelle: iterators: semantic patch to delete unneeded of_node_put deb-pkg: Add automatic support for armhf architecture scripts/coccinelle: fix typos coccinelle: misc: remove "complex return code" warnings Coccinelle: fix incorrect -include option transformation coccinelle: tests: improve odd_ptr_err.cocci coccinelle: misc: move constants to the right scripts/tags.sh: Teach tags about some powerpc macros
Diffstat (limited to 'scripts/coccinelle/tests/odd_ptr_err.cocci')
-rw-r--r--scripts/coccinelle/tests/odd_ptr_err.cocci120
1 files changed, 86 insertions, 34 deletions
diff --git a/scripts/coccinelle/tests/odd_ptr_err.cocci b/scripts/coccinelle/tests/odd_ptr_err.cocci
index cfe0a35cf2dd..dfc6b40c2969 100644
--- a/scripts/coccinelle/tests/odd_ptr_err.cocci
+++ b/scripts/coccinelle/tests/odd_ptr_err.cocci
@@ -1,12 +1,11 @@
/// PTR_ERR should access the value just tested by IS_ERR
-//# There can be false positives in the patch case, where it is the call
+//# There can be false positives in the patch case, where it is the call to
//# IS_ERR that is wrong.
///
// Confidence: High
-// Copyright: (C) 2012 Julia Lawall, INRIA. GPLv2.
-// Copyright: (C) 2012 Gilles Muller, INRIA. GPLv2.
+// Copyright: (C) 2012, 2015 Julia Lawall, INRIA. GPLv2.
+// Copyright: (C) 2012, 2015 Gilles Muller, INRIA. GPLv2.
// URL: http://coccinelle.lip6.fr/
-// Comments:
// Options: --no-includes --include-headers
virtual patch
@@ -14,52 +13,105 @@ virtual context
virtual org
virtual report
-@depends on patch@
-expression e,e1;
+@ok1 exists@
+expression x,e;
+position p;
@@
+if (IS_ERR(x=e) || ...) {
+ <...
+ PTR_ERR@p(x)
+ ...>
+}
+
+@ok2 exists@
+expression x,e1,e2;
+position p;
+@@
+
+if (IS_ERR(x) || ...) {
+ <...
(
-if (IS_ERR(e)) { ... PTR_ERR(e) ... }
+ PTR_ERR@p(\(e1 ? e2 : x\|e1 ? x : e2\))
|
-if (IS_ERR(e=e1)) { ... PTR_ERR(e) ... }
+ PTR_ERR@p(x)
+)
+ ...>
+}
+
+@r1 depends on patch && !context && !org && !report exists@
+expression x,y;
+position p != {ok1.p,ok2.p};
+@@
+
+if (IS_ERR(x) || ...) {
+ ... when any
+ when != IS_ERR(...)
+(
+ PTR_ERR(x)
|
-if (IS_ERR(e))
- { ...
- PTR_ERR(
-- e1
-+ e
+ PTR_ERR@p(
+- y
++ x
)
- ... }
)
+ ... when any
+}
+
+// ----------------------------------------------------------------------------
-@r depends on !patch@
-expression e,e1;
-position p1,p2;
+@r1_context depends on !patch && (context || org || report) exists@
+position p != {ok1.p,ok2.p};
+expression x, y;
+position j0, j1;
@@
+if (IS_ERR@j0(x) || ...) {
+ ... when any
+ when != IS_ERR(...)
(
-if (IS_ERR(e)) { ... PTR_ERR(e) ... }
+ PTR_ERR(x)
|
-if (IS_ERR(e=e1)) { ... PTR_ERR(e) ... }
-|
-*if (IS_ERR@p1(e))
- { ...
-* PTR_ERR@p2(e1)
- ... }
+ PTR_ERR@j1@p(
+ y
+ )
)
+ ... when any
+}
-@script:python depends on org@
-p1 << r.p1;
-p2 << r.p2;
+@r1_disj depends on !patch && (context || org || report) exists@
+position p != {ok1.p,ok2.p};
+expression x, y;
+position r1_context.j0, r1_context.j1;
@@
-cocci.print_main("inconsistent IS_ERR and PTR_ERR",p1)
-cocci.print_secs("PTR_ERR",p2)
+* if (IS_ERR@j0(x) || ...) {
+ ... when any
+ when != IS_ERR(...)
+* PTR_ERR@j1@p(
+ y
+ )
+ ... when any
+}
-@script:python depends on report@
-p1 << r.p1;
-p2 << r.p2;
+// ----------------------------------------------------------------------------
+
+@script:python r1_org depends on org@
+j0 << r1_context.j0;
+j1 << r1_context.j1;
@@
-msg = "inconsistent IS_ERR and PTR_ERR, PTR_ERR on line %s" % (p2[0].line)
-coccilib.report.print_report(p1[0],msg)
+msg = "inconsistent IS_ERR and PTR_ERR"
+coccilib.org.print_todo(j0[0], msg)
+coccilib.org.print_link(j1[0], "")
+
+// ----------------------------------------------------------------------------
+
+@script:python r1_report depends on report@
+j0 << r1_context.j0;
+j1 << r1_context.j1;
+@@
+
+msg = "inconsistent IS_ERR and PTR_ERR on line %s." % (j1[0].line)
+coccilib.report.print_report(j0[0], msg)
+