tracing/probes: cleanup: Set trace_probe::nr_args at trace_probe_init
authorMasami Hiramatsu (Google) <mhiramat@kernel.org>
Mon, 4 Mar 2024 03:40:36 +0000 (12:40 +0900)
committerMasami Hiramatsu (Google) <mhiramat@kernel.org>
Wed, 6 Mar 2024 15:27:15 +0000 (00:27 +0900)
Instead of incrementing the trace_probe::nr_args, init it at
trace_probe_init(). Without this change, there is no way to get the number
of trace_probe arguments while parsing it.
This is a cleanup, so the behavior is not changed.

Link: https://lore.kernel.org/all/170952363585.229804.13060759900346411951.stgit@devnote2/
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
kernel/trace/trace_eprobe.c
kernel/trace/trace_fprobe.c
kernel/trace/trace_kprobe.c
kernel/trace/trace_probe.c
kernel/trace/trace_probe.h
kernel/trace/trace_uprobe.c

index 03c851f5796929a241c55c54563ade66ed184671..eb72def7410f19306ac0481796d42dcdbbb331ae 100644 (file)
@@ -220,7 +220,7 @@ static struct trace_eprobe *alloc_event_probe(const char *group,
        if (!ep->event_system)
                goto error;
 
-       ret = trace_probe_init(&ep->tp, this_event, group, false);
+       ret = trace_probe_init(&ep->tp, this_event, group, false, nargs);
        if (ret < 0)
                goto error;
 
index 3ccef4d82235897d5a0b266b620a76ba8204be6f..5109650b0d82d5672aaa536b8d897f5068f2d0ac 100644 (file)
@@ -389,7 +389,7 @@ static struct trace_fprobe *alloc_trace_fprobe(const char *group,
        tf->tpoint = tpoint;
        tf->fp.nr_maxactive = maxactive;
 
-       ret = trace_probe_init(&tf->tp, event, group, false);
+       ret = trace_probe_init(&tf->tp, event, group, false, nargs);
        if (ret < 0)
                goto error;
 
index c4c6e0e0068be79a966775920903266df86cd8e7..843f13f839df7aee6134fd1f5c3d9b302bf4b5dc 100644 (file)
@@ -290,7 +290,7 @@ static struct trace_kprobe *alloc_trace_kprobe(const char *group,
        INIT_HLIST_NODE(&tk->rp.kp.hlist);
        INIT_LIST_HEAD(&tk->rp.kp.list);
 
-       ret = trace_probe_init(&tk->tp, event, group, false);
+       ret = trace_probe_init(&tk->tp, event, group, false, nargs);
        if (ret < 0)
                goto error;
 
index 67a0b9cbb6485ab2cae45a61dbd764bb97d8ca26..93f36f8a108e6b263cb29783abaaaf0eb1555e0a 100644 (file)
@@ -1423,9 +1423,6 @@ int traceprobe_parse_probe_arg(struct trace_probe *tp, int i, const char *arg,
        struct probe_arg *parg = &tp->args[i];
        const char *body;
 
-       /* Increment count for freeing args in error case */
-       tp->nr_args++;
-
        body = strchr(arg, '=');
        if (body) {
                if (body - arg > MAX_ARG_NAME_LEN) {
@@ -1810,7 +1807,7 @@ void trace_probe_cleanup(struct trace_probe *tp)
 }
 
 int trace_probe_init(struct trace_probe *tp, const char *event,
-                    const char *group, bool alloc_filter)
+                    const char *group, bool alloc_filter, int nargs)
 {
        struct trace_event_call *call;
        size_t size = sizeof(struct trace_probe_event);
@@ -1846,6 +1843,11 @@ int trace_probe_init(struct trace_probe *tp, const char *event,
                goto error;
        }
 
+       tp->nr_args = nargs;
+       /* Make sure pointers in args[] are NULL */
+       if (nargs)
+               memset(tp->args, 0, sizeof(tp->args[0]) * nargs);
+
        return 0;
 
 error:
index c1877d0182691c20eba09e60a98d80daf2dd810a..ed8d1052f8a78177e0c273d25ac59040dc1c8f74 100644 (file)
@@ -338,7 +338,7 @@ static inline bool trace_probe_has_single_file(struct trace_probe *tp)
 }
 
 int trace_probe_init(struct trace_probe *tp, const char *event,
-                    const char *group, bool alloc_filter);
+                    const char *group, bool alloc_filter, int nargs);
 void trace_probe_cleanup(struct trace_probe *tp);
 int trace_probe_append(struct trace_probe *tp, struct trace_probe *to);
 void trace_probe_unlink(struct trace_probe *tp);
index a84b85d8aac12464b80312431e68ceb46c5b19c5..796ebcae9b3809336b01189d10e739ebdc03087d 100644 (file)
@@ -337,7 +337,7 @@ alloc_trace_uprobe(const char *group, const char *event, int nargs, bool is_ret)
        if (!tu)
                return ERR_PTR(-ENOMEM);
 
-       ret = trace_probe_init(&tu->tp, event, group, true);
+       ret = trace_probe_init(&tu->tp, event, group, true, nargs);
        if (ret < 0)
                goto error;