Re: [PATCH v3 3/5] tracing: Use __free() for kprobe events to cleanup
From: Steven Rostedt
Date: Tue Jan 07 2025 - 10:41:09 EST
On Tue, 7 Jan 2025 20:50:35 +0900
"Masami Hiramatsu (Google)" <mhiramat@xxxxxxxxxx> wrote:
> @@ -1898,7 +1899,8 @@ create_local_trace_kprobe(char *func, void *addr, unsigned long offs,
> bool is_return)
> {
> enum probe_print_type ptype;
> - struct trace_kprobe *tk;
> + struct trace_kprobe *tk __free(free_trace_kprobe) = NULL;
> + struct trace_probe *tp;
> int ret;
> char *event;
>
> @@ -1929,19 +1931,16 @@ create_local_trace_kprobe(char *func, void *addr, unsigned long offs,
>
> ptype = trace_kprobe_is_return(tk) ?
> PROBE_PRINT_RETURN : PROBE_PRINT_NORMAL;
> - if (traceprobe_set_print_fmt(&tk->tp, ptype) < 0) {
> - ret = -ENOMEM;
> - goto error;
> - }
> + if (traceprobe_set_print_fmt(&tk->tp, ptype) < 0)
> + return ERR_PTR(-ENOMEM);
>
> ret = __register_trace_kprobe(tk);
> if (ret < 0)
> - goto error;
> + return ERR_PTR(ret);
>
> - return trace_probe_event_call(&tk->tp);
> -error:
> - free_trace_kprobe(tk);
> - return ERR_PTR(ret);
> + tp = &tk->tp;
> + tk = NULL; /* 'tk' is registered successfully, so do not free. */
I wonder if we could change the above to just:
tp = &(no_free_ptr(tk)->tp);
?
-- Steve
> + return trace_probe_event_call(tp);
> }
>
> void destroy_local_trace_kprobe(struct trace_event_call *event_call)