Re: [PATCH 2/3] coccinelle: double_lock: improve performance when no double lock exists

From: Julia Lawall

Date: Sat Jul 25 2026 - 15:49:06 EST




On Sat, 25 Jul 2026, Sang-Heon Jeon wrote:

> 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.

This is a good preformance improvement. Thanks!

Applied.

julia

>
> Signed-off-by: Sang-Heon Jeon <ekffu200098@xxxxxxxxx>
> ---
> scripts/coccinelle/locks/double_lock.cocci | 15 ++++++++++++++-
> 1 file changed, 14 insertions(+), 1 deletion(-)
>
> 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;
> --
> 2.43.0
>
>