Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /// Find missing clk_puts.
0003 ///
0004 //# This only signals a missing clk_put when there is a clk_put later
0005 //# in the same function.
0006 //# False positives can be due to loops.
0007 //
0008 // Confidence: Moderate
0009 // Copyright: (C) 2012 Julia Lawall, INRIA/LIP6.
0010 // Copyright: (C) 2012 Gilles Muller, INRIA/LiP6.
0011 // URL: https://coccinelle.gitlabpages.inria.fr/website
0012 // Comments:
0013 // Options:
0014 
0015 virtual context
0016 virtual org
0017 virtual report
0018 
0019 @clk@
0020 expression e;
0021 statement S,S1;
0022 int ret;
0023 position p1,p2,p3;
0024 @@
0025 
0026 e = clk_get@p1(...)
0027 ... when != clk_put(e)
0028 if (<+...e...+>) S
0029 ... when any
0030     when != clk_put(e)
0031     when != if (...) { ... clk_put(e); ... }
0032 (
0033  if (ret == 0) S1
0034 |
0035 if (...)
0036    { ...
0037      return 0; }
0038 |
0039 if (...)
0040    { ...
0041      return <+...e...+>; }
0042 |
0043 *if@p2 (...)
0044    { ... when != clk_put(e)
0045          when forall
0046      return@p3 ...; }
0047 )
0048 ... when any
0049 clk_put(e);
0050 
0051 @script:python depends on org@
0052 p1 << clk.p1;
0053 p2 << clk.p2;
0054 p3 << clk.p3;
0055 @@
0056 
0057 cocci.print_main("clk_get",p1)
0058 cocci.print_secs("if",p2)
0059 cocci.print_secs("needed clk_put",p3)
0060 
0061 @script:python depends on report@
0062 p1 << clk.p1;
0063 p2 << clk.p2;
0064 p3 << clk.p3;
0065 @@
0066 
0067 msg = "ERROR: missing clk_put; clk_get on line %s and execution via conditional on line %s" % (p1[0].line,p2[0].line)
0068 coccilib.report.print_report(p3[0],msg)