Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /// Device node iterators put the previous value of the index variable, so an
0003 /// explicit put causes a double put.
0004 ///
0005 // Confidence: High
0006 // Copyright: (C) 2015 Julia Lawall, Inria.
0007 // URL: https://coccinelle.gitlabpages.inria.fr/website
0008 // Options: --no-includes --include-headers
0009 // Requires: 1.0.4
0010 // Keywords: for_each_child_of_node, etc.
0011 
0012 // This uses a conjunction, which requires at least coccinelle >= 1.0.4
0013 
0014 virtual patch
0015 virtual context
0016 virtual org
0017 virtual report
0018 
0019 @r exists@
0020 expression e1,e2;
0021 local idexpression n;
0022 iterator name for_each_node_by_name, for_each_node_by_type,
0023 for_each_compatible_node, for_each_matching_node,
0024 for_each_matching_node_and_match, for_each_child_of_node,
0025 for_each_available_child_of_node, for_each_node_with_property;
0026 iterator i;
0027 position p1,p2;
0028 statement S;
0029 @@
0030 
0031 (
0032 (
0033 for_each_node_by_name(n,e1) S
0034 |
0035 for_each_node_by_type(n,e1) S
0036 |
0037 for_each_compatible_node(n,e1,e2) S
0038 |
0039 for_each_matching_node(n,e1) S
0040 |
0041 for_each_matching_node_and_match(n,e1,e2) S
0042 |
0043 for_each_child_of_node(e1,n) S
0044 |
0045 for_each_available_child_of_node(e1,n) S
0046 |
0047 for_each_node_with_property(n,e1) S
0048 )
0049 &
0050 i@p1(...) {
0051    ... when != of_node_get(n)
0052        when any
0053    of_node_put@p2(n);
0054    ... when any
0055 }
0056 )
0057 
0058 @s exists@
0059 local idexpression r.n;
0060 statement S;
0061 position r.p1,r.p2;
0062 iterator i;
0063 @@
0064 
0065  of_node_put@p2(n);
0066  ... when any
0067  i@p1(..., n, ...)
0068  S
0069 
0070 @t depends on s && patch && !context && !org && !report@
0071 local idexpression n;
0072 position r.p2;
0073 @@
0074 
0075 - of_node_put@p2(n);
0076 
0077 // ----------------------------------------------------------------------------
0078 
0079 @t_context depends on s && !patch && (context || org || report)@
0080 local idexpression n;
0081 position r.p2;
0082 position j0;
0083 @@
0084 
0085 *  of_node_put@j0@p2(n);
0086 
0087 // ----------------------------------------------------------------------------
0088 
0089 @script:python t_org depends on org@
0090 j0 << t_context.j0;
0091 @@
0092 
0093 msg = "ERROR: probable double put."
0094 coccilib.org.print_todo(j0[0], msg)
0095 
0096 // ----------------------------------------------------------------------------
0097 
0098 @script:python t_report depends on report@
0099 j0 << t_context.j0;
0100 @@
0101 
0102 msg = "ERROR: probable double put."
0103 coccilib.report.print_report(j0[0], msg)
0104