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/
Showing the changes to kernel/trace (2 of 2 files). Show all
Unified · Split
| @@ -838,15 +838,10 @@ static int __store_entry_arg(struct trace_probe *tp, int argnum) · 837 unmodified lines | |||
| 838 | int i, offset, last_offset = 0; | 838 | int i, offset, last_offset = 0; |
| 839 | 839 | ||
| 840 | if (!earg) { | 840 | if (!earg) { |
| 841 | earg = kzalloc_obj(*tp->entry_arg); | 841 | earg = kzalloc_flex(*earg, code, 2 * tp->nr_args + 1); |
| 842 | if (!earg) | 842 | if (!earg) |
| 843 | return -ENOMEM; | 843 | return -ENOMEM; |
| 844 | earg->size = 2 * tp->nr_args + 1; | 844 | 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 | } | ||
| 850 | /* Fill the code buffer with 'end' to simplify it */ | 845 | /* Fill the code buffer with 'end' to simplify it */ |
| 851 | for (i = 0; i < earg->size; i++) | 846 | for (i = 0; i < earg->size; i++) |
| 852 | earg->code[i].op = FETCH_OP_END; | 847 | earg->code[i].op = FETCH_OP_END; |
| @@ -2049,7 +2044,6 @@ void trace_probe_cleanup(struct trace_probe *tp) · 1196 unmodified lines | |||
| 2049 | traceprobe_free_probe_arg(&tp->args[i]); | 2044 | traceprobe_free_probe_arg(&tp->args[i]); |
| 2050 | 2045 | ||
| 2051 | if (tp->entry_arg) { | 2046 | if (tp->entry_arg) { |
| 2052 | kfree(tp->entry_arg->code); | ||
| 2053 | kfree(tp->entry_arg); | 2047 | kfree(tp->entry_arg); |
| 2054 | tp->entry_arg = NULL; | 2048 | tp->entry_arg = NULL; |
| 2055 | } | 2049 | } |
| @@ -238,8 +238,8 @@ struct probe_arg { · 237 unmodified lines | |||
| 238 | }; | 238 | }; |
| 239 | 239 | ||
| 240 | struct probe_entry_arg { | 240 | struct probe_entry_arg { |
| 241 | struct fetch_insn *code; | ||
| 242 | unsigned int size; /* The entry data size */ | 241 | unsigned int size; /* The entry data size */ |
| 242 | struct fetch_insn code[] __counted_by(size); | ||
| 243 | }; | 243 | }; |
| 244 | 244 | ||
| 245 | struct trace_uprobe_filter { | 245 | struct trace_uprobe_filter { |