]> Gentwo Git Trees - linux/.git/commitdiff
tracing: probes: Use __free() for trace_probe_log
authorMasami Hiramatsu (Google) <mhiramat@kernel.org>
Thu, 25 Sep 2025 00:56:47 +0000 (09:56 +0900)
committerMasami Hiramatsu (Google) <mhiramat@kernel.org>
Fri, 31 Oct 2025 16:10:28 +0000 (01:10 +0900)
Use __free() for trace_probe_log_clear() to cleanup error log interface.

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

index a1d402124836a15e95cd5c4aff639673f7f8bf60..aaba765d54cfee2de119cc366f579db7c896a1ee 100644 (file)
@@ -874,6 +874,7 @@ static int __trace_eprobe_create(int argc, const char *argv[])
         * Fetch args (no space):
         *  <name>=$<field>[:TYPE]
         */
+       const char *trlog __free(trace_probe_log_clear) = NULL;
        const char *event = NULL, *group = EPROBE_EVENT_SYSTEM;
        const char *sys_event = NULL, *sys_name = NULL;
        struct trace_event_call *event_call;
@@ -887,7 +888,7 @@ static int __trace_eprobe_create(int argc, const char *argv[])
        if (argc < 2 || argv[0][0] != 'e')
                return -ECANCELED;
 
-       trace_probe_log_init("event_probe", argc, argv);
+       trlog = trace_probe_log_init("event_probe", argc, argv);
 
        event = strchr(&argv[0][1], ':');
        if (event) {
@@ -987,7 +988,6 @@ static int __trace_eprobe_create(int argc, const char *argv[])
                        goto error;
                }
        }
-       trace_probe_log_clear();
        return ret;
 
 mem_error:
@@ -996,7 +996,6 @@ static int __trace_eprobe_create(int argc, const char *argv[])
 parse_error:
        ret = -EINVAL;
 error:
-       trace_probe_log_clear();
        trace_event_probe_cleanup(ep);
        return ret;
 }
index 5cbdc423afebcf33cddc6a4a32474c67f2e6278f..5b92376a58fcbc03b3df6a9d0d8a5d2a02372ad4 100644 (file)
@@ -156,7 +156,7 @@ static const struct fetch_type *find_fetch_type(const char *type, unsigned long
 static struct trace_probe_log trace_probe_log;
 extern struct mutex dyn_event_ops_mutex;
 
-void trace_probe_log_init(const char *subsystem, int argc, const char **argv)
+const char *trace_probe_log_init(const char *subsystem, int argc, const char **argv)
 {
        lockdep_assert_held(&dyn_event_ops_mutex);
 
@@ -164,6 +164,7 @@ void trace_probe_log_init(const char *subsystem, int argc, const char **argv)
        trace_probe_log.argc = argc;
        trace_probe_log.argv = argv;
        trace_probe_log.index = 0;
+       return subsystem;
 }
 
 void trace_probe_log_clear(void)
index 08b5bda24da2253db529f27cd0666d60a798ebd5..9fc56c937130456441f76fc5f1166782c7d8564f 100644 (file)
@@ -578,11 +578,13 @@ struct trace_probe_log {
        int             index;
 };
 
-void trace_probe_log_init(const char *subsystem, int argc, const char **argv);
+const char *trace_probe_log_init(const char *subsystem, int argc, const char **argv);
 void trace_probe_log_set_index(int index);
 void trace_probe_log_clear(void);
 void __trace_probe_log_err(int offset, int err);
 
+DEFINE_FREE(trace_probe_log_clear, const char *, if (_T) trace_probe_log_clear())
+
 #define trace_probe_log_err(offs, err) \
        __trace_probe_log_err(offs, TP_ERR_##err)
 
index 430d09c49462dd327402f9131888796a694db599..b3d39b5b0690bd5e5e66a5ea10b070aab70e1156 100644 (file)
@@ -539,6 +539,7 @@ static int register_trace_uprobe(struct trace_uprobe *tu)
  */
 static int __trace_uprobe_create(int argc, const char **argv)
 {
+       const char *trlog __free(trace_probe_log_clear) = NULL;
        const char *event = NULL, *group = UPROBE_EVENT_SYSTEM;
        char *arg, *filename, *rctr, *rctr_end, *tmp;
        unsigned long offset, ref_ctr_offset;
@@ -565,7 +566,7 @@ static int __trace_uprobe_create(int argc, const char **argv)
        if (argc < 2)
                return -ECANCELED;
 
-       trace_probe_log_init("trace_uprobe", argc, argv);
+       trlog = trace_probe_log_init("trace_uprobe", argc, argv);
 
        if (argc - 2 > MAX_TRACE_ARGS) {
                trace_probe_log_set_index(2);
@@ -597,7 +598,6 @@ static int __trace_uprobe_create(int argc, const char **argv)
        if (ret) {
                trace_probe_log_err(0, FILE_NOT_FOUND);
                kfree(filename);
-               trace_probe_log_clear();
                return ret;
        }
        if (!d_is_reg(path.dentry)) {
@@ -728,14 +728,12 @@ static int __trace_uprobe_create(int argc, const char **argv)
 error:
        free_trace_uprobe(tu);
 out:
-       trace_probe_log_clear();
        return ret;
 
 fail_mem:
        ret = -ENOMEM;
 
 fail_address_parse:
-       trace_probe_log_clear();
        path_put(&path);
        kfree(filename);