tracing: Simplify calculating entry size using struct_size()
authorSteven Rostedt (Google) <rostedt@goodmis.org>
Tue, 17 Jan 2023 15:21:26 +0000 (10:21 -0500)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Wed, 25 Jan 2023 15:31:24 +0000 (10:31 -0500)
When tracing a dynamic string field for a synthetic event, the offset
calculation for where to write the next event can use struct_size() to
find what the current size of the structure is.

This simplifies the code and makes it less error prone.

Link: https://lkml.kernel.org/r/20230117152235.698632147@goodmis.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Tom Zanussi <zanussi@kernel.org>
Cc: Ross Zwisler <zwisler@google.com>
Cc: Ching-lin Yu <chinglinyu@google.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/trace/trace_events_synth.c

index 67592eed0be8d6530ec29ba1b804aa335cc6a986..9f79cd689b79299c4b7903da0fdf699284240364 100644 (file)
@@ -416,8 +416,7 @@ static unsigned int trace_string(struct synth_trace_event *entry,
        if (is_dynamic) {
                u32 data_offset;
 
-               data_offset = offsetof(typeof(*entry), fields);
-               data_offset += event->n_u64 * sizeof(u64);
+               data_offset = struct_size(entry, fields, event->n_u64);
                data_offset += data_size;
 
                len = kern_fetch_store_strlen((unsigned long)str_val);