]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tracing: Use flexible array for entry fetch code
authorRosen Penev <rosenp@gmail.com>
Mon, 1 Jun 2026 14:35:21 +0000 (23:35 +0900)
committerMasami Hiramatsu (Google) <mhiramat@kernel.org>
Mon, 1 Jun 2026 14:35:21 +0000 (23:35 +0900)
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>
kernel/trace/trace_probe.c
kernel/trace/trace_probe.h

index 44c22d4e7881888eda54de4a046912a04d42d61b..695310571b08f897ef2cbb38564d06cef3a63e1c 100644 (file)
@@ -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;
@@ -2049,7 +2044,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;
        }
index 262d8707a3df7983e4c29a9ef3ee43dc4d99b9df..1076f1df347b4acafc17836f1d24c7f273bdb631 100644 (file)
@@ -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 {