[PATCH 1/3] stddef: Add offsetofp() and offsetofendp() for pointer arithmetic
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Thu Nov 5 17:25:50 UTC 2026
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] stddef: offsetofp() duplicates existing struct_offset() macro
--
commit 1381df6311c78f1d5db9e362d720874ccb5bad75
Author: Bence Csokas <bence.csokas at arm.com>
stddef: Add offsetofp() and offsetofendp() for pointer arithmetic
This commit introduces offsetofp() and offsetofendp() in
include/linux/stddef.h as convenience wrappers around offsetof() and
offsetofend() that take a struct pointer instead of a struct type.
> diff --git a/include/linux/stddef.h b/include/linux/stddef.h
> index e1851c50c89b5..87f0e131d2350 100644
> --- a/include/linux/stddef.h
> +++ b/include/linux/stddef.h
> @@ -32,6 +32,22 @@ enum {
> #define offsetofend(TYPE, MEMBER) \
> (offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER))
>
> +/**
> + * offsetofp() - Get the offset of a struct field from a pointer to the struct
> + *
> + * @P: Pointer to the structure
> + * @MEMBER: The member within the structure to get the start offset of
> + */
> +#define offsetofp(P, MEMBER) offsetof(typeof(*(P)), MEMBER)
> +
> +/**
> + * offsetofendp() - Get the end of a struct field from a pointer to the struct
> + *
> + * @P: Pointer to the structure
> + * @MEMBER: The member within the structure to get the end offset of
> + */
> +#define offsetofendp(P, MEMBER) offsetofend(typeof(*(P)), MEMBER)
[Severity: Low]
This isn't a bug, but commit f6ed9c5d3190 ("overflow: Implement
size_t saturating arithmetic helpers") already added struct_offset() in
include/linux/overflow.h with the same definition:
#define struct_offset(p, member) (offsetof(typeof(*(p)), member))
which is currently used in kernel/trace/trace.c and
sound/soc/codecs/cs-amp-lib.c, following the struct_size(p, member, count)
vs struct_size_t(type, member, count) naming convention.
Should offsetofp() and struct_offset() be consolidated (and offsetofendp()
aligned with the chosen naming convention) so there aren't two redundant
macros for pointer-based member offsets across the tree?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261105-offsetof-v1-0-4153f5c10edc@arm.com?part=1
More information about the Linux-security-module-archive
mailing list