[PATCH v4 1/2] overflow: Add offsetofend() variant of struct_offset()
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Wed Nov 18 12:07:31 UTC 2026
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] coccinelle: struct_offsetof.cocci requires parentheses around
ptr
--
commit bd704e7223e04b0fb7bb740d9f758d180e12c2d8
Author: Bence Csokas <bence.csokas at arm.com>
overflow: Add offsetofend() variant of struct_offset()
This commit adds the struct_offsetofend() helper macro and a Coccinelle
semantic patch to convert offsetof(typeof(*ptr), member) and
offsetofend(typeof(*ptr), member) calls.
> diff --git a/scripts/coccinelle/api/struct_offsetof.cocci b/scripts/coccinelle/api/struct_offsetof.cocci
> new file mode 100644
> index 0000000000000..5a30647d37872
> --- /dev/null
> +++ b/scripts/coccinelle/api/struct_offsetof.cocci
> @@ -0,0 +1,18 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/// Use struct_offset() family of macros
> +///
> +// Confidence: High
> +// Options: --no-includes --ignore ./tools/
> +
> +virtual patch
> +
> + at offsetof depends on patch@
> +expression ptr, member;
> +@@
> +- offsetof(typeof(*(ptr)), member)
> ++ struct_offset(ptr, member)
> + at offsetofend depends on patch@
> +expression ptr, member;
> +@@
> +- offsetofend(typeof(*(ptr)), member)
> ++ struct_offsetofend(ptr, member)
[Severity: Low]
Do the inner parentheses in typeof(*(ptr)) prevent these rules from
matching unparenthesized typeof(*ptr) call sites?
In Coccinelle, the paren isomorphism expands E to (E) in one direction,
so matching typeof(*(ptr)) requires explicit parentheses around ptr in
the C source. Writing typeof(*ptr) matches both typeof(*ptr) and
typeof(*(ptr)).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-offsetof-v4-0-95b385c10b22@arm.com?part=1
More information about the Linux-security-module-archive
mailing list