0001 // SPDX-License-Identifier: GPL-2.0
0002 /// Make sure calls to d_find_alias() have a corresponding call to dput().
0003 //
0004 // Keywords: d_find_alias, dput
0005 //
0006 // Confidence: Moderate
0007 // URL: https://coccinelle.gitlabpages.inria.fr/website
0008 // Options: --include-headers
0009
0010 virtual context
0011 virtual org
0012 virtual patch
0013 virtual report
0014
0015 @r exists@
0016 local idexpression struct dentry *dent;
0017 expression E, E1;
0018 statement S1, S2;
0019 position p1, p2;
0020 @@
0021 (
0022 if (!(dent@p1 = d_find_alias(...))) S1
0023 |
0024 dent@p1 = d_find_alias(...)
0025 )
0026
0027 <...when != dput(dent)
0028 when != if (...) { <+... dput(dent) ...+> }
0029 when != true !dent || ...
0030 when != dent = E
0031 when != E = dent
0032 if (!dent || ...) S2
0033 ...>
0034 (
0035 return <+...dent...+>;
0036 |
0037 return @p2 ...;
0038 |
0039 dent@p2 = E1;
0040 |
0041 E1 = dent;
0042 )
0043
0044 @depends on context@
0045 local idexpression struct dentry *r.dent;
0046 position r.p1,r.p2;
0047 @@
0048 * dent@p1 = ...
0049 ...
0050 (
0051 * return@p2 ...;
0052 |
0053 * dent@p2
0054 )
0055
0056
0057 @script:python depends on org@
0058 p1 << r.p1;
0059 p2 << r.p2;
0060 @@
0061 cocci.print_main("Missing call to dput()",p1)
0062 cocci.print_secs("",p2)
0063
0064 @depends on patch@
0065 local idexpression struct dentry *r.dent;
0066 position r.p2;
0067 @@
0068 (
0069 + dput(dent);
0070 return @p2 ...;
0071 |
0072 + dput(dent);
0073 dent@p2 = ...;
0074 )
0075
0076 @script:python depends on report@
0077 p1 << r.p1;
0078 p2 << r.p2;
0079 @@
0080 msg = "Missing call to dput() at line %s."
0081 coccilib.report.print_report(p1[0], msg % (p2[0].line))