History

coccinelle: misc: secs_to_jiffies: implement context and report modes

As requested by Ricardo and Jakub, implement report and context modes for the secs_to_jiffies Coccinelle script. While here, add the option to look for opportunities to use secs_to_jiffies() in headers.

Easwar Hariharan committed 1 year ago

Commit 249e7ce1 parent ee132401 file · +44 −5Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/coccinelle/misc/secs_to_jiffies.cocci+44−5
@@ -7,26 +7,65 @@ · 6 unmodified lines
77 // Confidence: High
88 // Copyright: (C) 2024 Easwar Hariharan, Microsoft
99 // Keywords: secs, seconds, jiffies
10−//
10+// Options: --include-headers
1111
1212 virtual patch
13+virtual report
14+virtual context
1315
14−@depends on patch@ constant C; @@
16+@pconst depends on patch@ constant C; @@
1517
1618 - msecs_to_jiffies(C * 1000)
1719 + secs_to_jiffies(C)
1820
19−@depends on patch@ constant C; @@
21+@pconstms depends on patch@ constant C; @@
2022
2123 - msecs_to_jiffies(C * MSEC_PER_SEC)
2224 + secs_to_jiffies(C)
2325
24−@depends on patch@ expression E; @@
26+@pexpr depends on patch@ expression E; @@
2527
2628 - msecs_to_jiffies(E * 1000)
2729 + secs_to_jiffies(E)
2830
29−@depends on patch@ expression E; @@
31+@pexprms depends on patch@ expression E; @@
3032
3133 - msecs_to_jiffies(E * MSEC_PER_SEC)
3234 + secs_to_jiffies(E)
35+
36+@r depends on report && !patch@
37+constant C;
38+expression E;
39+position p;
40+@@
41+
42+(
43+ msecs_to_jiffies(C@p * 1000)
44+|
45+ msecs_to_jiffies(C@p * MSEC_PER_SEC)
46+|
47+ msecs_to_jiffies(E@p * 1000)
48+|
49+ msecs_to_jiffies(E@p * MSEC_PER_SEC)
50+)
51+
52+@c depends on context && !patch@
53+constant C;
54+expression E;
55+@@
56+
57+(
58+* msecs_to_jiffies(C * 1000)
59+|
60+* msecs_to_jiffies(C * MSEC_PER_SEC)
61+|
62+* msecs_to_jiffies(E * 1000)
63+|
64+* msecs_to_jiffies(E * MSEC_PER_SEC)
65+)
66+
67+@script:python depends on report@
68+p << r.p;
69+@@
70+
71+coccilib.report.print_report(p[0], "WARNING opportunity for secs_to_jiffies()")