aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/coccinelle
diff options
context:
space:
mode:
authorJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
committerJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
commit8dea78da5cee153b8af9c07a2745f6c55057fe12 (patch)
treea8f4d49d63b1ecc92f2fddceba0655b2472c5bd9 /scripts/coccinelle
parent406089d01562f1e2bf9f089fd7637009ebaad589 (diff)
Patched in Tegra support.
Diffstat (limited to 'scripts/coccinelle')
-rw-r--r--scripts/coccinelle/api/d_find_alias.cocci80
-rw-r--r--scripts/coccinelle/api/devm_request_and_ioremap.cocci105
-rw-r--r--scripts/coccinelle/api/kstrdup.cocci75
-rw-r--r--scripts/coccinelle/api/memdup.cocci34
-rw-r--r--scripts/coccinelle/api/memdup_user.cocci39
-rw-r--r--scripts/coccinelle/api/ptr_ret.cocci96
-rw-r--r--scripts/coccinelle/api/simple_open.cocci70
-rw-r--r--scripts/coccinelle/free/clk_put.cocci67
-rw-r--r--scripts/coccinelle/free/devm_free.cocci71
-rw-r--r--scripts/coccinelle/free/iounmap.cocci67
-rw-r--r--scripts/coccinelle/free/kfree.cocci14
-rw-r--r--scripts/coccinelle/iterators/fen.cocci73
-rw-r--r--scripts/coccinelle/iterators/itnull.cocci54
-rw-r--r--scripts/coccinelle/iterators/use_after_iter.cocci147
-rw-r--r--scripts/coccinelle/locks/call_kern.cocci67
-rw-r--r--scripts/coccinelle/locks/flags.cocci12
-rw-r--r--scripts/coccinelle/locks/mini_lock.cocci15
-rw-r--r--scripts/coccinelle/misc/boolinit.cocci178
-rw-r--r--scripts/coccinelle/misc/cstptr.cocci41
-rw-r--r--scripts/coccinelle/misc/doubleinit.cocci8
-rw-r--r--scripts/coccinelle/misc/ifaddr.cocci35
-rw-r--r--scripts/coccinelle/misc/irqf_oneshot.cocci65
-rw-r--r--scripts/coccinelle/misc/noderef.cocci65
-rw-r--r--scripts/coccinelle/misc/warn.cocci109
-rw-r--r--scripts/coccinelle/null/badzero.cocci237
-rw-r--r--scripts/coccinelle/null/eno.cocci36
-rw-r--r--scripts/coccinelle/tests/odd_ptr_err.cocci65
27 files changed, 76 insertions, 1849 deletions
diff --git a/scripts/coccinelle/api/d_find_alias.cocci b/scripts/coccinelle/api/d_find_alias.cocci
deleted file mode 100644
index a9694a8d3e5..00000000000
--- a/scripts/coccinelle/api/d_find_alias.cocci
+++ /dev/null
@@ -1,80 +0,0 @@
1/// Make sure calls to d_find_alias() have a corresponding call to dput().
2//
3// Keywords: d_find_alias, dput
4//
5// Confidence: Moderate
6// URL: http://coccinelle.lip6.fr/
7// Options: -include_headers
8
9virtual context
10virtual org
11virtual patch
12virtual report
13
14@r exists@
15local idexpression struct dentry *dent;
16expression E, E1;
17statement S1, S2;
18position p1, p2;
19@@
20(
21 if (!(dent@p1 = d_find_alias(...))) S1
22|
23 dent@p1 = d_find_alias(...)
24)
25
26<...when != dput(dent)
27 when != if (...) { <+... dput(dent) ...+> }
28 when != true !dent || ...
29 when != dent = E
30 when != E = dent
31if (!dent || ...) S2
32...>
33(
34 return <+...dent...+>;
35|
36 return @p2 ...;
37|
38 dent@p2 = E1;
39|
40 E1 = dent;
41)
42
43@depends on context@
44local idexpression struct dentry *r.dent;
45position r.p1,r.p2;
46@@
47* dent@p1 = ...
48 ...
49(
50* return@p2 ...;
51|
52* dent@p2
53)
54
55
56@script:python depends on org@
57p1 << r.p1;
58p2 << r.p2;
59@@
60cocci.print_main("Missing call to dput()",p1)
61cocci.print_secs("",p2)
62
63@depends on patch@
64local idexpression struct dentry *r.dent;
65position r.p2;
66@@
67(
68+ dput(dent);
69 return @p2 ...;
70|
71+ dput(dent);
72 dent@p2 = ...;
73)
74
75@script:python depends on report@
76p1 << r.p1;
77p2 << r.p2;
78@@
79msg = "Missing call to dput() at line %s."
80coccilib.report.print_report(p1[0], msg % (p2[0].line))
diff --git a/scripts/coccinelle/api/devm_request_and_ioremap.cocci b/scripts/coccinelle/api/devm_request_and_ioremap.cocci
deleted file mode 100644
index 46beb81406a..00000000000
--- a/scripts/coccinelle/api/devm_request_and_ioremap.cocci
+++ /dev/null
@@ -1,105 +0,0 @@
1/// Reimplement a call to devm_request_mem_region followed by a call to ioremap
2/// or ioremap_nocache by a call to devm_request_and_ioremap.
3/// Devm_request_and_ioremap was introduced in
4/// 72f8c0bfa0de64c68ee59f40eb9b2683bffffbb0. It makes the code much more
5/// concise.
6///
7///
8// Confidence: High
9// Copyright: (C) 2011 Julia Lawall, INRIA/LIP6. GPLv2.
10// Copyright: (C) 2011 Gilles Muller, INRIA/LiP6. GPLv2.
11// URL: http://coccinelle.lip6.fr/
12// Comments:
13// Options: -no_includes -include_headers
14
15virtual patch
16virtual org
17virtual report
18virtual context
19
20@nm@
21expression myname;
22identifier i;
23@@
24
25struct platform_driver i = { .driver = { .name = myname } };
26
27@depends on patch@
28expression dev,res,size;
29@@
30
31-if (!devm_request_mem_region(dev, res->start, size,
32- \(res->name\|dev_name(dev)\))) {
33- ...
34- return ...;
35-}
36... when != res->start
37(
38-devm_ioremap(dev,res->start,size)
39+devm_request_and_ioremap(dev,res)
40|
41-devm_ioremap_nocache(dev,res->start,size)
42+devm_request_and_ioremap(dev,res)
43)
44... when any
45 when != res->start
46
47// this rule is separate from the previous one, because a single file can
48// have multiple values of myname
49@depends on patch@
50expression dev,res,size;
51expression nm.myname;
52@@
53
54-if (!devm_request_mem_region(dev, res->start, size,myname)) {
55- ...
56- return ...;
57-}
58... when != res->start
59(
60-devm_ioremap(dev,res->start,size)
61+devm_request_and_ioremap(dev,res)
62|
63-devm_ioremap_nocache(dev,res->start,size)
64+devm_request_and_ioremap(dev,res)
65)
66... when any
67 when != res->start
68
69
70@pb depends on org || report || context@
71expression dev,res,size;
72expression nm.myname;
73position p1,p2;
74@@
75
76*if
77 (!devm_request_mem_region@p1(dev, res->start, size,
78 \(res->name\|dev_name(dev)\|myname\))) {
79 ...
80 return ...;
81}
82... when != res->start
83(
84*devm_ioremap@p2(dev,res->start,size)
85|
86*devm_ioremap_nocache@p2(dev,res->start,size)
87)
88... when any
89 when != res->start
90
91@script:python depends on org@
92p1 << pb.p1;
93p2 << pb.p2;
94@@
95
96cocci.print_main("INFO: replace by devm_request_and_ioremap",p1)
97cocci.print_secs("",p2)
98
99@script:python depends on report@
100p1 << pb.p1;
101p2 << pb.p2;
102@@
103
104msg = "INFO: devm_request_mem_region followed by ioremap on line %s can be replaced by devm_request_and_ioremap" % (p2[0].line)
105coccilib.report.print_report(p1[0],msg)
diff --git a/scripts/coccinelle/api/kstrdup.cocci b/scripts/coccinelle/api/kstrdup.cocci
index 07a74b2c619..e0805ad08d3 100644
--- a/scripts/coccinelle/api/kstrdup.cocci
+++ b/scripts/coccinelle/api/kstrdup.cocci
@@ -1,19 +1,16 @@
1/// Use kstrdup rather than duplicating its implementation 1/// Use kstrdup rather than duplicating its implementation
2/// 2///
3// Confidence: High 3// Confidence: High
4// Copyright: (C) 2010-2012 Nicolas Palix. GPLv2. 4// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.
5// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. GPLv2. 5// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.
6// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2. 6// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
7// URL: http://coccinelle.lip6.fr/ 7// URL: http://coccinelle.lip6.fr/
8// Comments: 8// Comments:
9// Options: -no_includes -include_headers 9// Options: -no_includes -include_headers
10 10
11virtual patch 11virtual patch
12virtual context
13virtual org
14virtual report
15 12
16@depends on patch@ 13@@
17expression from,to; 14expression from,to;
18expression flag,E1,E2; 15expression flag,E1,E2;
19statement S; 16statement S;
@@ -26,7 +23,7 @@ statement S;
26 ... when != \(from = E2 \| to = E2 \) 23 ... when != \(from = E2 \| to = E2 \)
27- strcpy(to, from); 24- strcpy(to, from);
28 25
29@depends on patch@ 26@@
30expression x,from,to; 27expression x,from,to;
31expression flag,E1,E2,E3; 28expression flag,E1,E2,E3;
32statement S; 29statement S;
@@ -40,65 +37,3 @@ statement S;
40 if (to==NULL || ...) S 37 if (to==NULL || ...) S
41 ... when != \(x = E3 \| from = E3 \| to = E3 \) 38 ... when != \(x = E3 \| from = E3 \| to = E3 \)
42- memcpy(to, from, x); 39- memcpy(to, from, x);
43
44// ---------------------------------------------------------------------
45
46@r1 depends on !patch exists@
47expression from,to;
48expression flag,E1,E2;
49statement S;
50position p1,p2;
51@@
52
53* to = kmalloc@p1(strlen(from) + 1,flag);
54 ... when != \(from = E1 \| to = E1 \)
55 if (to==NULL || ...) S
56 ... when != \(from = E2 \| to = E2 \)
57* strcpy@p2(to, from);
58
59@r2 depends on !patch exists@
60expression x,from,to;
61expression flag,E1,E2,E3;
62statement S;
63position p1,p2;
64@@
65
66* x = strlen(from) + 1;
67 ... when != \( x = E1 \| from = E1 \)
68* to = \(kmalloc@p1\|kzalloc@p2\)(x,flag);
69 ... when != \(x = E2 \| from = E2 \| to = E2 \)
70 if (to==NULL || ...) S
71 ... when != \(x = E3 \| from = E3 \| to = E3 \)
72* memcpy@p2(to, from, x);
73
74@script:python depends on org@
75p1 << r1.p1;
76p2 << r1.p2;
77@@
78
79cocci.print_main("WARNING opportunity for kstrdep",p1)
80cocci.print_secs("strcpy",p2)
81
82@script:python depends on org@
83p1 << r2.p1;
84p2 << r2.p2;
85@@
86
87cocci.print_main("WARNING opportunity for kstrdep",p1)
88cocci.print_secs("memcpy",p2)
89
90@script:python depends on report@
91p1 << r1.p1;
92p2 << r1.p2;
93@@
94
95msg = "WARNING opportunity for kstrdep (strcpy on line %s)" % (p2[0].line)
96coccilib.report.print_report(p1[0], msg)
97
98@script:python depends on report@
99p1 << r2.p1;
100p2 << r2.p2;
101@@
102
103msg = "WARNING opportunity for kstrdep (memcpy on line %s)" % (p2[0].line)
104coccilib.report.print_report(p1[0], msg)
diff --git a/scripts/coccinelle/api/memdup.cocci b/scripts/coccinelle/api/memdup.cocci
index 4dceab6d54d..b5d722077dc 100644
--- a/scripts/coccinelle/api/memdup.cocci
+++ b/scripts/coccinelle/api/memdup.cocci
@@ -1,17 +1,14 @@
1/// Use kmemdup rather than duplicating its implementation 1/// Use kmemdup rather than duplicating its implementation
2/// 2///
3// Confidence: High 3// Confidence: High
4// Copyright: (C) 2010-2012 Nicolas Palix. GPLv2. 4// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.
5// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. GPLv2. 5// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.
6// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2. 6// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
7// URL: http://coccinelle.lip6.fr/ 7// URL: http://coccinelle.lip6.fr/
8// Comments: 8// Comments:
9// Options: -no_includes -include_headers 9// Options: -no_includes -include_headers
10 10
11virtual patch 11virtual patch
12virtual context
13virtual org
14virtual report
15 12
16@r1@ 13@r1@
17expression from,to; 14expression from,to;
@@ -31,7 +28,7 @@ position p;
31 ... when != \( x = E1 \| from = E1 \) 28 ... when != \( x = E1 \| from = E1 \)
32 to = \(kmalloc@p\|kzalloc@p\)(x,flag); 29 to = \(kmalloc@p\|kzalloc@p\)(x,flag);
33 30
34@depends on patch@ 31@@
35expression from,to,size,flag; 32expression from,to,size,flag;
36position p != {r1.p,r2.p}; 33position p != {r1.p,r2.p};
37statement S; 34statement S;
@@ -41,26 +38,3 @@ statement S;
41+ to = kmemdup(from,size,flag); 38+ to = kmemdup(from,size,flag);
42 if (to==NULL || ...) S 39 if (to==NULL || ...) S
43- memcpy(to, from, size); 40- memcpy(to, from, size);
44
45@r depends on !patch@
46expression from,to,size,flag;
47position p != {r1.p,r2.p};
48statement S;
49@@
50
51* to = \(kmalloc@p\|kzalloc@p\)(size,flag);
52 to = kmemdup(from,size,flag);
53 if (to==NULL || ...) S
54* memcpy(to, from, size);
55
56@script:python depends on org@
57p << r.p;
58@@
59
60coccilib.org.print_todo(p[0], "WARNING opportunity for kmemdep")
61
62@script:python depends on report@
63p << r.p;
64@@
65
66coccilib.report.print_report(p[0], "WARNING opportunity for kmemdep")
diff --git a/scripts/coccinelle/api/memdup_user.cocci b/scripts/coccinelle/api/memdup_user.cocci
index 2b131a8a130..72ce012e878 100644
--- a/scripts/coccinelle/api/memdup_user.cocci
+++ b/scripts/coccinelle/api/memdup_user.cocci
@@ -1,25 +1,23 @@
1/// Use memdup_user rather than duplicating its implementation 1/// Use kmemdup_user rather than duplicating its implementation
2/// This is a little bit restricted to reduce false positives 2/// This is a little bit restricted to reduce false positives
3/// 3///
4// Confidence: High 4// Confidence: High
5// Copyright: (C) 2010-2012 Nicolas Palix. GPLv2. 5// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.
6// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. GPLv2. 6// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.
7// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2. 7// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
8// URL: http://coccinelle.lip6.fr/ 8// URL: http://coccinelle.lip6.fr/
9// Comments: 9// Comments:
10// Options: -no_includes -include_headers 10// Options: -no_includes -include_headers
11 11
12virtual patch 12virtual patch
13virtual context
14virtual org
15virtual report
16 13
17@depends on patch@ 14@@
18expression from,to,size,flag; 15expression from,to,size,flag;
16position p;
19identifier l1,l2; 17identifier l1,l2;
20@@ 18@@
21 19
22- to = \(kmalloc\|kzalloc\)(size,flag); 20- to = \(kmalloc@p\|kzalloc@p\)(size,flag);
23+ to = memdup_user(from,size); 21+ to = memdup_user(from,size);
24 if ( 22 if (
25- to==NULL 23- to==NULL
@@ -35,26 +33,3 @@ identifier l1,l2;
35- -EFAULT 33- -EFAULT
36- ...+> 34- ...+>
37- } 35- }
38
39@r depends on !patch@
40expression from,to,size,flag;
41position p;
42statement S1,S2;
43@@
44
45* to = \(kmalloc@p\|kzalloc@p\)(size,flag);
46 if (to==NULL || ...) S1
47 if (copy_from_user(to, from, size) != 0)
48 S2
49
50@script:python depends on org@
51p << r.p;
52@@
53
54coccilib.org.print_todo(p[0], "WARNING opportunity for memdup_user")
55
56@script:python depends on report@
57p << r.p;
58@@
59
60coccilib.report.print_report(p[0], "WARNING opportunity for memdup_user")
diff --git a/scripts/coccinelle/api/ptr_ret.cocci b/scripts/coccinelle/api/ptr_ret.cocci
deleted file mode 100644
index 15f076fdecb..00000000000
--- a/scripts/coccinelle/api/ptr_ret.cocci
+++ /dev/null
@@ -1,96 +0,0 @@
1///
2/// Use PTR_RET rather than if(IS_ERR(...)) + PTR_ERR
3///
4// Confidence: High
5// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
6// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
7// URL: http://coccinelle.lip6.fr/
8// Options: -no_includes -include_headers
9//
10// Keywords: ERR_PTR, PTR_ERR, PTR_RET
11// Version min: 2.6.39
12//
13
14virtual context
15virtual patch
16virtual org
17virtual report
18
19@depends on patch@
20expression ptr;
21@@
22
23- if (IS_ERR(ptr)) return PTR_ERR(ptr); else return 0;
24+ return PTR_RET(ptr);
25
26@depends on patch@
27expression ptr;
28@@
29
30- if (IS_ERR(ptr)) return PTR_ERR(ptr); return 0;
31+ return PTR_RET(ptr);
32
33@depends on patch@
34expression ptr;
35@@
36
37- (IS_ERR(ptr) ? PTR_ERR(ptr) : 0)
38+ PTR_RET(ptr)
39
40@r1 depends on !patch@
41expression ptr;
42position p1;
43@@
44
45* if@p1 (IS_ERR(ptr)) return PTR_ERR(ptr); else return 0;
46
47@r2 depends on !patch@
48expression ptr;
49position p2;
50@@
51
52* if@p2 (IS_ERR(ptr)) return PTR_ERR(ptr); return 0;
53
54@r3 depends on !patch@
55expression ptr;
56position p3;
57@@
58
59* IS_ERR@p3(ptr) ? PTR_ERR(ptr) : 0
60
61@script:python depends on org@
62p << r1.p1;
63@@
64
65coccilib.org.print_todo(p[0], "WARNING: PTR_RET can be used")
66
67
68@script:python depends on org@
69p << r2.p2;
70@@
71
72coccilib.org.print_todo(p[0], "WARNING: PTR_RET can be used")
73
74@script:python depends on org@
75p << r3.p3;
76@@
77
78coccilib.org.print_todo(p[0], "WARNING: PTR_RET can be used")
79
80@script:python depends on report@
81p << r1.p1;
82@@
83
84coccilib.report.print_report(p[0], "WARNING: PTR_RET can be used")
85
86@script:python depends on report@
87p << r2.p2;
88@@
89
90coccilib.report.print_report(p[0], "WARNING: PTR_RET can be used")
91
92@script:python depends on report@
93p << r3.p3;
94@@
95
96coccilib.report.print_report(p[0], "WARNING: PTR_RET can be used")
diff --git a/scripts/coccinelle/api/simple_open.cocci b/scripts/coccinelle/api/simple_open.cocci
deleted file mode 100644
index 05962f7be15..00000000000
--- a/scripts/coccinelle/api/simple_open.cocci
+++ /dev/null
@@ -1,70 +0,0 @@
1/// This removes an open coded simple_open() function
2/// and replaces file operations references to the function
3/// with simple_open() instead.
4///
5// Confidence: High
6// Comments:
7// Options: -no_includes -include_headers
8
9virtual patch
10virtual report
11
12@ open depends on patch @
13identifier open_f != simple_open;
14identifier i, f;
15@@
16-int open_f(struct inode *i, struct file *f)
17-{
18(
19-if (i->i_private)
20-f->private_data = i->i_private;
21|
22-f->private_data = i->i_private;
23)
24-return 0;
25-}
26
27@ has_open depends on open @
28identifier fops;
29identifier open.open_f;
30@@
31struct file_operations fops = {
32...,
33-.open = open_f,
34+.open = simple_open,
35...
36};
37
38@ openr depends on report @
39identifier open_f != simple_open;
40identifier i, f;
41position p;
42@@
43int open_f@p(struct inode *i, struct file *f)
44{
45(
46if (i->i_private)
47f->private_data = i->i_private;
48|
49f->private_data = i->i_private;
50)
51return 0;
52}
53
54@ has_openr depends on openr @
55identifier fops;
56identifier openr.open_f;
57position p;
58@@
59struct file_operations fops = {
60...,
61.open = open_f@p,
62...
63};
64
65@script:python@
66pf << openr.p;
67ps << has_openr.p;
68@@
69
70coccilib.report.print_report(pf[0],"WARNING opportunity for simple_open, see also structure on line %s"%(ps[0].line))
diff --git a/scripts/coccinelle/free/clk_put.cocci b/scripts/coccinelle/free/clk_put.cocci
deleted file mode 100644
index 46747adfd20..00000000000
--- a/scripts/coccinelle/free/clk_put.cocci
+++ /dev/null
@@ -1,67 +0,0 @@
1/// Find missing clk_puts.
2///
3//# This only signals a missing clk_put when there is a clk_put later
4//# in the same function.
5//# False positives can be due to loops.
6//
7// Confidence: Moderate
8// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
9// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
10// URL: http://coccinelle.lip6.fr/
11// Comments:
12// Options:
13
14virtual context
15virtual org
16virtual report
17
18@clk@
19expression e;
20statement S,S1;
21int ret;
22position p1,p2,p3;
23@@
24
25e = clk_get@p1(...)
26... when != clk_put(e)
27if (<+...e...+>) S
28... when any
29 when != clk_put(e)
30 when != if (...) { ... clk_put(e); ... }
31(
32 if (ret == 0) S1
33|
34if (...)
35 { ...
36 return 0; }
37|
38if (...)
39 { ...
40 return <+...e...+>; }
41|
42*if@p2 (...)
43 { ... when != clk_put(e)
44 when forall
45 return@p3 ...; }
46)
47... when any
48clk_put(e);
49
50@script:python depends on org@
51p1 << clk.p1;
52p2 << clk.p2;
53p3 << clk.p3;
54@@
55
56cocci.print_main("clk_get",p1)
57cocci.print_secs("if",p2)
58cocci.print_secs("needed clk_put",p3)
59
60@script:python depends on report@
61p1 << clk.p1;
62p2 << clk.p2;
63p3 << clk.p3;
64@@
65
66msg = "ERROR: missing clk_put; clk_get on line %s and execution via conditional on line %s" % (p1[0].line,p2[0].line)
67coccilib.report.print_report(p3[0],msg)
diff --git a/scripts/coccinelle/free/devm_free.cocci b/scripts/coccinelle/free/devm_free.cocci
deleted file mode 100644
index 0a1e36146d7..00000000000
--- a/scripts/coccinelle/free/devm_free.cocci
+++ /dev/null
@@ -1,71 +0,0 @@
1/// Find uses of standard freeing functons on values allocated using devm_
2/// functions. Values allocated using the devm_functions are freed when
3/// the device is detached, and thus the use of the standard freeing
4/// function would cause a double free.
5/// See Documentation/driver-model/devres.txt for more information.
6///
7/// A difficulty of detecting this problem is that the standard freeing
8/// function might be called from a different function than the one
9/// containing the allocation function. It is thus necessary to make the
10/// connection between the allocation function and the freeing function.
11/// Here this is done using the specific argument text, which is prone to
12/// false positives. There is no rule for the request_region and
13/// request_mem_region variants because this heuristic seems to be a bit
14/// less reliable in these cases.
15///
16// Confidence: Moderate
17// Copyright: (C) 2011 Julia Lawall, INRIA/LIP6. GPLv2.
18// Copyright: (C) 2011 Gilles Muller, INRIA/LiP6. GPLv2.
19// URL: http://coccinelle.lip6.fr/
20// Comments:
21// Options: -no_includes -include_headers
22
23virtual org
24virtual report
25virtual context
26
27@r depends on context || org || report@
28expression x;
29@@
30
31(
32 x = devm_kzalloc(...)
33|
34 x = devm_request_irq(...)
35|
36 x = devm_ioremap(...)
37|
38 x = devm_ioremap_nocache(...)
39|
40 x = devm_ioport_map(...)
41)
42
43@pb@
44expression r.x;
45position p;
46@@
47
48(
49* kfree@p(x)
50|
51* free_irq@p(x)
52|
53* iounmap@p(x)
54|
55* ioport_unmap@p(x)
56)
57
58@script:python depends on org@
59p << pb.p;
60@@
61
62msg="WARNING: invalid free of devm_ allocated data"
63coccilib.org.print_todo(p[0], msg)
64
65@script:python depends on report@
66p << pb.p;
67@@
68
69msg="WARNING: invalid free of devm_ allocated data"
70coccilib.report.print_report(p[0], msg)
71
diff --git a/scripts/coccinelle/free/iounmap.cocci b/scripts/coccinelle/free/iounmap.cocci
deleted file mode 100644
index 5384f4ba119..00000000000
--- a/scripts/coccinelle/free/iounmap.cocci
+++ /dev/null
@@ -1,67 +0,0 @@
1/// Find missing iounmaps.
2///
3//# This only signals a missing iounmap when there is an iounmap later
4//# in the same function.
5//# False positives can be due to loops.
6//
7// Confidence: Moderate
8// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
9// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
10// URL: http://coccinelle.lip6.fr/
11// Comments:
12// Options:
13
14virtual context
15virtual org
16virtual report
17
18@iom@
19expression e;
20statement S,S1;
21int ret;
22position p1,p2,p3;
23@@
24
25e = \(ioremap@p1\|ioremap_nocache@p1\)(...)
26... when != iounmap(e)
27if (<+...e...+>) S
28... when any
29 when != iounmap(e)
30 when != if (...) { ... iounmap(e); ... }
31(
32 if (ret == 0) S1
33|
34if (...)
35 { ...
36 return 0; }
37|
38if (...)
39 { ...
40 return <+...e...+>; }
41|
42*if@p2 (...)
43 { ... when != iounmap(e)
44 when forall
45 return@p3 ...; }
46)
47... when any
48iounmap(e);
49
50@script:python depends on org@
51p1 << iom.p1;
52p2 << iom.p2;
53p3 << iom.p3;
54@@
55
56cocci.print_main("ioremap",p1)
57cocci.print_secs("if",p2)
58cocci.print_secs("needed iounmap",p3)
59
60@script:python depends on report@
61p1 << iom.p1;
62p2 << iom.p2;
63p3 << iom.p3;
64@@
65
66msg = "ERROR: missing iounmap; ioremap on line %s and execution via conditional on line %s" % (p1[0].line,p2[0].line)
67coccilib.report.print_report(p3[0],msg)
diff --git a/scripts/coccinelle/free/kfree.cocci b/scripts/coccinelle/free/kfree.cocci
index d9ae6d89c2f..f9f79d9245e 100644
--- a/scripts/coccinelle/free/kfree.cocci
+++ b/scripts/coccinelle/free/kfree.cocci
@@ -5,9 +5,9 @@
5//# SCTP_DBG_OBJCNT_DEC that do not actually evaluate their argument 5//# SCTP_DBG_OBJCNT_DEC that do not actually evaluate their argument
6/// 6///
7// Confidence: Moderate 7// Confidence: Moderate
8// Copyright: (C) 2010-2012 Nicolas Palix. GPLv2. 8// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.
9// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. GPLv2. 9// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.
10// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2. 10// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
11// URL: http://coccinelle.lip6.fr/ 11// URL: http://coccinelle.lip6.fr/
12// Comments: 12// Comments:
13// Options: -no_includes -include_headers 13// Options: -no_includes -include_headers
@@ -23,7 +23,7 @@ position p1;
23kfree@p1(E) 23kfree@p1(E)
24 24
25@print expression@ 25@print expression@
26constant char [] c; 26constant char *c;
27expression free.E,E2; 27expression free.E,E2;
28type T; 28type T;
29position p; 29position p;
@@ -37,10 +37,6 @@ identifier f;
37| 37|
38 E@p != E2 38 E@p != E2
39| 39|
40 E2 == E@p
41|
42 E2 != E@p
43|
44 !E@p 40 !E@p
45| 41|
46 E@p || ... 42 E@p || ...
@@ -117,5 +113,5 @@ p1 << free.p1;
117p2 << r.p2; 113p2 << r.p2;
118@@ 114@@
119 115
120msg = "ERROR: reference preceded by free on line %s" % (p1[0].line) 116msg = "reference preceded by free on line %s" % (p1[0].line)
121coccilib.report.print_report(p2[0],msg) 117coccilib.report.print_report(p2[0],msg)
diff --git a/scripts/coccinelle/iterators/fen.cocci b/scripts/coccinelle/iterators/fen.cocci
index 0a40af828c4..77bc108c3f5 100644
--- a/scripts/coccinelle/iterators/fen.cocci
+++ b/scripts/coccinelle/iterators/fen.cocci
@@ -2,19 +2,16 @@
2/// is no point to call of_node_put on the final value. 2/// is no point to call of_node_put on the final value.
3/// 3///
4// Confidence: High 4// Confidence: High
5// Copyright: (C) 2010-2012 Nicolas Palix. GPLv2. 5// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.
6// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. GPLv2. 6// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.
7// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2. 7// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
8// URL: http://coccinelle.lip6.fr/ 8// URL: http://coccinelle.lip6.fr/
9// Comments: 9// Comments:
10// Options: -no_includes -include_headers 10// Options: -no_includes -include_headers
11 11
12virtual patch 12virtual patch
13virtual context
14virtual org
15virtual report
16 13
17@depends on patch@ 14@@
18iterator name for_each_node_by_name; 15iterator name for_each_node_by_name;
19expression np,E; 16expression np,E;
20identifier l; 17identifier l;
@@ -27,7 +24,7 @@ for_each_node_by_name(np,...) {
27... when != np = E 24... when != np = E
28- of_node_put(np); 25- of_node_put(np);
29 26
30@depends on patch@ 27@@
31iterator name for_each_node_by_type; 28iterator name for_each_node_by_type;
32expression np,E; 29expression np,E;
33identifier l; 30identifier l;
@@ -40,7 +37,7 @@ for_each_node_by_type(np,...) {
40... when != np = E 37... when != np = E
41- of_node_put(np); 38- of_node_put(np);
42 39
43@depends on patch@ 40@@
44iterator name for_each_compatible_node; 41iterator name for_each_compatible_node;
45expression np,E; 42expression np,E;
46identifier l; 43identifier l;
@@ -53,7 +50,7 @@ for_each_compatible_node(np,...) {
53... when != np = E 50... when != np = E
54- of_node_put(np); 51- of_node_put(np);
55 52
56@depends on patch@ 53@@
57iterator name for_each_matching_node; 54iterator name for_each_matching_node;
58expression np,E; 55expression np,E;
59identifier l; 56identifier l;
@@ -65,59 +62,3 @@ for_each_matching_node(np,...) {
65} 62}
66... when != np = E 63... when != np = E
67- of_node_put(np); 64- of_node_put(np);
68
69// ----------------------------------------------------------------------
70
71@r depends on !patch forall@
72//iterator name for_each_node_by_name;
73//iterator name for_each_node_by_type;
74//iterator name for_each_compatible_node;
75//iterator name for_each_matching_node;
76expression np,E;
77identifier l;
78position p1,p2;
79@@
80
81(
82*for_each_node_by_name@p1(np,...)
83{
84 ... when != break;
85 when != goto l;
86}
87|
88*for_each_node_by_type@p1(np,...)
89{
90 ... when != break;
91 when != goto l;
92}
93|
94*for_each_compatible_node@p1(np,...)
95{
96 ... when != break;
97 when != goto l;
98}
99|
100*for_each_matching_node@p1(np,...)
101{
102 ... when != break;
103 when != goto l;
104}
105)
106... when != np = E
107* of_node_put@p2(np);
108
109@script:python depends on org@
110p1 << r.p1;
111p2 << r.p2;
112@@
113
114cocci.print_main("unneeded of_node_put",p2)
115cocci.print_secs("iterator",p1)
116
117@script:python depends on report@
118p1 << r.p1;
119p2 << r.p2;
120@@
121
122msg = "ERROR: of_node_put not needed after iterator on line %s" % (p1[0].line)
123coccilib.report.print_report(p2[0], msg)
diff --git a/scripts/coccinelle/iterators/itnull.cocci b/scripts/coccinelle/iterators/itnull.cocci
index 259899f6838..baa4297a4ed 100644
--- a/scripts/coccinelle/iterators/itnull.cocci
+++ b/scripts/coccinelle/iterators/itnull.cocci
@@ -1,24 +1,20 @@
1/// Many iterators have the property that the first argument is always bound 1/// Many iterators have the property that the first argument is always bound
2/// to a real list element, never NULL. 2/// to a real list element, never NULL. False positives arise for some
3//# False positives arise for some iterators that do not have this property, 3/// iterators that do not have this property, or in cases when the loop
4//# or in cases when the loop cursor is reassigned. The latter should only 4/// cursor is reassigned. The latter should only happen when the matched
5//# happen when the matched code is on the way to a loop exit (break, goto, 5/// code is on the way to a loop exit (break, goto, or return).
6//# or return).
7/// 6///
8// Confidence: Moderate 7// Confidence: Moderate
9// Copyright: (C) 2010-2012 Nicolas Palix. GPLv2. 8// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.
10// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. GPLv2. 9// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.
11// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2. 10// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
12// URL: http://coccinelle.lip6.fr/ 11// URL: http://coccinelle.lip6.fr/
13// Comments: 12// Comments:
14// Options: -no_includes -include_headers 13// Options: -no_includes -include_headers
15 14
16virtual patch 15virtual patch
17virtual context
18virtual org
19virtual report
20 16
21@depends on patch@ 17@@
22iterator I; 18iterator I;
23expression x,E,E1,E2; 19expression x,E,E1,E2;
24statement S,S1,S2; 20statement S,S1,S2;
@@ -59,36 +55,4 @@ I(x,...) { <...
59 x != NULL 55 x != NULL
60+ ) 56+ )
61) 57)
62 ...> } 58 ...> } \ No newline at end of file
63
64@r depends on !patch exists@
65iterator I;
66expression x,E;
67position p1,p2;
68@@
69
70*I@p1(x,...)
71{ ... when != x = E
72(
73* x@p2 == NULL
74|
75* x@p2 != NULL
76)
77 ... when any
78}
79
80@script:python depends on org@
81p1 << r.p1;
82p2 << r.p2;
83@@
84
85cocci.print_main("iterator-bound variable",p1)
86cocci.print_secs("useless NULL test",p2)
87
88@script:python depends on report@
89p1 << r.p1;
90p2 << r.p2;
91@@
92
93msg = "ERROR: iterator variable bound on line %s cannot be NULL" % (p1[0].line)
94coccilib.report.print_report(p2[0], msg)
diff --git a/scripts/coccinelle/iterators/use_after_iter.cocci b/scripts/coccinelle/iterators/use_after_iter.cocci
deleted file mode 100644
index 06284c57a95..00000000000
--- a/scripts/coccinelle/iterators/use_after_iter.cocci
+++ /dev/null
@@ -1,147 +0,0 @@
1/// If list_for_each_entry, etc complete a traversal of the list, the iterator
2/// variable ends up pointing to an address at an offset from the list head,
3/// and not a meaningful structure. Thus this value should not be used after
4/// the end of the iterator.
5//#False positives arise when there is a goto in the iterator and the
6//#reported reference is at the label of this goto. Some flag tests
7//#may also cause a report to be a false positive.
8///
9// Confidence: Moderate
10// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
11// Copyright: (C) 2012 Gilles Muller, INRIA/LIP6. GPLv2.
12// URL: http://coccinelle.lip6.fr/
13// Comments:
14// Options: -no_includes -include_headers
15
16virtual context
17virtual org
18virtual report
19
20@r exists@
21identifier c,member;
22expression E,x;
23iterator name list_for_each_entry;
24iterator name list_for_each_entry_reverse;
25iterator name list_for_each_entry_continue;
26iterator name list_for_each_entry_continue_reverse;
27iterator name list_for_each_entry_from;
28iterator name list_for_each_entry_safe;
29iterator name list_for_each_entry_safe_continue;
30iterator name list_for_each_entry_safe_from;
31iterator name list_for_each_entry_safe_reverse;
32iterator name hlist_for_each_entry;
33iterator name hlist_for_each_entry_continue;
34iterator name hlist_for_each_entry_from;
35iterator name hlist_for_each_entry_safe;
36statement S;
37position p1,p2;
38@@
39
40(
41list_for_each_entry@p1(c,...,member) { ... when != break;
42 when forall
43 when strict
44}
45|
46list_for_each_entry_reverse@p1(c,...,member) { ... when != break;
47 when forall
48 when strict
49}
50|
51list_for_each_entry_continue@p1(c,...,member) { ... when != break;
52 when forall
53 when strict
54}
55|
56list_for_each_entry_continue_reverse@p1(c,...,member) { ... when != break;
57 when forall
58 when strict
59}
60|
61list_for_each_entry_from@p1(c,...,member) { ... when != break;
62 when forall
63 when strict
64}
65|
66list_for_each_entry_safe@p1(c,...,member) { ... when != break;
67 when forall
68 when strict
69}
70|
71list_for_each_entry_safe_continue@p1(c,...,member) { ... when != break;
72 when forall
73 when strict
74}
75|
76list_for_each_entry_safe_from@p1(c,...,member) { ... when != break;
77 when forall
78 when strict
79}
80|
81list_for_each_entry_safe_reverse@p1(c,...,member) { ... when != break;
82 when forall
83 when strict
84}
85)
86...
87(
88list_for_each_entry(c,...) S
89|
90list_for_each_entry_reverse(c,...) S
91|
92list_for_each_entry_continue(c,...) S
93|
94list_for_each_entry_continue_reverse(c,...) S
95|
96list_for_each_entry_from(c,...) S
97|
98list_for_each_entry_safe(c,...) S
99|
100list_for_each_entry_safe(x,c,...) S
101|
102list_for_each_entry_safe_continue(c,...) S
103|
104list_for_each_entry_safe_continue(x,c,...) S
105|
106list_for_each_entry_safe_from(c,...) S
107|
108list_for_each_entry_safe_from(x,c,...) S
109|
110list_for_each_entry_safe_reverse(c,...) S
111|
112list_for_each_entry_safe_reverse(x,c,...) S
113|
114hlist_for_each_entry(c,...) S
115|
116hlist_for_each_entry_continue(c,...) S
117|
118hlist_for_each_entry_from(c,...) S
119|
120hlist_for_each_entry_safe(c,...) S
121|
122list_remove_head(x,c,...)
123|
124sizeof(<+...c...+>)
125|
126&c->member
127|
128c = E
129|
130*c@p2
131)
132
133@script:python depends on org@
134p1 << r.p1;
135p2 << r.p2;
136@@
137
138cocci.print_main("invalid iterator index reference",p2)
139cocci.print_secs("iterator",p1)
140
141@script:python depends on report@
142p1 << r.p1;
143p2 << r.p2;
144@@
145
146msg = "ERROR: invalid reference to the index variable of the iterator on line %s" % (p1[0].line)
147coccilib.report.print_report(p2[0], msg)
diff --git a/scripts/coccinelle/locks/call_kern.cocci b/scripts/coccinelle/locks/call_kern.cocci
index 8f10b49603c..00af5344a68 100644
--- a/scripts/coccinelle/locks/call_kern.cocci
+++ b/scripts/coccinelle/locks/call_kern.cocci
@@ -1,20 +1,17 @@
1/// Find functions that refer to GFP_KERNEL but are called with locks held. 1/// Find functions that refer to GFP_KERNEL but are called with locks held.
2//# The proposed change of converting the GFP_KERNEL is not necessarily the 2/// The proposed change of converting the GFP_KERNEL is not necessarily the
3//# correct one. It may be desired to unlock the lock, or to not call the 3/// correct one. It may be desired to unlock the lock, or to not call the
4//# function under the lock in the first place. 4/// function under the lock in the first place.
5/// 5///
6// Confidence: Moderate 6// Confidence: Moderate
7// Copyright: (C) 2012 Nicolas Palix. GPLv2. 7// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.
8// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2. 8// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.
9// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2. 9// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
10// URL: http://coccinelle.lip6.fr/ 10// URL: http://coccinelle.lip6.fr/
11// Comments: 11// Comments:
12// Options: -no_includes -include_headers 12// Options: -no_includes -include_headers
13 13
14virtual patch 14virtual patch
15virtual context
16virtual org
17virtual report
18 15
19@gfp exists@ 16@gfp exists@
20identifier fn; 17identifier fn;
@@ -35,29 +32,28 @@ fn(...) {
35 ... when any 32 ... when any
36} 33}
37 34
38@locked exists@ 35@locked@
39identifier gfp.fn; 36identifier gfp.fn;
40position p1,p2;
41@@ 37@@
42 38
43( 39(
44read_lock_irq@p1 40read_lock_irq
45| 41|
46write_lock_irq@p1 42write_lock_irq
47| 43|
48read_lock_irqsave@p1 44read_lock_irqsave
49| 45|
50write_lock_irqsave@p1 46write_lock_irqsave
51| 47|
52spin_lock@p1 48spin_lock
53| 49|
54spin_trylock@p1 50spin_trylock
55| 51|
56spin_lock_irq@p1 52spin_lock_irq
57| 53|
58spin_lock_irqsave@p1 54spin_lock_irqsave
59| 55|
60local_irq_disable@p1 56local_irq_disable
61) 57)
62 (...) 58 (...)
63... when != read_unlock_irq(...) 59... when != read_unlock_irq(...)
@@ -68,38 +64,11 @@ local_irq_disable@p1
68 when != spin_unlock_irq(...) 64 when != spin_unlock_irq(...)
69 when != spin_unlock_irqrestore(...) 65 when != spin_unlock_irqrestore(...)
70 when != local_irq_enable(...) 66 when != local_irq_enable(...)
71fn@p2(...) 67fn(...)
72 68
73@depends on locked && patch@ 69@depends on locked@
74position gfp.p; 70position gfp.p;
75@@ 71@@
76 72
77- GFP_KERNEL@p 73- GFP_KERNEL@p
78+ GFP_ATOMIC 74+ GFP_ATOMIC
79
80@depends on locked && !patch@
81position gfp.p;
82@@
83
84* GFP_KERNEL@p
85
86@script:python depends on !patch && org@
87p << gfp.p;
88fn << gfp.fn;
89p1 << locked.p1;
90p2 << locked.p2;
91@@
92
93cocci.print_main("lock",p1)
94cocci.print_secs("call",p2)
95cocci.print_secs("GFP_KERNEL",p)
96
97@script:python depends on !patch && report@
98p << gfp.p;
99fn << gfp.fn;
100p1 << locked.p1;
101p2 << locked.p2;
102@@
103
104msg = "ERROR: function %s called on line %s inside lock on line %s but uses GFP_KERNEL" % (fn,p2[0].line,p1[0].line)
105coccilib.report.print_report(p[0], msg)
diff --git a/scripts/coccinelle/locks/flags.cocci b/scripts/coccinelle/locks/flags.cocci
index 1c4ffe6fd84..b4344d83809 100644
--- a/scripts/coccinelle/locks/flags.cocci
+++ b/scripts/coccinelle/locks/flags.cocci
@@ -1,9 +1,9 @@
1/// Find nested lock+irqsave functions that use the same flags variables 1/// Find nested lock+irqsave functions that use the same flags variables
2/// 2///
3// Confidence: High 3// Confidence: High
4// Copyright: (C) 2010-2012 Nicolas Palix. GPLv2. 4// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.
5// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. GPLv2. 5// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.
6// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2. 6// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
7// URL: http://coccinelle.lip6.fr/ 7// URL: http://coccinelle.lip6.fr/
8// Comments: 8// Comments:
9// Options: -no_includes -include_headers 9// Options: -no_includes -include_headers
@@ -12,7 +12,7 @@ virtual context
12virtual org 12virtual org
13virtual report 13virtual report
14 14
15@r exists@ 15@r@
16expression lock1,lock2,flags; 16expression lock1,lock2,flags;
17position p1,p2; 17position p1,p2;
18@@ 18@@
@@ -39,7 +39,7 @@ read_lock_irqsave@p2(lock2,flags)
39write_lock_irqsave@p2(lock2,flags) 39write_lock_irqsave@p2(lock2,flags)
40) 40)
41 41
42@d exists@ 42@d@
43expression f <= r.flags; 43expression f <= r.flags;
44expression lock1,lock2,flags; 44expression lock1,lock2,flags;
45position r.p1, r.p2; 45position r.p1, r.p2;
@@ -76,5 +76,5 @@ p1 << r.p1;
76p2 << r.p2; 76p2 << r.p2;
77@@ 77@@
78 78
79msg="ERROR: nested lock+irqsave that reuses flags from line %s." % (p1[0].line) 79msg="ERROR: nested lock+irqsave that reuses flags from %s." % (p1[0].line)
80coccilib.report.print_report(p2[0], msg) 80coccilib.report.print_report(p2[0], msg)
diff --git a/scripts/coccinelle/locks/mini_lock.cocci b/scripts/coccinelle/locks/mini_lock.cocci
index 3267d7410bd..7641a292543 100644
--- a/scripts/coccinelle/locks/mini_lock.cocci
+++ b/scripts/coccinelle/locks/mini_lock.cocci
@@ -6,14 +6,13 @@
6/// function call that releases the lock. 6/// function call that releases the lock.
7/// 7///
8// Confidence: Moderate 8// Confidence: Moderate
9// Copyright: (C) 2010-2012 Nicolas Palix. GPLv2. 9// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.
10// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. GPLv2. 10// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.
11// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2. 11// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
12// URL: http://coccinelle.lip6.fr/ 12// URL: http://coccinelle.lip6.fr/
13// Comments: 13// Comments:
14// Options: -no_includes -include_headers 14// Options: -no_includes -include_headers
15 15
16virtual context
17virtual org 16virtual org
18virtual report 17virtual report
19 18
@@ -58,7 +57,7 @@ position r;
58 57
59for(...;...;...) { <+... return@r ...; ...+> } 58for(...;...;...) { <+... return@r ...; ...+> }
60 59
61@err exists@ 60@err@
62expression E1; 61expression E1;
63position prelocked.p; 62position prelocked.p;
64position up != prelocked.p1; 63position up != prelocked.p1;
@@ -66,14 +65,14 @@ position r!=looped.r;
66identifier lock,unlock; 65identifier lock,unlock;
67@@ 66@@
68 67
69*lock(E1@p,...); 68lock(E1@p,...);
70<+... when != E1 69<+... when != E1
71if (...) { 70if (...) {
72 ... when != E1 71 ... when != E1
73* return@r ...; 72 return@r ...;
74} 73}
75...+> 74...+>
76*unlock@up(E1,...); 75unlock@up(E1,...);
77 76
78@script:python depends on org@ 77@script:python depends on org@
79p << prelocked.p1; 78p << prelocked.p1;
diff --git a/scripts/coccinelle/misc/boolinit.cocci b/scripts/coccinelle/misc/boolinit.cocci
deleted file mode 100644
index 97ce41ce813..00000000000
--- a/scripts/coccinelle/misc/boolinit.cocci
+++ /dev/null
@@ -1,178 +0,0 @@
1/// Bool initializations should use true and false. Bool tests don't need
2/// comparisons. Based on contributions from Joe Perches, Rusty Russell
3/// and Bruce W Allan.
4///
5// Confidence: High
6// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
7// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
8// URL: http://coccinelle.lip6.fr/
9// Options: -include_headers
10
11virtual patch
12virtual context
13virtual org
14virtual report
15
16@depends on patch@
17bool t;
18symbol true;
19symbol false;
20@@
21
22(
23- t == true
24+ t
25|
26- true == t
27+ t
28|
29- t != true
30+ !t
31|
32- true != t
33+ !t
34|
35- t == false
36+ !t
37|
38- false == t
39+ !t
40|
41- t != false
42+ t
43|
44- false != t
45+ t
46)
47
48@depends on patch disable is_zero, isnt_zero@
49bool t;
50@@
51
52(
53- t == 1
54+ t
55|
56- t != 1
57+ !t
58|
59- t == 0
60+ !t
61|
62- t != 0
63+ t
64)
65
66@depends on patch@
67bool b;
68@@
69(
70 b =
71- 0
72+ false
73|
74 b =
75- 1
76+ true
77)
78
79// ---------------------------------------------------------------------
80
81@r1 depends on !patch@
82bool t;
83position p;
84@@
85
86(
87* t@p == true
88|
89* true == t@p
90|
91* t@p != true
92|
93* true != t@p
94|
95* t@p == false
96|
97* false == t@p
98|
99* t@p != false
100|
101* false != t@p
102)
103
104@r2 depends on !patch disable is_zero, isnt_zero@
105bool t;
106position p;
107@@
108
109(
110* t@p == 1
111|
112* t@p != 1
113|
114* t@p == 0
115|
116* t@p != 0
117)
118
119@r3 depends on !patch@
120bool b;
121position p1,p2;
122constant c;
123@@
124(
125*b@p1 = 0
126|
127*b@p1 = 1
128|
129*b@p2 = c
130)
131
132@script:python depends on org@
133p << r1.p;
134@@
135
136cocci.print_main("WARNING: Comparison to bool",p)
137
138@script:python depends on org@
139p << r2.p;
140@@
141
142cocci.print_main("WARNING: Comparison of bool to 0/1",p)
143
144@script:python depends on org@
145p1 << r3.p1;
146@@
147
148cocci.print_main("WARNING: Assignment of bool to 0/1",p1)
149
150@script:python depends on org@
151p2 << r3.p2;
152@@
153
154cocci.print_main("ERROR: Assignment of bool to non-0/1 constant",p2)
155
156@script:python depends on report@
157p << r1.p;
158@@
159
160coccilib.report.print_report(p[0],"WARNING: Comparison to bool")
161
162@script:python depends on report@
163p << r2.p;
164@@
165
166coccilib.report.print_report(p[0],"WARNING: Comparison of bool to 0/1")
167
168@script:python depends on report@
169p1 << r3.p1;
170@@
171
172coccilib.report.print_report(p1[0],"WARNING: Assignment of bool to 0/1")
173
174@script:python depends on report@
175p2 << r3.p2;
176@@
177
178coccilib.report.print_report(p2[0],"ERROR: Assignment of bool to non-0/1 constant")
diff --git a/scripts/coccinelle/misc/cstptr.cocci b/scripts/coccinelle/misc/cstptr.cocci
deleted file mode 100644
index d4256448452..00000000000
--- a/scripts/coccinelle/misc/cstptr.cocci
+++ /dev/null
@@ -1,41 +0,0 @@
1/// PTR_ERR should be applied before its argument is reassigned, typically
2/// to NULL
3///
4// Confidence: High
5// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
6// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
7// URL: http://coccinelle.lip6.fr/
8// Comments:
9// Options: -no_includes -include_headers
10
11virtual org
12virtual report
13virtual context
14
15@r exists@
16expression e,e1;
17constant c;
18position p1,p2;
19@@
20
21*e@p1 = c
22... when != e = e1
23 when != &e
24 when != true IS_ERR(e)
25*PTR_ERR@p2(e)
26
27@script:python depends on org@
28p1 << r.p1;
29p2 << r.p2;
30@@
31
32cocci.print_main("PTR_ERR",p2)
33cocci.print_secs("assignment",p1)
34
35@script:python depends on report@
36p1 << r.p1;
37p2 << r.p2;
38@@
39
40msg = "ERROR: PTR_ERR applied after initialization to constant on line %s" % (p1[0].line)
41coccilib.report.print_report(p2[0],msg)
diff --git a/scripts/coccinelle/misc/doubleinit.cocci b/scripts/coccinelle/misc/doubleinit.cocci
index cf74a00cf59..156b20adb35 100644
--- a/scripts/coccinelle/misc/doubleinit.cocci
+++ b/scripts/coccinelle/misc/doubleinit.cocci
@@ -3,9 +3,9 @@
3/// initialization. 3/// initialization.
4/// 4///
5// Confidence: Low 5// Confidence: Low
6// Copyright: (C) 2010-2012 Nicolas Palix. GPLv2. 6// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.
7// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. GPLv2. 7// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.
8// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2. 8// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
9// URL: http://coccinelle.lip6.fr/ 9// URL: http://coccinelle.lip6.fr/
10// Comments: requires at least Coccinelle 0.2.4, lex or parse error otherwise 10// Comments: requires at least Coccinelle 0.2.4, lex or parse error otherwise
11// Options: -no_includes -include_headers 11// Options: -no_includes -include_headers
@@ -49,5 +49,5 @@ pr << r.p;
49@@ 49@@
50 50
51if int(ps[0].line) < int(pr[0].line) or (int(ps[0].line) == int(pr[0].line) and int(ps[0].column) < int(pr[0].column)): 51if int(ps[0].line) < int(pr[0].line) or (int(ps[0].line) == int(pr[0].line) and int(ps[0].column) < int(pr[0].column)):
52 msg = "%s: first occurrence line %s, second occurrence line %s" % (fld,ps[0].line,pr[0].line) 52 msg = "%s: first occurrence %s, second occurrence %s" % (fld,ps[0].line,pr[0].line)
53 coccilib.report.print_report(p0[0],msg) 53 coccilib.report.print_report(p0[0],msg)
diff --git a/scripts/coccinelle/misc/ifaddr.cocci b/scripts/coccinelle/misc/ifaddr.cocci
deleted file mode 100644
index 3e4089a7700..00000000000
--- a/scripts/coccinelle/misc/ifaddr.cocci
+++ /dev/null
@@ -1,35 +0,0 @@
1/// the address of a variable or field is non-zero is likely always to bo
2/// non-zero
3///
4// Confidence: High
5// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
6// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
7// URL: http://coccinelle.lip6.fr/
8// Comments:
9// Options: -no_includes -include_headers
10
11virtual org
12virtual report
13virtual context
14
15@r@
16expression x;
17statement S1,S2;
18position p;
19@@
20
21*if@p (&x)
22 S1 else S2
23
24@script:python depends on org@
25p << r.p;
26@@
27
28cocci.print_main("test of a variable/field address",p)
29
30@script:python depends on report@
31p << r.p;
32@@
33
34msg = "ERROR: test of a variable/field address"
35coccilib.report.print_report(p[0],msg)
diff --git a/scripts/coccinelle/misc/irqf_oneshot.cocci b/scripts/coccinelle/misc/irqf_oneshot.cocci
deleted file mode 100644
index 6cfde94be0e..00000000000
--- a/scripts/coccinelle/misc/irqf_oneshot.cocci
+++ /dev/null
@@ -1,65 +0,0 @@
1/// Make sure threaded IRQs without a primary handler are always request with
2/// IRQF_ONESHOT
3///
4//
5// Confidence: Good
6// Comments:
7// Options: --no-includes
8
9virtual patch
10virtual context
11virtual org
12virtual report
13
14@r1@
15expression irq;
16expression thread_fn;
17expression flags;
18position p;
19@@
20request_threaded_irq@p(irq, NULL, thread_fn,
21(
22flags | IRQF_ONESHOT
23|
24IRQF_ONESHOT
25)
26, ...)
27
28@depends on patch@
29expression irq;
30expression thread_fn;
31expression flags;
32position p != r1.p;
33@@
34request_threaded_irq@p(irq, NULL, thread_fn,
35(
36-0
37+IRQF_ONESHOT
38|
39-flags
40+flags | IRQF_ONESHOT
41)
42, ...)
43
44@depends on context@
45position p != r1.p;
46@@
47*request_threaded_irq@p(...)
48
49@match depends on report || org@
50expression irq;
51position p != r1.p;
52@@
53request_threaded_irq@p(irq, NULL, ...)
54
55@script:python depends on org@
56p << match.p;
57@@
58msg = "ERROR: Threaded IRQ with no primary handler requested without IRQF_ONESHOT"
59coccilib.org.print_todo(p[0],msg)
60
61@script:python depends on report@
62p << match.p;
63@@
64msg = "ERROR: Threaded IRQ with no primary handler requested without IRQF_ONESHOT"
65coccilib.report.print_report(p[0],msg)
diff --git a/scripts/coccinelle/misc/noderef.cocci b/scripts/coccinelle/misc/noderef.cocci
deleted file mode 100644
index c1707214e60..00000000000
--- a/scripts/coccinelle/misc/noderef.cocci
+++ /dev/null
@@ -1,65 +0,0 @@
1/// sizeof when applied to a pointer typed expression gives the size of
2/// the pointer
3///
4// Confidence: High
5// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
6// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
7// URL: http://coccinelle.lip6.fr/
8// Comments:
9// Options: -no_includes -include_headers
10
11virtual org
12virtual report
13virtual context
14virtual patch
15
16@depends on patch@
17expression *x;
18expression f;
19type T;
20@@
21
22(
23x = <+... sizeof(
24- x
25+ *x
26 ) ...+>
27|
28f(...,(T)(x),...,sizeof(
29- x
30+ *x
31 ),...)
32|
33f(...,sizeof(x),...,(T)(
34- x
35+ *x
36 ),...)
37)
38
39@r depends on !patch@
40expression *x;
41expression f;
42position p;
43type T;
44@@
45
46(
47*x = <+... sizeof@p(x) ...+>
48|
49*f(...,(T)(x),...,sizeof@p(x),...)
50|
51*f(...,sizeof@p(x),...,(T)(x),...)
52)
53
54@script:python depends on org@
55p << r.p;
56@@
57
58cocci.print_main("application of sizeof to pointer",p)
59
60@script:python depends on report@
61p << r.p;
62@@
63
64msg = "ERROR: application of sizeof to pointer"
65coccilib.report.print_report(p[0],msg)
diff --git a/scripts/coccinelle/misc/warn.cocci b/scripts/coccinelle/misc/warn.cocci
deleted file mode 100644
index fda8c3558e4..00000000000
--- a/scripts/coccinelle/misc/warn.cocci
+++ /dev/null
@@ -1,109 +0,0 @@
1/// Use WARN(1,...) rather than printk followed by WARN_ON(1)
2///
3// Confidence: High
4// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
5// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
6// URL: http://coccinelle.lip6.fr/
7// Comments:
8// Options: -no_includes -include_headers
9
10virtual patch
11virtual context
12virtual org
13virtual report
14
15@bad1@
16position p;
17@@
18
19printk(...);
20printk@p(...);
21WARN_ON(1);
22
23@r1 depends on context || report || org@
24position p != bad1.p;
25@@
26
27 printk@p(...);
28*WARN_ON(1);
29
30@script:python depends on org@
31p << r1.p;
32@@
33
34cocci.print_main("printk + WARN_ON can be just WARN",p)
35
36@script:python depends on report@
37p << r1.p;
38@@
39
40msg = "SUGGESTION: printk + WARN_ON can be just WARN"
41coccilib.report.print_report(p[0],msg)
42
43@ok1 depends on patch@
44expression list es;
45position p != bad1.p;
46@@
47
48-printk@p(
49+WARN(1,
50 es);
51-WARN_ON(1);
52
53@depends on patch@
54expression list ok1.es;
55@@
56
57if (...)
58- {
59 WARN(1,es);
60- }
61
62// --------------------------------------------------------------------
63
64@bad2@
65position p;
66@@
67
68printk(...);
69printk@p(...);
70WARN_ON_ONCE(1);
71
72@r2 depends on context || report || org@
73position p != bad1.p;
74@@
75
76 printk@p(...);
77*WARN_ON_ONCE(1);
78
79@script:python depends on org@
80p << r2.p;
81@@
82
83cocci.print_main("printk + WARN_ON_ONCE can be just WARN_ONCE",p)
84
85@script:python depends on report@
86p << r2.p;
87@@
88
89msg = "SUGGESTION: printk + WARN_ON_ONCE can be just WARN_ONCE"
90coccilib.report.print_report(p[0],msg)
91
92@ok2 depends on patch@
93expression list es;
94position p != bad2.p;
95@@
96
97-printk@p(
98+WARN_ONCE(1,
99 es);
100-WARN_ON_ONCE(1);
101
102@depends on patch@
103expression list ok2.es;
104@@
105
106if (...)
107- {
108 WARN_ONCE(1,es);
109- }
diff --git a/scripts/coccinelle/null/badzero.cocci b/scripts/coccinelle/null/badzero.cocci
deleted file mode 100644
index d79baf7220e..00000000000
--- a/scripts/coccinelle/null/badzero.cocci
+++ /dev/null
@@ -1,237 +0,0 @@
1/// Compare pointer-typed values to NULL rather than 0
2///
3//# This makes an effort to choose between !x and x == NULL. !x is used
4//# if it has previously been used with the function used to initialize x.
5//# This relies on type information. More type information can be obtained
6//# using the option -all_includes and the option -I to specify an
7//# include path.
8//
9// Confidence: High
10// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
11// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
12// URL: http://coccinelle.lip6.fr/
13// Comments:
14// Options:
15
16virtual patch
17virtual context
18virtual org
19virtual report
20
21@initialize:ocaml@
22let negtable = Hashtbl.create 101
23
24@depends on patch@
25expression *E;
26identifier f;
27@@
28
29(
30 (E = f(...)) ==
31- 0
32+ NULL
33|
34 (E = f(...)) !=
35- 0
36+ NULL
37|
38- 0
39+ NULL
40 == (E = f(...))
41|
42- 0
43+ NULL
44 != (E = f(...))
45)
46
47
48@t1 depends on !patch@
49expression *E;
50identifier f;
51position p;
52@@
53
54(
55 (E = f(...)) ==
56* 0@p
57|
58 (E = f(...)) !=
59* 0@p
60|
61* 0@p
62 == (E = f(...))
63|
64* 0@p
65 != (E = f(...))
66)
67
68@script:python depends on org@
69p << t1.p;
70@@
71
72coccilib.org.print_todo(p[0], "WARNING comparing pointer to 0")
73
74@script:python depends on report@
75p << t1.p;
76@@
77
78coccilib.report.print_report(p[0], "WARNING comparing pointer to 0")
79
80// Tests of returned values
81
82@s@
83identifier f;
84expression E,E1;
85@@
86
87 E = f(...)
88 ... when != E = E1
89 !E
90
91@script:ocaml depends on s@
92f << s.f;
93@@
94
95try let _ = Hashtbl.find negtable f in ()
96with Not_found -> Hashtbl.add negtable f ()
97
98@ r disable is_zero,isnt_zero exists @
99expression *E;
100identifier f;
101@@
102
103E = f(...)
104...
105(E == 0
106|E != 0
107|0 == E
108|0 != E
109)
110
111@script:ocaml@
112f << r.f;
113@@
114
115try let _ = Hashtbl.find negtable f in ()
116with Not_found -> include_match false
117
118// This rule may lead to inconsistent path problems, if E is defined in two
119// places
120@ depends on patch disable is_zero,isnt_zero @
121expression *E;
122expression E1;
123identifier r.f;
124@@
125
126E = f(...)
127<...
128(
129- E == 0
130+ !E
131|
132- E != 0
133+ E
134|
135- 0 == E
136+ !E
137|
138- 0 != E
139+ E
140)
141...>
142?E = E1
143
144@t2 depends on !patch disable is_zero,isnt_zero @
145expression *E;
146expression E1;
147identifier r.f;
148position p1;
149position p2;
150@@
151
152E = f(...)
153<...
154(
155* E == 0@p1
156|
157* E != 0@p2
158|
159* 0@p1 == E
160|
161* 0@p1 != E
162)
163...>
164?E = E1
165
166@script:python depends on org@
167p << t2.p1;
168@@
169
170coccilib.org.print_todo(p[0], "WARNING comparing pointer to 0, suggest !E")
171
172@script:python depends on org@
173p << t2.p2;
174@@
175
176coccilib.org.print_todo(p[0], "WARNING comparing pointer to 0")
177
178@script:python depends on report@
179p << t2.p1;
180@@
181
182coccilib.report.print_report(p[0], "WARNING comparing pointer to 0, suggest !E")
183
184@script:python depends on report@
185p << t2.p2;
186@@
187
188coccilib.report.print_report(p[0], "WARNING comparing pointer to 0")
189
190@ depends on patch disable is_zero,isnt_zero @
191expression *E;
192@@
193
194(
195 E ==
196- 0
197+ NULL
198|
199 E !=
200- 0
201+ NULL
202|
203- 0
204+ NULL
205 == E
206|
207- 0
208+ NULL
209 != E
210)
211
212@ t3 depends on !patch disable is_zero,isnt_zero @
213expression *E;
214position p;
215@@
216
217(
218* E == 0@p
219|
220* E != 0@p
221|
222* 0@p == E
223|
224* 0@p != E
225)
226
227@script:python depends on org@
228p << t3.p;
229@@
230
231coccilib.org.print_todo(p[0], "WARNING comparing pointer to 0")
232
233@script:python depends on report@
234p << t3.p;
235@@
236
237coccilib.report.print_report(p[0], "WARNING comparing pointer to 0")
diff --git a/scripts/coccinelle/null/eno.cocci b/scripts/coccinelle/null/eno.cocci
index ed961a1f7d1..4c9c52b9c41 100644
--- a/scripts/coccinelle/null/eno.cocci
+++ b/scripts/coccinelle/null/eno.cocci
@@ -1,19 +1,16 @@
1/// The various basic memory allocation functions don't return ERR_PTR 1/// The various basic memory allocation functions don't return ERR_PTR
2/// 2///
3// Confidence: High 3// Confidence: High
4// Copyright: (C) 2010-2012 Nicolas Palix. GPLv2. 4// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.
5// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. GPLv2. 5// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.
6// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2. 6// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
7// URL: http://coccinelle.lip6.fr/ 7// URL: http://coccinelle.lip6.fr/
8// Comments: 8// Comments:
9// Options: -no_includes -include_headers 9// Options: -no_includes -include_headers
10 10
11virtual patch 11virtual patch
12virtual context
13virtual org
14virtual report
15 12
16@depends on patch@ 13@@
17expression x,E; 14expression x,E;
18@@ 15@@
19 16
@@ -21,28 +18,3 @@ x = \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|kmem_cache
21... when != x = E 18... when != x = E
22- IS_ERR(x) 19- IS_ERR(x)
23+ !x 20+ !x
24
25@r depends on !patch exists@
26expression x,E;
27position p1,p2;
28@@
29
30*x = \(kmalloc@p1\|kzalloc@p1\|kcalloc@p1\|kmem_cache_alloc@p1\|kmem_cache_zalloc@p1\|kmem_cache_alloc_node@p1\|kmalloc_node@p1\|kzalloc_node@p1\)(...)
31... when != x = E
32* IS_ERR@p2(x)
33
34@script:python depends on org@
35p1 << r.p1;
36p2 << r.p2;
37@@
38
39cocci.print_main("alloc call",p1)
40cocci.print_secs("IS_ERR that should be NULL tests",p2)
41
42@script:python depends on report@
43p1 << r.p1;
44p2 << r.p2;
45@@
46
47msg = "ERROR: allocation function on line %s returns NULL not ERR_PTR on failure" % (p1[0].line)
48coccilib.report.print_report(p2[0], msg)
diff --git a/scripts/coccinelle/tests/odd_ptr_err.cocci b/scripts/coccinelle/tests/odd_ptr_err.cocci
deleted file mode 100644
index e8dd8a6b28a..00000000000
--- a/scripts/coccinelle/tests/odd_ptr_err.cocci
+++ /dev/null
@@ -1,65 +0,0 @@
1/// PTR_ERR should access the value just tested by IS_ERR
2//# There can be false positives in the patch case, where it is the call
3//# IS_ERR that is wrong.
4///
5// Confidence: High
6// Copyright: (C) 2012 Julia Lawall, INRIA. GPLv2.
7// Copyright: (C) 2012 Gilles Muller, INRIA. GPLv2.
8// URL: http://coccinelle.lip6.fr/
9// Comments:
10// Options: -no_includes -include_headers
11
12virtual patch
13virtual context
14virtual org
15virtual report
16
17@depends on patch@
18expression e,e1;
19@@
20
21(
22if (IS_ERR(e)) { ... PTR_ERR(e) ... }
23|
24if (IS_ERR(e=e1)) { ... PTR_ERR(e) ... }
25|
26if (IS_ERR(e))
27 { ...
28 PTR_ERR(
29- e1
30+ e
31 )
32 ... }
33)
34
35@r depends on !patch@
36expression e,e1;
37position p1,p2;
38@@
39
40(
41if (IS_ERR(e)) { ... PTR_ERR(e) ... }
42|
43if (IS_ERR(e=e1)) { ... PTR_ERR(e) ... }
44|
45*if (IS_ERR@p1(e))
46 { ...
47* PTR_ERR@p2(e1)
48 ... }
49)
50
51@script:python depends on org@
52p1 << r.p1;
53p2 << r.p2;
54@@
55
56cocci.print_main("inconsistent IS_ERR and PTR_ERR",p1)
57cocci.print_secs("PTR_ERR",p2)
58
59@script:python depends on report@
60p1 << r.p1;
61p2 << r.p2;
62@@
63
64msg = "inconsistent IS_ERR and PTR_ERR, PTR_ERR on line %s" % (p2[0].line)
65coccilib.report.print_report(p1[0],msg)