Skip to content

Commit 249e7ce

Browse files
easwarhakpm00
authored andcommitted
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. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Easwar Hariharan <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Closes: https://lore.kernel.org/all/[email protected]/ Tested-by: Ricardo Ribalda <[email protected]> Cc: Julia Lawall <[email protected]> Cc: Nicolas Palix <[email protected]> Cc: Jakub Kicinski <[email protected]> Cc: Ricardo Ribalda <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent ee13240 commit 249e7ce

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

scripts/coccinelle/misc/secs_to_jiffies.cocci

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,65 @@
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()")

0 commit comments

Comments
 (0)