[PATCH 2/6] coccinelle: add rules to match recently introduced choice helpers

From: Dmitry Antipov

Date: Thu Aug 20 2026 - 02:18:52 EST


Add rules to match 'str_lock{ed}_unlock{ed}' and 'str_pass{ed}_fail{ed}'
string choice helpers.

Signed-off-by: Dmitry Antipov <dmantipov@xxxxxxxxx>
---
scripts/coccinelle/api/string_choices.cocci | 76 +++++++++++++++++++++
1 file changed, 76 insertions(+)

diff --git a/scripts/coccinelle/api/string_choices.cocci b/scripts/coccinelle/api/string_choices.cocci
index 375045086912..77334a84e992 100644
--- a/scripts/coccinelle/api/string_choices.cocci
+++ b/scripts/coccinelle/api/string_choices.cocci
@@ -300,3 +300,79 @@ e << str_yes_no_r.E;
@@

coccilib.report.print_report(p[0], "opportunity for str_yes_no(%s)" % e)
+
+@str_lock_unlock depends on patch@
+expression E;
+@@
+- ((E) ? "lock" : "unlock")
++ str_lock_unlock(E)
+
+@str_lock_unlock_r depends on !patch@
+expression E;
+position P;
+@@
+* E@P ? "lock" : "unlock"
+
+@script:python depends on report@
+p << str_lock_unlock_r.P;
+e << str_lock_unlock_r.E;
+@@
+
+coccilib.report.print_report(p[0], "opportunity for str_lock_unlock(%s)" % e)
+
+@str_locked_unlocked depends on patch@
+expression E;
+@@
+- ((E) ? "locked" : "unlocked")
++ str_locked_unlocked(E)
+
+@str_locked_unlocked_r depends on !patch@
+expression E;
+position P;
+@@
+* E@P ? "locked" : "unlocked"
+
+@script:python depends on report@
+p << str_locked_unlocked_r.P;
+e << str_locked_unlocked_r.E;
+@@
+
+coccilib.report.print_report(p[0], "opportunity for str_locked_unlocked(%s)" % e)
+
+@str_pass_fail depends on patch@
+expression E;
+@@
+- ((E) ? "pass" : "fail")
++ str_pass_fail(E)
+
+@str_pass_fail_r depends on !patch@
+expression E;
+position P;
+@@
+* E@P ? "pass" : "fail"
+
+@script:python depends on report@
+p << str_pass_fail_r.P;
+e << str_pass_fail_r.E;
+@@
+
+coccilib.report.print_report(p[0], "opportunity for str_pass_fail(%s)" % e)
+
+@str_passed_failed depends on patch@
+expression E;
+@@
+- ((E) ? "passed" : "failed")
++ str_passed_failed(E)
+
+@str_passed_failed_r depends on !patch@
+expression E;
+position P;
+@@
+* E@P ? "passed" : "failed"
+
+@script:python depends on report@
+p << str_passed_failed_r.P;
+e << str_passed_failed_r.E;
+@@
+
+coccilib.report.print_report(p[0], "opportunity for str_passed_failed(%s)" % e)
--
2.55.0