xref: /linux/scripts/coccinelle/iterators/device_node_continue.cocci (revision 41167d072b8626ed14e80241c71beb99ac65db53)
1*41167d07SJulia Lawall/// Device node iterators put the previous value of the index variable, so an
2*41167d07SJulia Lawall/// explicit put causes a double put.
3*41167d07SJulia Lawall///
4*41167d07SJulia Lawall// Confidence: High
5*41167d07SJulia Lawall// Copyright: (C) 2015 Julia Lawall, Inria. GPLv2.
6*41167d07SJulia Lawall// URL: http://coccinelle.lip6.fr/
7*41167d07SJulia Lawall// Options: --no-includes --include-headers
8*41167d07SJulia Lawall// Keywords: for_each_child_of_node, etc.
9*41167d07SJulia Lawall
10*41167d07SJulia Lawallvirtual patch
11*41167d07SJulia Lawallvirtual context
12*41167d07SJulia Lawallvirtual org
13*41167d07SJulia Lawallvirtual report
14*41167d07SJulia Lawall
15*41167d07SJulia Lawall@r exists@
16*41167d07SJulia Lawallexpression e1,e2;
17*41167d07SJulia Lawalllocal idexpression n;
18*41167d07SJulia Lawalliterator name for_each_node_by_name, for_each_node_by_type,
19*41167d07SJulia Lawallfor_each_compatible_node, for_each_matching_node,
20*41167d07SJulia Lawallfor_each_matching_node_and_match, for_each_child_of_node,
21*41167d07SJulia Lawallfor_each_available_child_of_node, for_each_node_with_property;
22*41167d07SJulia Lawalliterator i;
23*41167d07SJulia Lawallposition p1,p2;
24*41167d07SJulia Lawallstatement S;
25*41167d07SJulia Lawall@@
26*41167d07SJulia Lawall
27*41167d07SJulia Lawall(
28*41167d07SJulia Lawall(
29*41167d07SJulia Lawallfor_each_node_by_name(n,e1) S
30*41167d07SJulia Lawall|
31*41167d07SJulia Lawallfor_each_node_by_type(n,e1) S
32*41167d07SJulia Lawall|
33*41167d07SJulia Lawallfor_each_compatible_node(n,e1,e2) S
34*41167d07SJulia Lawall|
35*41167d07SJulia Lawallfor_each_matching_node(n,e1) S
36*41167d07SJulia Lawall|
37*41167d07SJulia Lawallfor_each_matching_node_and_match(n,e1,e2) S
38*41167d07SJulia Lawall|
39*41167d07SJulia Lawallfor_each_child_of_node(e1,n) S
40*41167d07SJulia Lawall|
41*41167d07SJulia Lawallfor_each_available_child_of_node(e1,n) S
42*41167d07SJulia Lawall|
43*41167d07SJulia Lawallfor_each_node_with_property(n,e1) S
44*41167d07SJulia Lawall)
45*41167d07SJulia Lawall&
46*41167d07SJulia Lawalli@p1(...) {
47*41167d07SJulia Lawall   ... when != of_node_get(n)
48*41167d07SJulia Lawall       when any
49*41167d07SJulia Lawall   of_node_put@p2(n);
50*41167d07SJulia Lawall   ... when any
51*41167d07SJulia Lawall}
52*41167d07SJulia Lawall)
53*41167d07SJulia Lawall
54*41167d07SJulia Lawall@s exists@
55*41167d07SJulia Lawalllocal idexpression r.n;
56*41167d07SJulia Lawallstatement S;
57*41167d07SJulia Lawallposition r.p1,r.p2;
58*41167d07SJulia Lawalliterator i;
59*41167d07SJulia Lawall@@
60*41167d07SJulia Lawall
61*41167d07SJulia Lawall of_node_put@p2(n);
62*41167d07SJulia Lawall ... when any
63*41167d07SJulia Lawall i@p1(..., n, ...)
64*41167d07SJulia Lawall S
65*41167d07SJulia Lawall
66*41167d07SJulia Lawall@t depends on s && patch && !context && !org && !report@
67*41167d07SJulia Lawalllocal idexpression n;
68*41167d07SJulia Lawallposition r.p2;
69*41167d07SJulia Lawall@@
70*41167d07SJulia Lawall
71*41167d07SJulia Lawall- of_node_put@p2(n);
72*41167d07SJulia Lawall
73*41167d07SJulia Lawall// ----------------------------------------------------------------------------
74*41167d07SJulia Lawall
75*41167d07SJulia Lawall@t_context depends on s && !patch && (context || org || report)@
76*41167d07SJulia Lawalllocal idexpression n;
77*41167d07SJulia Lawallposition r.p2;
78*41167d07SJulia Lawallposition j0;
79*41167d07SJulia Lawall@@
80*41167d07SJulia Lawall
81*41167d07SJulia Lawall*  of_node_put@j0@p2(n);
82*41167d07SJulia Lawall
83*41167d07SJulia Lawall// ----------------------------------------------------------------------------
84*41167d07SJulia Lawall
85*41167d07SJulia Lawall@script:python t_org depends on org@
86*41167d07SJulia Lawallj0 << t_context.j0;
87*41167d07SJulia Lawall@@
88*41167d07SJulia Lawall
89*41167d07SJulia Lawallmsg = "ERROR: probable double put."
90*41167d07SJulia Lawallcoccilib.org.print_todo(j0[0], msg)
91*41167d07SJulia Lawall
92*41167d07SJulia Lawall// ----------------------------------------------------------------------------
93*41167d07SJulia Lawall
94*41167d07SJulia Lawall@script:python t_report depends on report@
95*41167d07SJulia Lawallj0 << t_context.j0;
96*41167d07SJulia Lawall@@
97*41167d07SJulia Lawall
98*41167d07SJulia Lawallmsg = "ERROR: probable double put."
99*41167d07SJulia Lawallcoccilib.report.print_report(j0[0], msg)
100*41167d07SJulia Lawall
101