Skip to content

Commit 19ff804

Browse files
committed
tracing: Simplify calculating entry size using struct_size()
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>
1 parent 3e4272b commit 19ff804

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

kernel/trace/trace_events_synth.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,7 @@ static unsigned int trace_string(struct synth_trace_event *entry,
416416
if (is_dynamic) {
417417
u32 data_offset;
418418

419-
data_offset = offsetof(typeof(*entry), fields);
420-
data_offset += event->n_u64 * sizeof(u64);
419+
data_offset = struct_size(entry, fields, event->n_u64);
421420
data_offset += data_size;
422421

423422
len = kern_fetch_store_strlen((unsigned long)str_val);

0 commit comments

Comments
 (0)