[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251011193742.410cea9d@gandalf.local.home>
Date: Sat, 11 Oct 2025 19:37:42 -0400
From: Steven Rostedt <rostedt@...dmis.org>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Kees Cook <kees@...nel.org>, LKML <linux-kernel@...r.kernel.org>, Masami
Hiramatsu <mhiramat@...nel.org>, Mathieu Desnoyers
<mathieu.desnoyers@...icios.com>, Andrew Morton <akpm@...ux-foundation.org>
Subject: Re: [GIT PULL] tracing: A couple more fixes to v6.18
On Sat, 11 Oct 2025 16:09:18 -0700
Linus Torvalds <torvalds@...ux-foundation.org> wrote:
> On Sat, 11 Oct 2025 at 12:52, Steven Rostedt <rostedt@...dmis.org> wrote:
> >
> > + /* cnt includes both the entry->id and the data behind it. */
> > + size = struct_size(entry, buf, cnt - sizeof(entry->id));
>
> This seems very non-intuitive.
>
> Why isn't it just saying
>
> size = cnt + offsetof(struct raw_data_entry, id);
>
> which would seem to be much more straightforward than saying "go to
> the end, and then subtract out the size of this entry" - which then
> relies on the entry being the last thing in the struct.
>
> And if somebody wants to have a helper like
>
> #define struct_offset(s,memb) (offsetof(typeof(*(s)), memb))
>
> in order to get some kind of "typesafe offsetof", to go with 'struct
> size' then by all means.. That would make it be just
>
> size = cnt + struct_offset(entry, id);
>
> which looks fairly legible and logical, and would go with the comment
> (and would pair fairly well with our other "struct_xyz()" helpers, I
> think).
>
> I've pulled this, I just reacted to how odd that calculation looked.
> It makes very little sense to me, since the calculation really has
> _nothing_ do with the size of the struct, and you explicitly have to
> play tricks to get the offset that way.
I could make this change for the next merge window.
I originally was going to change it to:
size = sizeof(*entry) + cnt - sizeof(entry->id);
But figured using a macro would be better.
Honestly, I didn't like either solution. But having a:
size = struct_offset(entry, id) + cnt
Would probably look better.
But again, it can probably wait till 6.19.
-- Steve
Powered by blists - more mailing lists