Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /// list_for_each_entry uses its first argument to get from one element of
0003 /// the list to the next, so it is usually not a good idea to reassign it.
0004 /// The first rule finds such a reassignment and the second rule checks
0005 /// that there is a path from the reassignment back to the top of the loop.
0006 ///
0007 // Confidence: High
0008 // Copyright: (C) 2010 Nicolas Palix, DIKU.
0009 // Copyright: (C) 2010 Julia Lawall, DIKU.
0010 // Copyright: (C) 2010 Gilles Muller, INRIA/LiP6.
0011 // URL: https://coccinelle.gitlabpages.inria.fr/website
0012 // Comments:
0013 // Options: --no-includes --include-headers
0014 
0015 virtual context
0016 virtual org
0017 virtual report
0018 
0019 @r exists@
0020 iterator name list_for_each_entry;
0021 expression x,E;
0022 position p1,p2;
0023 @@
0024 
0025 list_for_each_entry@p1(x,...) { <... x =@p2 E ...> }
0026 
0027 @depends on context && !org && !report@
0028 expression x,E;
0029 position r.p1,r.p2;
0030 statement S;
0031 @@
0032 
0033 *x =@p2 E
0034 ...
0035 list_for_each_entry@p1(x,...) S
0036 
0037 // ------------------------------------------------------------------------
0038 
0039 @back depends on (org || report) && !context exists@
0040 expression x,E;
0041 position r.p1,r.p2;
0042 statement S;
0043 @@
0044 
0045 x =@p2 E
0046 ...
0047 list_for_each_entry@p1(x,...) S
0048 
0049 @script:python depends on back && org@
0050 p1 << r.p1;
0051 p2 << r.p2;
0052 @@
0053 
0054 cocci.print_main("iterator",p1)
0055 cocci.print_secs("update",p2)
0056 
0057 @script:python depends on back && report@
0058 p1 << r.p1;
0059 p2 << r.p2;
0060 @@
0061 
0062 msg = "iterator with update on line %s" % (p2[0].line)
0063 coccilib.report.print_report(p1[0],msg)