diff options
author | Julia Lawall <Julia.Lawall@lip6.fr> | 2012-01-14 17:41:54 -0500 |
---|---|---|
committer | Michal Marek <mmarek@suse.cz> | 2012-01-14 18:05:46 -0500 |
commit | 29a36d4dec6cf7ad72e6e3337bf954096cbbb4cf (patch) | |
tree | 15ac5f3d0df3f56f233603e8626b5d383e6ab278 /scripts/coccinelle/locks | |
parent | fb3f8af4ff52faf9b31e6c4e8ca0b0b16332808c (diff) |
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.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Diffstat (limited to 'scripts/coccinelle/locks')
-rw-r--r-- | scripts/coccinelle/locks/call_kern.cocci | 67 | ||||
-rw-r--r-- | scripts/coccinelle/locks/flags.cocci | 12 | ||||
-rw-r--r-- | scripts/coccinelle/locks/mini_lock.cocci | 15 |
3 files changed, 63 insertions, 31 deletions
diff --git a/scripts/coccinelle/locks/call_kern.cocci b/scripts/coccinelle/locks/call_kern.cocci index 00af5344a68f..8f10b49603c3 100644 --- a/scripts/coccinelle/locks/call_kern.cocci +++ b/scripts/coccinelle/locks/call_kern.cocci | |||
@@ -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 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) 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_headers | 12 | // Options: -no_includes -include_headers |
13 | 13 | ||
14 | virtual patch | 14 | virtual patch |
15 | virtual context | ||
16 | virtual org | ||
17 | virtual report | ||
15 | 18 | ||
16 | @gfp exists@ | 19 | @gfp exists@ |
17 | identifier fn; | 20 | identifier fn; |
@@ -32,28 +35,29 @@ fn(...) { | |||
32 | ... when any | 35 | ... when any |
33 | } | 36 | } |
34 | 37 | ||
35 | @locked@ | 38 | @locked exists@ |
36 | identifier gfp.fn; | 39 | identifier gfp.fn; |
40 | position p1,p2; | ||
37 | @@ | 41 | @@ |
38 | 42 | ||
39 | ( | 43 | ( |
40 | read_lock_irq | 44 | read_lock_irq@p1 |
41 | | | 45 | | |
42 | write_lock_irq | 46 | write_lock_irq@p1 |
43 | | | 47 | | |
44 | read_lock_irqsave | 48 | read_lock_irqsave@p1 |
45 | | | 49 | | |
46 | write_lock_irqsave | 50 | write_lock_irqsave@p1 |
47 | | | 51 | | |
48 | spin_lock | 52 | spin_lock@p1 |
49 | | | 53 | | |
50 | spin_trylock | 54 | spin_trylock@p1 |
51 | | | 55 | | |
52 | spin_lock_irq | 56 | spin_lock_irq@p1 |
53 | | | 57 | | |
54 | spin_lock_irqsave | 58 | spin_lock_irqsave@p1 |
55 | | | 59 | | |
56 | local_irq_disable | 60 | local_irq_disable@p1 |
57 | ) | 61 | ) |
58 | (...) | 62 | (...) |
59 | ... when != read_unlock_irq(...) | 63 | ... when != read_unlock_irq(...) |
@@ -64,11 +68,38 @@ local_irq_disable | |||
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(...) |
67 | fn(...) | 71 | fn@p2(...) |
68 | 72 | ||
69 | @depends on locked@ | 73 | @depends on locked && patch@ |
70 | position gfp.p; | 74 | position gfp.p; |
71 | @@ | 75 | @@ |
72 | 76 | ||
73 | - GFP_KERNEL@p | 77 | - GFP_KERNEL@p |
74 | + GFP_ATOMIC | 78 | + GFP_ATOMIC |
79 | |||
80 | @depends on locked && !patch@ | ||
81 | position gfp.p; | ||
82 | @@ | ||
83 | |||
84 | * GFP_KERNEL@p | ||
85 | |||
86 | @script:python depends on !patch && org@ | ||
87 | p << gfp.p; | ||
88 | fn << gfp.fn; | ||
89 | p1 << locked.p1; | ||
90 | p2 << locked.p2; | ||
91 | @@ | ||
92 | |||
93 | cocci.print_main("lock",p1) | ||
94 | cocci.print_secs("call",p2) | ||
95 | cocci.print_secs("GFP_KERNEL",p) | ||
96 | |||
97 | @script:python depends on !patch && report@ | ||
98 | p << gfp.p; | ||
99 | fn << gfp.fn; | ||
100 | p1 << locked.p1; | ||
101 | p2 << locked.p2; | ||
102 | @@ | ||
103 | |||
104 | msg = "ERROR: function %s called on line %s inside lock on line %s but uses GFP_KERNEL" % (fn,p2[0].line,p1[0].line) | ||
105 | coccilib.report.print_report(p[0], msg) | ||
diff --git a/scripts/coccinelle/locks/flags.cocci b/scripts/coccinelle/locks/flags.cocci index b4344d838097..1c4ffe6fd846 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 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_headers | 9 | // Options: -no_includes -include_headers |
@@ -12,7 +12,7 @@ virtual context | |||
12 | virtual org | 12 | virtual org |
13 | virtual report | 13 | virtual report |
14 | 14 | ||
15 | @r@ | 15 | @r exists@ |
16 | expression lock1,lock2,flags; | 16 | expression lock1,lock2,flags; |
17 | position p1,p2; | 17 | position p1,p2; |
18 | @@ | 18 | @@ |
@@ -39,7 +39,7 @@ read_lock_irqsave@p2(lock2,flags) | |||
39 | write_lock_irqsave@p2(lock2,flags) | 39 | write_lock_irqsave@p2(lock2,flags) |
40 | ) | 40 | ) |
41 | 41 | ||
42 | @d@ | 42 | @d exists@ |
43 | expression f <= r.flags; | 43 | expression f <= r.flags; |
44 | expression lock1,lock2,flags; | 44 | expression lock1,lock2,flags; |
45 | position r.p1, r.p2; | 45 | position r.p1, r.p2; |
@@ -76,5 +76,5 @@ p1 << r.p1; | |||
76 | p2 << r.p2; | 76 | p2 << r.p2; |
77 | @@ | 77 | @@ |
78 | 78 | ||
79 | msg="ERROR: nested lock+irqsave that reuses flags from %s." % (p1[0].line) | 79 | msg="ERROR: nested lock+irqsave that reuses flags from line %s." % (p1[0].line) |
80 | coccilib.report.print_report(p2[0], msg) | 80 | coccilib.report.print_report(p2[0], msg) |
diff --git a/scripts/coccinelle/locks/mini_lock.cocci b/scripts/coccinelle/locks/mini_lock.cocci index 7641a2925434..3267d7410bd5 100644 --- a/scripts/coccinelle/locks/mini_lock.cocci +++ b/scripts/coccinelle/locks/mini_lock.cocci | |||
@@ -6,13 +6,14 @@ | |||
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 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_headers | 14 | // Options: -no_includes -include_headers |
15 | 15 | ||
16 | virtual context | ||
16 | virtual org | 17 | virtual org |
17 | virtual report | 18 | virtual report |
18 | 19 | ||
@@ -57,7 +58,7 @@ position r; | |||
57 | 58 | ||
58 | for(...;...;...) { <+... return@r ...; ...+> } | 59 | for(...;...;...) { <+... return@r ...; ...+> } |
59 | 60 | ||
60 | @err@ | 61 | @err exists@ |
61 | expression E1; | 62 | expression E1; |
62 | position prelocked.p; | 63 | position prelocked.p; |
63 | position up != prelocked.p1; | 64 | position up != prelocked.p1; |
@@ -65,14 +66,14 @@ position r!=looped.r; | |||
65 | identifier lock,unlock; | 66 | identifier lock,unlock; |
66 | @@ | 67 | @@ |
67 | 68 | ||
68 | lock(E1@p,...); | 69 | *lock(E1@p,...); |
69 | <+... when != E1 | 70 | <+... when != E1 |
70 | if (...) { | 71 | if (...) { |
71 | ... when != E1 | 72 | ... when != E1 |
72 | return@r ...; | 73 | * return@r ...; |
73 | } | 74 | } |
74 | ...+> | 75 | ...+> |
75 | unlock@up(E1,...); | 76 | *unlock@up(E1,...); |
76 | 77 | ||
77 | @script:python depends on org@ | 78 | @script:python depends on org@ |
78 | p << prelocked.p1; | 79 | p << prelocked.p1; |