From: Alejandro Colomar <alx@kernel.org>
To: Julia Lawall <julia.lawall@inria.fr>
Cc: cocci@inria.fr, Markus Elfring <Markus.Elfring@web.de>,
Kees Cook <kees@kernel.org>,
Nicolas Palix <nicolas.palix@imag.fr>
Subject: Re: [cocci] [PATCH v3 (resend)] scripts/coccinelle: Add script for using ARRAY_END()
Date: Sun, 27 Sep 2026 12:48:43 +0200 [thread overview]
Message-ID: <arj0PChwFU6aWtRE@debian> (raw)
In-Reply-To: <127f7c71-6ab7-5b4-2540-2e2dc3313a@inria.fr>
[-- Attachment #1: Type: text/plain, Size: 4538 bytes --]
Hi Julia,
> Date: 2026-09-27 11:21:54+0200
> From: Julia Lawall <julia.lawall@inria.fr>
>
>
>
> On Tue, 22 Sep 2026, Alejandro Colomar wrote:
>
> > Recently, we added an ARRAY_END() macro to simplify finding a pointer
> > one past the last element in an array. Such a pointer is often called
> > the 'end', and thus the macro name.
> >
> > Make it easy to find more places where that macro should be used.
> >
> > See also:
> > 436debc9cad8 ("array_size.h: add ARRAY_END()")
> > 8118f197b7b7 ("mm: fix benign off-by-one bugs")
> > a9e5620c9a9e ("kernel: fix off-by-one benign bugs")
> > 61e9210e2392 ("mm: use ARRAY_END() instead of open-coding it")
> >
> > Cc: Kees Cook <kees@kernel.org>
> > Cc: Markus Elfring <Markus.Elfring@web.de>
> > Cc: Julia Lawall <Julia.Lawall@inria.fr>
> > Cc: Nicolas Palix <nicolas.palix@imag.fr>
> > Signed-off-by: Alejandro Colomar <alx@kernel.org>
> > ---
> >
> >
> > Hi Julia,
> >
> > Resent the patch now, as you asked me to do.
>
> Applied, thanks.
>
> Afterwards, I made two changes:
>
> * Add disable zero_multiple_format to each rule to avoid considering
> the possibility that an array index is expressed using '\0'
>
> * Omit outer parentheses on context and org/report rules that
> only match ubt don't transform, since matching a subterm gives
> the same result whether or not the parentheses are present.
Thanks!!
I'll look at the patch to see how it changed, out of curiosity. :)
Have a lovely day!
Alex
>
> julia
>
>
> >
> >
> > Cheers,
> > Alex
> >
> > Here's the original message that came with the patch:
> >
> > Hi!
> >
> > This v3 only has one change: I've removed the comment about the false
> > negatives. They were due to spatch(1) not being able to correctly parse
> > unrelated code elsewhere.
> >
> > See range-diff and interdiff at the bottom.
> >
> >
> > Have a lovely night!
> > Alex
> >
> > scripts/coccinelle/misc/array_end.cocci | 73 +++++++++++++++++++++++++
> > 1 file changed, 73 insertions(+)
> > create mode 100644 scripts/coccinelle/misc/array_end.cocci
> >
> > diff --git a/scripts/coccinelle/misc/array_end.cocci b/scripts/coccinelle/misc/array_end.cocci
> > new file mode 100644
> > index 00000000..88c664de
> > --- /dev/null
> > +++ b/scripts/coccinelle/misc/array_end.cocci
> > @@ -0,0 +1,73 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +/// Use ARRAY_END instead of an expression derived from ARRAY_SIZE
> > +//
> > +// Confidence: High
> > +// Copyright: 2026, Alejandro Colomar <alx@kernel.org>
> > +// Options: --no-includes --include-headers
> > +
> > +virtual patch
> > +virtual context
> > +virtual org
> > +virtual report
> > +
> > +@depends on context@
> > +type T;
> > +T[] a;
> > +expression b;
> > +@@
> > +(
> > +* (a + ARRAY_SIZE(a))
> > +|
> > +* (&a[0] + ARRAY_SIZE(a))
> > +|
> > +* (&a[ARRAY_SIZE(a)])
> > +|
> > +* (&a[ARRAY_SIZE(a) - b])
> > +)
> > +
> > +@depends on patch@
> > +type T;
> > +T[] a;
> > +expression b;
> > +@@
> > +(
> > +- (a + ARRAY_SIZE(a))
> > ++ ARRAY_END(a)
> > +|
> > +- (&a[0] + ARRAY_SIZE(a))
> > ++ ARRAY_END(a)
> > +|
> > +- (&a[ARRAY_SIZE(a)])
> > ++ ARRAY_END(a)
> > +|
> > +- (&a[ARRAY_SIZE(a) - b])
> > ++ ARRAY_END(a) - b
> > +)
> > +
> > +@r depends on org || report@
> > +type T;
> > +T[] a;
> > +expression b;
> > +position p;
> > +@@
> > +(
> > + (a@p + ARRAY_SIZE(a))
> > +|
> > + (&a[0]@p + ARRAY_SIZE(a))
> > +|
> > + (&a[ARRAY_SIZE(a)]@p)
> > +|
> > + (&a[ARRAY_SIZE(a)@p - b])
> > +)
> > +
> > +@script:python depends on org@
> > +p << r.p;
> > +@@
> > +
> > +coccilib.org.print_todo(p[0], "WARNING should use ARRAY_END")
> > +
> > +@script:python depends on report@
> > +p << r.p;
> > +@@
> > +
> > +coccilib.report.print_report(p[0], "WARNING: opportunity for ARRAY_END")
> >
> > Range-diff:
> > 1: 9fd8d3d1 ! 1: 2ae22f8b scripts/coccinelle: Add script for using ARRAY_END()
> > @@ scripts/coccinelle/misc/array_end.cocci (new)
> > +//
> > +// Confidence: High
> > +// Copyright: 2026, Alejandro Colomar <alx@kernel.org>
> > -+// Comments: No known false positives, but has a few false negatives
> > +// Options: --no-includes --include-headers
> > +
> > +virtual patch
> > --
> > 2.53.0
> >
> >
> > ----- End forwarded message -----
> >
> > --
> > <https://www.alejandro-colomar.es>
> >
--
<https://www.alejandro-colomar.es>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
prev parent reply other threads:[~2026-09-27 11:12 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-05 23:20 [cocci] [PATCH v1 0/1] scripts/coccinelle: Add script for using ARRAY_END() Alejandro Colomar
2026-03-05 23:20 ` [cocci] [PATCH v1 1/1] " Alejandro Colomar
2026-03-09 11:17 ` [cocci] [PATCH] " Markus Elfring
2026-03-09 11:59 ` Julia Lawall
2026-03-09 12:16 ` Alejandro Colomar
2026-03-09 12:10 ` Alejandro Colomar
2026-03-09 12:21 ` Julia Lawall
2026-03-09 12:27 ` Alejandro Colomar
2026-03-09 12:13 ` [cocci] [PATCH v2] " Alejandro Colomar
2026-03-09 14:05 ` Markus Elfring
2026-03-09 14:32 ` Alejandro Colomar
2026-03-15 17:17 ` Alejandro Colomar
2026-03-15 17:54 ` Julia Lawall
2026-03-15 22:05 ` Alejandro Colomar
2026-03-16 7:18 ` [cocci] [v2] " Markus Elfring
2026-03-16 10:39 ` Alejandro Colomar
2026-03-16 10:46 ` Markus Elfring
2026-03-15 22:11 ` [cocci] [PATCH v3] " Alejandro Colomar
2026-03-15 22:12 ` Alejandro Colomar
2026-09-21 13:27 ` Alejandro Colomar
2026-09-22 19:34 ` [cocci] [PATCH v3 (resend)] " Alejandro Colomar
2026-09-27 9:21 ` Julia Lawall
2026-09-27 10:48 ` Alejandro Colomar [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=arj0PChwFU6aWtRE@debian \
--to=alx@kernel.org \
--cc=Markus.Elfring@web.de \
--cc=cocci@inria.fr \
--cc=julia.lawall@inria.fr \
--cc=kees@kernel.org \
--cc=nicolas.palix@imag.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox