tracing: Use flexible array for entry fetch code
PATCH 1/1 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
Signed-off-by Rosen Penev <[email protected]>
--- kernel/trace/trace_probe.c | 8 +------- kernel/trace/trace_probe.h | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-)
kernel/trace/trace_probe.c +1 -7
@@ -838,15 +838,10 @@ static int __store_entry_arg(struct trace_probe *tp, int argnum)int i, offset, last_offset =0 ;if (!earg) { - earg =kzalloc_obj (*tp->entry_arg); + earg =kzalloc_flex (*earg, code,2 * tp->nr_args +1 );if (!earg)return -ENOMEM ; earg->size =2 * tp->nr_args +1 ; - earg->code = kzalloc_objs(struct fetch_insn, earg->size); -if (!earg->code) { -kfree (earg); -return -ENOMEM ; - }/* Fill the code buffer with 'end' to simplify it */ for (i =0 ; i < earg->size; i++) earg->code[i].op =FETCH_OP_END ;
@@ -2051,7 +2046,6 @@ void trace_probe_cleanup(struct trace_probe *tp)traceprobe_free_probe_arg (&tp->args[i]);if (tp->entry_arg) { -kfree (tp->entry_arg->code);kfree (tp->entry_arg); tp->entry_arg =NULL ; }
kernel/trace/trace_probe.h +1 -1
@@ -238,8 +238,8 @@ struct probe_arg { };struct probe_entry_arg { -struct fetch_insn *code;unsigned int size;/* The entry data size */ + struct fetch_insn code[] __counted_by(size); };struct trace_uprobe_filter {
Signature · 1 line
2.54.0
Masami Hiramatsu (Google)
maintainerQuoted 7 lines · On Wed, 20 May 2026 14:58:17 -0700 Rosen Penev <[email protected]> wrote:
Store probe entry fetch instructions in the
probe_entry_argallocation instead of allocating a separate instruction array.This keeps the entry fetch code tied to the entry argument lifetime while leaving regular
probe_arginstruction arrays separately allocated and freed.
Thanks, this looks good to me.
Quoted 53 lines
Assisted-by Codex:GPT-5.5Signed-off-by Rosen Penev <[email protected]>--- kernel/trace/trace_probe.c | 8 +------- kernel/trace/trace_probe.h | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-)kernel/trace/trace_probe.c +1
-7@@ -838,15 +838,10 @@ static int __store_entry_arg(struct trace_probe *tp, int argnum)int i, offset, last_offset =0 ;if (!earg) { - earg =kzalloc_obj (*tp->entry_arg); + earg =kzalloc_flex (*earg, code,2 * tp->nr_args +1 );if (!earg)return -ENOMEM ; earg->size =2 * tp->nr_args +1 ; - earg->code = kzalloc_objs(struct fetch_insn, earg->size); -if (!earg->code) { -kfree (earg); -return -ENOMEM ; - }/* Fill the code buffer with 'end' to simplify it */ for (i =0 ; i < earg->size; i++) earg->code[i].op =FETCH_OP_END ;@@ -2051,7 +2046,6 @@ void trace_probe_cleanup(struct trace_probe *tp)traceprobe_free_probe_arg (&tp->args[i]);if (tp->entry_arg) { -kfree (tp->entry_arg->code);kfree (tp->entry_arg); tp->entry_arg =NULL ; }kernel/trace/trace_probe.h +1
-1@@ -238,8 +238,8 @@ struct probe_arg { };struct probe_entry_arg { -struct fetch_insn *code;unsigned int size;/* The entry data size */ + struct fetch_insn code[] __counted_by(size); };struct trace_uprobe_filter {Signature · 1 line
2.54.0
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>