diff mbox series

coccinelle: Add rules to find str_down_up() replacements

Message ID 20240812183637.work.999-kees@kernel.org (mailing list archive)
State Mainlined
Commit 0336f898881ae13b92dfd8b72e69ed1246eac762
Headers show
Series coccinelle: Add rules to find str_down_up() replacements | expand

Commit Message

Kees Cook Aug. 12, 2024, 6:36 p.m. UTC
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>
Signed-off-by: Kees Cook <kees@kernel.org>
---
Cc: Andy Shevchenko <andy@kernel.org>
Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: Julia Lawall <Julia.Lawall@inria.fr>
Cc: Nicolas Palix <nicolas.palix@imag.fr>
Cc: linux-hardening@vger.kernel.org
Cc: cocci@inria.fr
---
 scripts/coccinelle/api/string_choices.cocci | 23 +++++++++++++++++++++
 1 file changed, 23 insertions(+)

Comments

Andy Shevchenko Aug. 12, 2024, 7:49 p.m. UTC | #1
On Mon, Aug 12, 2024 at 11:36:38AM -0700, Kees Cook wrote:
> As done with str_up_down(), add checks for str_down_up() opportunities.
> 5 cases currently exist in the tree.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
diff mbox series

Patch

diff --git a/scripts/coccinelle/api/string_choices.cocci b/scripts/coccinelle/api/string_choices.cocci
index d517f6bc850b..5e729f187f22 100644
--- a/scripts/coccinelle/api/string_choices.cocci
+++ b/scripts/coccinelle/api/string_choices.cocci
@@ -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)