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

Unified · Split

scripts/coccinelle/misc/secs_to_jiffies.cocci+44−5
@@ -7,26 +7,65 @@ · 6 unmodified lines
7// Confidence: High7// Confidence: High
8// Copyright: (C) 2024 Easwar Hariharan, Microsoft8// Copyright: (C) 2024 Easwar Hariharan, Microsoft
9// Keywords: secs, seconds, jiffies9// Keywords: secs, seconds, jiffies
10//10// Options: --include-headers
11 11
12virtual patch12virtual patch
13virtual report
14virtual context
13 15
14@depends on patch@ constant C; @@16@pconst depends on patch@ constant C; @@
15 17
16- msecs_to_jiffies(C * 1000)18- msecs_to_jiffies(C * 1000)
17+ secs_to_jiffies(C)19+ secs_to_jiffies(C)
18 20
19@depends on patch@ constant C; @@21@pconstms depends on patch@ constant C; @@
20 22
21- msecs_to_jiffies(C * MSEC_PER_SEC)23- msecs_to_jiffies(C * MSEC_PER_SEC)
22+ secs_to_jiffies(C)24+ secs_to_jiffies(C)
23 25
24@depends on patch@ expression E; @@26@pexpr depends on patch@ expression E; @@
25 27
26- msecs_to_jiffies(E * 1000)28- msecs_to_jiffies(E * 1000)
27+ secs_to_jiffies(E)29+ secs_to_jiffies(E)
28 30
29@depends on patch@ expression E; @@31@pexprms depends on patch@ expression E; @@
30 32
31- msecs_to_jiffies(E * MSEC_PER_SEC)33- msecs_to_jiffies(E * MSEC_PER_SEC)
32+ secs_to_jiffies(E)34+ secs_to_jiffies(E)
35
36@r depends on report && !patch@
37constant C;
38expression E;
39position 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@
53constant C;
54expression 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@
68p << r.p;
69@@
70
71coccilib.report.print_report(p[0], "WARNING opportunity for secs_to_jiffies()")