History

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/

Rosen Penev committed 5 months ago

Commit cf24cbb1 parent 4304c812 files · +2 −8Browse files

Unified · Split

2 files
  1. kernel/trace/trace_probe.c +1 −7
  2. kernel/trace/trace_probe.h +1 −1
kernel/trace/trace_probe.c+1−7
@@ -838,15 +838,10 @@ static int __store_entry_arg(struct trace_probe *tp, int argnum) · 837 unmodified lines
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) · 1196 unmodified lines
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+1−1
@@ -238,8 +238,8 @@ struct probe_arg { · 237 unmodified lines
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 {