Re: [GIT PULL] tracing: A couple more fixes to v6.18
From: Linus Torvalds
Date: Sat Oct 11 2025 - 19:09:38 EST
On Sat, 11 Oct 2025 at 12:52, Steven Rostedt <rostedt@xxxxxxxxxxx> 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.
Linus