[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <6219BF5A-0EC3-4111-A329-D35244C9714A@kernel.org>
Date: Thu, 27 Nov 2025 18:00:01 -0800
From: Kees Cook <kees@...nel.org>
To: Steven Rostedt <rostedt@...dmis.org>
CC: LKML <linux-kernel@...r.kernel.org>, linux-hardening@...r.kernel.org,
Linux Trace Kernel <linux-trace-kernel@...r.kernel.org>,
Masami Hiramatsu <mhiramat@...nel.org>,
Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
"Gustavo A. R. Silva" <gustavoars@...nel.org>
Subject: Re: [PATCH] overflow: Introduce struct_offset() to get offset of member
On November 27, 2025 5:43:42 PM PST, Steven Rostedt <rostedt@...dmis.org> wrote:
>On Wed, 26 Nov 2025 23:58:01 -0800
>Kees Cook <kees@...nel.org> wrote:
>
>> > +/**
>> > + * struct_offset() - Calculate the offset of a member within a struct
>> > + * @p: Pointer to the struct
>> > + * @member: Name of the member to get the offset of
>> > + *
>> > + * Calculates the offset of a particular @member of the structure pointed
>> > + * to by @p.
>> > + *
>> > + * Return: number of bytes to the location of @member.
>> > + */
>> > +#define struct_offset(p, member) (offsetof(typeof(*(p)), member))
>>
>> I wonder if the kerndoc for this and offsetof() should reference each
>> other? "For a type instead of a pointer, use offsetof()" etc...
>
>I know I pushed this to my for-next branch already, but it's the top
>patch. Looking at my code, I actually have a lot of places that use the
>offsetof() for a structure variable and not a pointer to a structure.
>
>Thus, I wonder if it is better to have this as:
>
>#define struct_offset(s, member) (offsetof(typeof(s), member))
I'd rather it keep the same API style as struct_size() if it's going to share the naming style.
If you have an instance and not a pointer, just slap on a & :)
--
Kees Cook
Powered by blists - more mailing lists