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

From: Sang-Heon Jeon

Date: Sun Jul 26 2026 - 06:28:22 EST


Hello,

On Sun, Jul 26, 2026 at 4:48 AM Julia Lawall <julia.lawall@xxxxxxxx> wrote:
>
>
>
> 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.

Thanks for the review. Would you please review other patches in this
series as well?

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

Best Regards,
Sang-Heon Jeon