History

scripts/coccinelle: improve the coverage of some semantic patches

This patch ensures that all semantic patches in the scripts/coccinelle directory provide the report option. Report messages that include line numbers now have the line number preceded by "line" for easier subsequent processing.

Julia Lawall committed 14 years ago

Commit 29a36d41 parent fb3f8af11 files · +351 −76Browse files

Unified · Split

11 files
  1. scripts/coccinelle/api/kstrdup.cocci +70 −5
  2. scripts/coccinelle/api/memdup.cocci +30 −4
  3. scripts/coccinelle/api/memdup_user.cocci +32 −7
  4. scripts/coccinelle/free/kfree.cocci +9 −5
  5. scripts/coccinelle/iterators/fen.cocci +66 −7
  6. scripts/coccinelle/iterators/itnull.cocci +45 −9
  7. scripts/coccinelle/locks/call_kern.cocci +49 −18
  8. scripts/coccinelle/locks/flags.cocci +6 −6
  9. scripts/coccinelle/locks/mini_lock.cocci +8 −7
  10. scripts/coccinelle/misc/doubleinit.cocci +4 −4
  11. scripts/coccinelle/null/eno.cocci +32 −4
scripts/coccinelle/api/kstrdup.cocci+70−5
@@ -1,16 +1,19 @@
1/// Use kstrdup rather than duplicating its implementation1/// Use kstrdup rather than duplicating its implementation
2///2///
3// Confidence: High3// Confidence: High
4// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.4// Copyright: (C) 2010-2012 Nicolas Palix. GPLv2.
5// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.5// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. GPLv2.
6// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.6// Copyright: (C) 2010-2012 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_headers9// Options: -no_includes -include_headers
10 10
11virtual patch11virtual patch
12virtual context
13virtual org
14virtual report
12 15
13@@16@depends on patch@
14expression from,to;17expression from,to;
15expression flag,E1,E2;18expression flag,E1,E2;
16statement S;19statement S;
@@ -23,7 +26,7 @@ statement S; · 6 unmodified lines
23 ... when != \(from = E2 \| to = E2 \)26 ... when != \(from = E2 \| to = E2 \)
24- strcpy(to, from);27- strcpy(to, from);
25 28
26@@29@depends on patch@
27expression x,from,to;30expression x,from,to;
28expression flag,E1,E2,E3;31expression flag,E1,E2,E3;
29statement S;32statement S;
@@ -37,3 +40,65 @@ statement S; · 7 unmodified lines
37 if (to==NULL || ...) S40 if (to==NULL || ...) S
38 ... when != \(x = E3 \| from = E3 \| to = E3 \)41 ... when != \(x = E3 \| from = E3 \| to = E3 \)
39- memcpy(to, from, x);42- 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)
scripts/coccinelle/api/memdup.cocci+30−4
@@ -1,14 +1,17 @@
1/// Use kmemdup rather than duplicating its implementation1/// Use kmemdup rather than duplicating its implementation
2///2///
3// Confidence: High3// Confidence: High
4// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.4// Copyright: (C) 2010-2012 Nicolas Palix. GPLv2.
5// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.5// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. GPLv2.
6// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.6// Copyright: (C) 2010-2012 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_headers9// Options: -no_includes -include_headers
10 10
11virtual patch11virtual patch
12virtual context
13virtual org
14virtual report
12 15
13@r1@16@r1@
14expression from,to;17expression from,to;
@@ -28,7 +31,7 @@ position p; · 13 unmodified lines
28 ... when != \( x = E1 \| from = E1 \)31 ... when != \( x = E1 \| from = E1 \)
29 to = \(kmalloc@p\|kzalloc@p\)(x,flag);32 to = \(kmalloc@p\|kzalloc@p\)(x,flag);
30 33
31@@34@depends on patch@
32expression from,to,size,flag;35expression from,to,size,flag;
33position p != {r1.p,r2.p};36position p != {r1.p,r2.p};
34statement S;37statement S;
@@ -38,3 +41,26 @@ statement S; · 3 unmodified lines
38+ to = kmemdup(from,size,flag);41+ to = kmemdup(from,size,flag);
39 if (to==NULL || ...) S42 if (to==NULL || ...) S
40- memcpy(to, from, size);43- 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")
scripts/coccinelle/api/memdup_user.cocci+32−7
@@ -1,23 +1,25 @@
1/// Use kmemdup_user rather than duplicating its implementation1/// Use memdup_user rather than duplicating its implementation
2/// This is a little bit restricted to reduce false positives2/// This is a little bit restricted to reduce false positives
3///3///
4// Confidence: High4// Confidence: High
5// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.5// Copyright: (C) 2010-2012 Nicolas Palix. GPLv2.
6// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.6// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. GPLv2.
7// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.7// Copyright: (C) 2010-2012 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_headers10// Options: -no_includes -include_headers
11 11
12virtual patch12virtual patch
13virtual context
14virtual org
15virtual report
13 16
14@@17@depends on patch@
15expression from,to,size,flag;18expression from,to,size,flag;
16position p;
17identifier l1,l2;19identifier l1,l2;
18@@20@@
19 21
20- to = \(kmalloc@p\|kzalloc@p\)(size,flag);22- to = \(kmalloc\|kzalloc\)(size,flag);
21+ to = memdup_user(from,size);23+ to = memdup_user(from,size);
22 if (24 if (
23- to==NULL25- to==NULL
@@ -33,3 +35,26 @@ identifier l1,l2; · 9 unmodified lines
33- -EFAULT35- -EFAULT
34- ...+>36- ...+>
35- }37- }
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 memdep_user")
55
56@script:python depends on report@
57p << r.p;
58@@
59
60coccilib.report.print_report(p[0], "WARNING opportunity for memdep_user")
scripts/coccinelle/free/kfree.cocci+9−5
@@ -5,9 +5,9 @@ · 4 unmodified lines
5//# SCTP_DBG_OBJCNT_DEC that do not actually evaluate their argument5//# SCTP_DBG_OBJCNT_DEC that do not actually evaluate their argument
6///6///
7// Confidence: Moderate7// Confidence: Moderate
8// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.8// Copyright: (C) 2010-2012 Nicolas Palix. GPLv2.
9// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.9// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. GPLv2.
10// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.10// Copyright: (C) 2010-2012 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_headers13// Options: -no_includes -include_headers
@@ -23,7 +23,7 @@ position p1; · 9 unmodified lines
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;
@@ -36,6 +36,10 @@ identifier f; · 6 unmodified lines
36 E@p == E236 E@p == E2
37|37|
38 E@p != E238 E@p != E2
39|
40 E2 == E@p
41|
42 E2 != E@p
39|43|
40 !E@p44 !E@p
41|45|
@@ -113,5 +117,5 @@ p1 << free.p1; · 71 unmodified lines
113p2 << r.p2;117p2 << r.p2;
114@@118@@
115 119
116msg = "reference preceded by free on line %s" % (p1[0].line)120msg = "ERROR: reference preceded by free on line %s" % (p1[0].line)
117coccilib.report.print_report(p2[0],msg)121coccilib.report.print_report(p2[0],msg)
scripts/coccinelle/iterators/fen.cocci+66−7
@@ -2,16 +2,19 @@ · 1 unmodified line
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: High4// Confidence: High
5// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.5// Copyright: (C) 2010-2012 Nicolas Palix. GPLv2.
6// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.6// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. GPLv2.
7// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.7// Copyright: (C) 2010-2012 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_headers10// Options: -no_includes -include_headers
11 11
12virtual patch12virtual patch
13virtual context
14virtual org
15virtual report
13 16
14@@17@depends on patch@
15iterator name for_each_node_by_name;18iterator name for_each_node_by_name;
16expression np,E;19expression np,E;
17identifier l;20identifier l;
@@ -24,7 +27,7 @@ for_each_node_by_name(np,...) { · 6 unmodified lines
24... when != np = E27... when != np = E
25- of_node_put(np);28- of_node_put(np);
26 29
27@@30@depends on patch@
28iterator name for_each_node_by_type;31iterator name for_each_node_by_type;
29expression np,E;32expression np,E;
30identifier l;33identifier l;
@@ -37,7 +40,7 @@ for_each_node_by_type(np,...) { · 6 unmodified lines
37... when != np = E40... when != np = E
38- of_node_put(np);41- of_node_put(np);
39 42
40@@43@depends on patch@
41iterator name for_each_compatible_node;44iterator name for_each_compatible_node;
42expression np,E;45expression np,E;
43identifier l;46identifier l;
@@ -50,7 +53,7 @@ for_each_compatible_node(np,...) { · 6 unmodified lines
50... when != np = E53... when != np = E
51- of_node_put(np);54- of_node_put(np);
52 55
53@@56@depends on patch@
54iterator name for_each_matching_node;57iterator name for_each_matching_node;
55expression np,E;58expression np,E;
56identifier l;59identifier l;
@@ -62,3 +65,59 @@ for_each_matching_node(np,...) { · 5 unmodified lines
62}65}
63... when != np = E66... when != np = E
64- of_node_put(np);67- 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)
scripts/coccinelle/iterators/itnull.cocci+45−9
@@ -1,20 +1,24 @@
1/// Many iterators have the property that the first argument is always bound1/// Many iterators have the property that the first argument is always bound
2/// to a real list element, never NULL. False positives arise for some2/// to a real list element, never NULL.
3/// iterators that do not have this property, or in cases when the loop3//# False positives arise for some iterators that do not have this property,
4/// cursor is reassigned. The latter should only happen when the matched4//# or in cases when the loop cursor is reassigned. The latter should only
5/// code is on the way to a loop exit (break, goto, or return).5//# happen when the matched code is on the way to a loop exit (break, goto,
6//# or return).
6///7///
7// Confidence: Moderate8// Confidence: Moderate
8// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.9// Copyright: (C) 2010-2012 Nicolas Palix. GPLv2.
9// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.10// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. GPLv2.
10// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.11// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2.
11// URL: http://coccinelle.lip6.fr/12// URL: http://coccinelle.lip6.fr/
12// Comments:13// Comments:
13// Options: -no_includes -include_headers14// Options: -no_includes -include_headers
14 15
15virtual patch16virtual patch
17virtual context
18virtual org
19virtual report
16 20
17@@21@depends on patch@
18iterator I;22iterator I;
19expression x,E,E1,E2;23expression x,E,E1,E2;
20statement S,S1,S2;24statement S,S1,S2;
@@ -55,4 +59,36 @@ I(x,...) { <... · 34 unmodified lines
55 x != NULL59 x != NULL
56+ )60+ )
57)61)
58 ...> }62 ...> }
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)
scripts/coccinelle/locks/call_kern.cocci+49−18
@@ -1,17 +1,20 @@
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 the2//# 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 the3//# 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: Moderate6// Confidence: Moderate
7// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.7// Copyright: (C) 2012 Nicolas Palix. GPLv2.
8// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.8// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
9// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.9// Copyright: (C) 2012 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_headers12// Options: -no_includes -include_headers
13 13
14virtual patch14virtual patch
15virtual context
16virtual org
17virtual report
15 18
16@gfp exists@19@gfp exists@
17identifier fn;20identifier fn;
@@ -32,28 +35,29 @@ fn(...) { · 14 unmodified lines
32 ... when any35 ... when any
33}36}
34 37
35@locked@38@locked exists@
36identifier gfp.fn;39identifier gfp.fn;
40position p1,p2;
37@@41@@
38 42
39(43(
40read_lock_irq44read_lock_irq@p1
41|45|
42write_lock_irq46write_lock_irq@p1
43|47|
44read_lock_irqsave48read_lock_irqsave@p1
45|49|
46write_lock_irqsave50write_lock_irqsave@p1
47|51|
48spin_lock52spin_lock@p1
49|53|
50spin_trylock54spin_trylock@p1
51|55|
52spin_lock_irq56spin_lock_irq@p1
53|57|
54spin_lock_irqsave58spin_lock_irqsave@p1
55|59|
56local_irq_disable60local_irq_disable@p1
57)61)
58 (...)62 (...)
59... when != read_unlock_irq(...)63... when != read_unlock_irq(...)
@@ -64,11 +68,38 @@ local_irq_disable · 4 unmodified lines
64 when != spin_unlock_irq(...)68 when != spin_unlock_irq(...)
65 when != spin_unlock_irqrestore(...)69 when != spin_unlock_irqrestore(...)
66 when != local_irq_enable(...)70 when != local_irq_enable(...)
67fn(...)71fn@p2(...)
68 72
69@depends on locked@73@depends on locked && patch@
70position gfp.p;74position gfp.p;
71@@75@@
72 76
73- GFP_KERNEL@p77- GFP_KERNEL@p
74+ GFP_ATOMIC78+ 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)
scripts/coccinelle/locks/flags.cocci+6−6
@@ -1,9 +1,9 @@
1/// Find nested lock+irqsave functions that use the same flags variables1/// Find nested lock+irqsave functions that use the same flags variables
2///2///
3// Confidence: High3// Confidence: High
4// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.4// Copyright: (C) 2010-2012 Nicolas Palix. GPLv2.
5// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.5// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. GPLv2.
6// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.6// Copyright: (C) 2010-2012 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_headers9// Options: -no_includes -include_headers
@@ -12,7 +12,7 @@ virtual context · 2 unmodified lines
12virtual org12virtual org
13virtual report13virtual report
14 14
15@r@15@r exists@
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) · 20 unmodified lines
39write_lock_irqsave@p2(lock2,flags)39write_lock_irqsave@p2(lock2,flags)
40)40)
41 41
42@d@42@d exists@
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; · 30 unmodified lines
76p2 << r.p2;76p2 << r.p2;
77@@77@@
78 78
79msg="ERROR: nested lock+irqsave that reuses flags from %s." % (p1[0].line)79msg="ERROR: nested lock+irqsave that reuses flags from line %s." % (p1[0].line)
80coccilib.report.print_report(p2[0], msg)80coccilib.report.print_report(p2[0], msg)
scripts/coccinelle/locks/mini_lock.cocci+8−7
@@ -6,13 +6,14 @@ · 5 unmodified lines
6/// function call that releases the lock.6/// function call that releases the lock.
7///7///
8// Confidence: Moderate8// Confidence: Moderate
9// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.9// Copyright: (C) 2010-2012 Nicolas Palix. GPLv2.
10// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.10// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. GPLv2.
11// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.11// Copyright: (C) 2010-2012 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_headers14// Options: -no_includes -include_headers
15 15
16virtual context
16virtual org17virtual org
17virtual report18virtual report
18 19
@@ -57,7 +58,7 @@ position r; · 38 unmodified lines
57 58
58for(...;...;...) { <+... return@r ...; ...+> }59for(...;...;...) { <+... return@r ...; ...+> }
59 60
60@err@61@err exists@
61expression E1;62expression E1;
62position prelocked.p;63position prelocked.p;
63position up != prelocked.p1;64position up != prelocked.p1;
@@ -65,14 +66,14 @@ position r!=looped.r; · 1 unmodified line
65identifier lock,unlock;66identifier lock,unlock;
66@@67@@
67 68
68lock(E1@p,...);69*lock(E1@p,...);
69<+... when != E170<+... when != E1
70if (...) {71if (...) {
71 ... when != E172 ... when != E1
72 return@r ...;73* return@r ...;
73}74}
74...+>75...+>
75unlock@up(E1,...);76*unlock@up(E1,...);
76 77
77@script:python depends on org@78@script:python depends on org@
78p << prelocked.p1;79p << prelocked.p1;
scripts/coccinelle/misc/doubleinit.cocci+4−4
@@ -3,9 +3,9 @@ · 2 unmodified lines
3/// initialization.3/// initialization.
4///4///
5// Confidence: Low5// Confidence: Low
6// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.6// Copyright: (C) 2010-2012 Nicolas Palix. GPLv2.
7// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.7// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. GPLv2.
8// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.8// Copyright: (C) 2010-2012 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 otherwise10// Comments: requires at least Coccinelle 0.2.4, lex or parse error otherwise
11// Options: -no_includes -include_headers11// Options: -no_includes -include_headers
@@ -49,5 +49,5 @@ pr << r.p; · 37 unmodified lines
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 %s, second occurrence %s" % (fld,ps[0].line,pr[0].line)52 msg = "%s: first occurrence line %s, second occurrence line %s" % (fld,ps[0].line,pr[0].line)
53 coccilib.report.print_report(p0[0],msg)53 coccilib.report.print_report(p0[0],msg)
scripts/coccinelle/null/eno.cocci+32−4
@@ -1,16 +1,19 @@
1/// The various basic memory allocation functions don't return ERR_PTR1/// The various basic memory allocation functions don't return ERR_PTR
2///2///
3// Confidence: High3// Confidence: High
4// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.4// Copyright: (C) 2010-2012 Nicolas Palix. GPLv2.
5// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.5// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. GPLv2.
6// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.6// Copyright: (C) 2010-2012 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_headers9// Options: -no_includes -include_headers
10 10
11virtual patch11virtual patch
12virtual context
13virtual org
14virtual report
12 15
13@@16@depends on patch@
14expression x,E;17expression x,E;
15@@18@@
16 19
@@ -18,3 +21,28 @@ x = \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|kmem_cache · 1 unmodified line
18... when != x = E21... when != x = E
19- IS_ERR(x)22- IS_ERR(x)
20+ !x23+ !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)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t