Skip to content

Commit 9b97452

Browse files
mwajdeczkees
authored andcommitted
coccinelle: Add rules to find str_up_down() replacements
Add rules for finding places where str_up_down() can be used. This currently finds over 20 locations. Signed-off-by: Michal Wajdeczko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent a98ae7f commit 9b97452

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

scripts/coccinelle/api/string_choices.cocci

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,26 @@ e << str_plural_r.E;
3939
@@
4040
4141
coccilib.report.print_report(p[0], "opportunity for str_plural(%s)" % e)
42+
43+
@str_up_down depends on patch@
44+
expression E;
45+
@@
46+
(
47+
- ((E) ? "up" : "down")
48+
+ str_up_down(E)
49+
)
50+
51+
@str_up_down_r depends on !patch exists@
52+
expression E;
53+
position P;
54+
@@
55+
(
56+
* ((E@P) ? "up" : "down")
57+
)
58+
59+
@script:python depends on report@
60+
p << str_up_down_r.P;
61+
e << str_up_down_r.E;
62+
@@
63+
64+
coccilib.report.print_report(p[0], "opportunity for str_up_down(%s)" % e)

0 commit comments

Comments
 (0)