summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorSang-Heon Jeon <ekffu200098@gmail.com>2026-07-25 20:32:40 +0900
committerJulia Lawall <Julia.Lawall@inria.fr>2026-08-23 22:12:09 +0200
commitbf2fe566a8cbd3671b816223eec8fadd18ec8d77 (patch)
tree480eb871b5864d3f720323e31dca9bfaf2caa0c6 /scripts
parentb6b019a1d9b90ac51174f0ca15b1338b61506bf9 (diff)
coccinelle: double_lock: improve performance when no double lock exists
The 'balanced' rule collects the locks that are taken and released under the same condition, to prevent them from being reported as a double lock. It runs on every file that contains a lock call. To avoid this, collect the double-lock candidates first, so that 'balanced' runs only when one exists. The report then excludes what 'balanced' found. Every double lock that can be reported is also a candidate, so the same reports are made as before and the output does not change. A report-mode run over every .c file in the tree produces identical output. Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com> Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/coccinelle/locks/double_lock.cocci15
1 files changed, 14 insertions, 1 deletions
diff --git a/scripts/coccinelle/locks/double_lock.cocci b/scripts/coccinelle/locks/double_lock.cocci
index 619cfc714409..381060849a7b 100644
--- a/scripts/coccinelle/locks/double_lock.cocci
+++ b/scripts/coccinelle/locks/double_lock.cocci
@@ -38,7 +38,20 @@ write_lock@p1
write_trylock@p1
) (E1@p,...);
-@balanced@
+@r_candidate exists@
+expression x <= locked.E1;
+expression locked.E1;
+expression E2;
+identifier lock;
+position locked.p,p1,p2;
+@@
+
+lock@p1 (E1@p,...);
+... when != E1
+ when != \(x = E2\|&x\)
+lock@p2 (E1,...);
+
+@balanced depends on r_candidate@
position p1 != locked.p1;
position locked.p;
identifier lock,unlock;