Skip to content

Commit cf24cbb

Browse files
nehebmhiramat
authored andcommitted
tracing: Use flexible array for entry fetch code
Store probe entry fetch instructions in the probe_entry_arg allocation instead of allocating a separate instruction array. This keeps the entry fetch code tied to the entry argument lifetime while leaving regular probe_arg instruction arrays separately allocated and freed. Assisted-by: Codex:GPT-5.5 Link: https://lore.kernel.org/all/20260520215817.16560-1-rosenp@gmail.com/ Signed-off-by: Rosen Penev <rosenp@gmail.com> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
1 parent 4304c81 commit cf24cbb

2 files changed

Lines changed: 2 additions & 8 deletions

File tree

kernel/trace/trace_probe.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -838,15 +838,10 @@ static int __store_entry_arg(struct trace_probe *tp, int argnum)
838838
int i, offset, last_offset = 0;
839839

840840
if (!earg) {
841-
earg = kzalloc_obj(*tp->entry_arg);
841+
earg = kzalloc_flex(*earg, code, 2 * tp->nr_args + 1);
842842
if (!earg)
843843
return -ENOMEM;
844844
earg->size = 2 * tp->nr_args + 1;
845-
earg->code = kzalloc_objs(struct fetch_insn, earg->size);
846-
if (!earg->code) {
847-
kfree(earg);
848-
return -ENOMEM;
849-
}
850845
/* Fill the code buffer with 'end' to simplify it */
851846
for (i = 0; i < earg->size; i++)
852847
earg->code[i].op = FETCH_OP_END;
@@ -2049,7 +2044,6 @@ void trace_probe_cleanup(struct trace_probe *tp)
20492044
traceprobe_free_probe_arg(&tp->args[i]);
20502045

20512046
if (tp->entry_arg) {
2052-
kfree(tp->entry_arg->code);
20532047
kfree(tp->entry_arg);
20542048
tp->entry_arg = NULL;
20552049
}

kernel/trace/trace_probe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ struct probe_arg {
238238
};
239239

240240
struct probe_entry_arg {
241-
struct fetch_insn *code;
242241
unsigned int size; /* The entry data size */
242+
struct fetch_insn code[] __counted_by(size);
243243
};
244244

245245
struct trace_uprobe_filter {

0 commit comments

Comments
 (0)