]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
coccinelle: Add rules to find str_down_up() replacements
authorKees Cook <kees@kernel.org>
Mon, 12 Aug 2024 18:36:38 +0000 (11:36 -0700)
committerKees Cook <kees@kernel.org>
Thu, 15 Aug 2024 16:26:02 +0000 (09:26 -0700)
As done with str_up_down(), add checks for str_down_up() opportunities.
5 cases currently exist in the tree.

Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20240812183637.work.999-kees@kernel.org
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Kees Cook <kees@kernel.org>
scripts/coccinelle/api/string_choices.cocci

index d517f6bc850b4a2a92e1c542434080db11bc6dab..5e729f187f22ebea49a842bfe941b59fc262ab38 100644 (file)
@@ -62,3 +62,26 @@ e << str_up_down_r.E;
 @@
 
 coccilib.report.print_report(p[0], "opportunity for str_up_down(%s)" % e)
+
+@str_down_up depends on patch@
+expression E;
+@@
+(
+-      ((E) ? "down" : "up")
++      str_down_up(E)
+)
+
+@str_down_up_r depends on !patch exists@
+expression E;
+position P;
+@@
+(
+*      ((E@P) ? "down" : "up")
+)
+
+@script:python depends on report@
+p << str_down_up_r.P;
+e << str_down_up_r.E;
+@@
+
+coccilib.report.print_report(p[0], "opportunity for str_down_up(%s)" % e)