diff options
| author | Julia Lawall <Julia.Lawall@lip6.fr> | 2015-10-22 16:11:59 -0400 |
|---|---|---|
| committer | Michal Marek <mmarek@suse.cz> | 2015-10-26 17:39:11 -0400 |
| commit | 41167d072b8626ed14e80241c71beb99ac65db53 (patch) | |
| tree | c4944a5ef348dfc73e1de8b2a1c3a9d414165b0a /scripts | |
| parent | 63a478fbc05cb0627b0a33a69f3aed8dcb965953 (diff) | |
cocinelle: iterators: semantic patch to delete unneeded of_node_put
Device node iterators perform an of_node_put on each iteration, so putting
an of_node_put before a continue results in a double put.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/coccinelle/iterators/device_node_continue.cocci | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/scripts/coccinelle/iterators/device_node_continue.cocci b/scripts/coccinelle/iterators/device_node_continue.cocci new file mode 100644 index 000000000000..38ab744a4037 --- /dev/null +++ b/scripts/coccinelle/iterators/device_node_continue.cocci | |||
| @@ -0,0 +1,100 @@ | |||
| 1 | /// Device node iterators put the previous value of the index variable, so an | ||
| 2 | /// explicit put causes a double put. | ||
| 3 | /// | ||
| 4 | // Confidence: High | ||
| 5 | // Copyright: (C) 2015 Julia Lawall, Inria. GPLv2. | ||
| 6 | // URL: http://coccinelle.lip6.fr/ | ||
| 7 | // Options: --no-includes --include-headers | ||
| 8 | // Keywords: for_each_child_of_node, etc. | ||
| 9 | |||
| 10 | virtual patch | ||
| 11 | virtual context | ||
| 12 | virtual org | ||
| 13 | virtual report | ||
| 14 | |||
| 15 | @r exists@ | ||
| 16 | expression e1,e2; | ||
| 17 | local idexpression n; | ||
| 18 | iterator name for_each_node_by_name, for_each_node_by_type, | ||
| 19 | for_each_compatible_node, for_each_matching_node, | ||
| 20 | for_each_matching_node_and_match, for_each_child_of_node, | ||
| 21 | for_each_available_child_of_node, for_each_node_with_property; | ||
| 22 | iterator i; | ||
| 23 | position p1,p2; | ||
| 24 | statement S; | ||
| 25 | @@ | ||
| 26 | |||
| 27 | ( | ||
| 28 | ( | ||
| 29 | for_each_node_by_name(n,e1) S | ||
| 30 | | | ||
| 31 | for_each_node_by_type(n,e1) S | ||
| 32 | | | ||
| 33 | for_each_compatible_node(n,e1,e2) S | ||
| 34 | | | ||
| 35 | for_each_matching_node(n,e1) S | ||
| 36 | | | ||
| 37 | for_each_matching_node_and_match(n,e1,e2) S | ||
| 38 | | | ||
| 39 | for_each_child_of_node(e1,n) S | ||
| 40 | | | ||
| 41 | for_each_available_child_of_node(e1,n) S | ||
| 42 | | | ||
| 43 | for_each_node_with_property(n,e1) S | ||
| 44 | ) | ||
| 45 | & | ||
| 46 | i@p1(...) { | ||
| 47 | ... when != of_node_get(n) | ||
| 48 | when any | ||
| 49 | of_node_put@p2(n); | ||
| 50 | ... when any | ||
| 51 | } | ||
| 52 | ) | ||
| 53 | |||
| 54 | @s exists@ | ||
| 55 | local idexpression r.n; | ||
| 56 | statement S; | ||
| 57 | position r.p1,r.p2; | ||
| 58 | iterator i; | ||
| 59 | @@ | ||
| 60 | |||
| 61 | of_node_put@p2(n); | ||
| 62 | ... when any | ||
| 63 | i@p1(..., n, ...) | ||
| 64 | S | ||
| 65 | |||
| 66 | @t depends on s && patch && !context && !org && !report@ | ||
| 67 | local idexpression n; | ||
| 68 | position r.p2; | ||
| 69 | @@ | ||
| 70 | |||
| 71 | - of_node_put@p2(n); | ||
| 72 | |||
| 73 | // ---------------------------------------------------------------------------- | ||
| 74 | |||
| 75 | @t_context depends on s && !patch && (context || org || report)@ | ||
| 76 | local idexpression n; | ||
| 77 | position r.p2; | ||
| 78 | position j0; | ||
| 79 | @@ | ||
| 80 | |||
| 81 | * of_node_put@j0@p2(n); | ||
| 82 | |||
| 83 | // ---------------------------------------------------------------------------- | ||
| 84 | |||
| 85 | @script:python t_org depends on org@ | ||
| 86 | j0 << t_context.j0; | ||
| 87 | @@ | ||
| 88 | |||
| 89 | msg = "ERROR: probable double put." | ||
| 90 | coccilib.org.print_todo(j0[0], msg) | ||
| 91 | |||
| 92 | // ---------------------------------------------------------------------------- | ||
| 93 | |||
| 94 | @script:python t_report depends on report@ | ||
| 95 | j0 << t_context.j0; | ||
| 96 | @@ | ||
| 97 | |||
| 98 | msg = "ERROR: probable double put." | ||
| 99 | coccilib.report.print_report(j0[0], msg) | ||
| 100 | |||
