Merge tag 'afs-fixes-04012021' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowe...
[linux-2.6-microblaze.git] / scripts / coccinelle / misc / newline_in_nl_msg.cocci
1 // SPDX-License-Identifier: GPL-2.0-only
2 ///
3 /// Catch strings ending in newline with GENL_SET_ERR_MSG, NL_SET_ERR_MSG,
4 /// NL_SET_ERR_MSG_MOD.
5 ///
6 // Confidence: Very High
7 // Copyright: (C) 2020 Intel Corporation
8 // URL: http://coccinelle.lip6.fr/
9 // Options: --no-includes --include-headers
10
11 virtual context
12 virtual org
13 virtual report
14
15 @r depends on context || org || report@
16 expression e;
17 constant m;
18 position p;
19 @@
20   \(GENL_SET_ERR_MSG\|NL_SET_ERR_MSG\|NL_SET_ERR_MSG_MOD\)(e,m@p)
21
22 @script:python@
23 m << r.m;
24 @@
25
26 if not m.endswith("\\n\""):
27         cocci.include_match(False)
28
29 @r1 depends on r@
30 identifier fname;
31 expression r.e;
32 constant r.m;
33 position r.p;
34 @@
35   fname(e,m@p)
36
37 //----------------------------------------------------------
38 //  For context mode
39 //----------------------------------------------------------
40
41 @depends on context && r@
42 identifier r1.fname;
43 expression r.e;
44 constant r.m;
45 @@
46 * fname(e,m)
47
48 //----------------------------------------------------------
49 //  For org mode
50 //----------------------------------------------------------
51
52 @script:python depends on org@
53 fname << r1.fname;
54 m << r.m;
55 p << r.p;
56 @@
57
58 if m.endswith("\\n\""):
59         msg="WARNING avoid newline at end of message in %s" % (fname)
60         msg_safe=msg.replace("[","@(").replace("]",")")
61         coccilib.org.print_todo(p[0], msg_safe)
62
63 //----------------------------------------------------------
64 //  For report mode
65 //----------------------------------------------------------
66
67 @script:python depends on report@
68 fname << r1.fname;
69 m << r.m;
70 p << r.p;
71 @@
72
73 if m.endswith("\\n\""):
74         msg="WARNING avoid newline at end of message in %s" % (fname)
75         coccilib.report.print_report(p[0], msg)