From nobody Sat Oct 4 19:15:56 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D96602EACF6; Wed, 13 Aug 2025 14:29:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755095390; cv=none; b=ayQvnMRX7V/n/BxfjzEld3BpNgZx9UVmGGgDxG+oqmJ+sHZd/aqTmTYJMfmk07GvACGFxI0FR2xV3UbzU2vXn0GIBLJsgLViSLc+vf/fmGc5JU3tXW9Ln5gsR10Kr/0bNXLaou/4WPoWd+lQTLtoPUyqOqB2mWZ7bzjHIL09W+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755095390; c=relaxed/simple; bh=KtZOOoU0yNnyX0bs6ukfbHdLNrul7k2oPOAIlTcgzIg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MFOLq6r1Hc8zNvyJtZIMjREbFxsBIryJ5tKPlJrbPWDQCrO8Wyw7sDXIbKWQv7dTPVb/vop4rLNgQkyigEKLr9Dtazlo9dOthEAwZZwTAge8YriAI3eoVMKkfWO0uF5Fr2zp7N3czI3lwtzDEGvnnq9D+7a+r3OG2UzX6qGgkI8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=I42ZjTtD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="I42ZjTtD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6A69C4CEEB; Wed, 13 Aug 2025 14:29:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755095390; bh=KtZOOoU0yNnyX0bs6ukfbHdLNrul7k2oPOAIlTcgzIg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I42ZjTtDRVKB7SR84WgEp8XT6HIJQL4anw4JwP0t+l/3IziYJzavo9naZih5tXXoC ky+ddu/ybGgdO24l7/Yo6pgerlVFIUBzL12VgdfwL0fB7Yq0VyZWqlVf69OnSJF2hU oPx8OiLeadZNQIX5DCqhE82745ViYqi82srPpKyyk6xPdrBwt8JZ/U9B9TxSAfXVSL 7L4RwlutX0XiQPMDitHAs6iysSkT7UYCAPNvmYNnVycmArkZLfmBE5haPDlDtucEd/ WwJsZxAAw4hLDEmSqqmJAU0gJLPH5bY153Zf49igwOcTQYSH4/JwolofCu7v9pLeOd ZnsXDlC1mNl8w== From: "Masami Hiramatsu (Google)" To: Steven Rostedt , Mathieu Desnoyers Cc: Masami Hiramatsu , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH 1/4] tracing: probes: Use __free() for trace_probe_log Date: Wed, 13 Aug 2025 23:29:46 +0900 Message-ID: <175509538609.193596.16646724647358218778.stgit@devnote2> X-Mailer: git-send-email 2.43.0 In-Reply-To: <175509537667.193596.9139462012987606126.stgit@devnote2> References: <175509537667.193596.9139462012987606126.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Masami Hiramatsu (Google) Use __free() for trace_probe_log_clear() to cleanup error log interface. Signed-off-by: Masami Hiramatsu (Google) --- kernel/trace/trace_eprobe.c | 5 ++--- kernel/trace/trace_probe.c | 3 ++- kernel/trace/trace_probe.h | 4 +++- kernel/trace/trace_uprobe.c | 6 ++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c index a1d402124836..aaba765d54cf 100644 --- a/kernel/trace/trace_eprobe.c +++ b/kernel/trace/trace_eprobe.c @@ -874,6 +874,7 @@ static int __trace_eprobe_create(int argc, const char *= argv[]) * Fetch args (no space): * =3D$[:TYPE] */ + const char *trlog __free(trace_probe_log_clear) =3D NULL; const char *event =3D NULL, *group =3D EPROBE_EVENT_SYSTEM; const char *sys_event =3D NULL, *sys_name =3D 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] !=3D 'e') return -ECANCELED; =20 - trace_probe_log_init("event_probe", argc, argv); + trlog =3D trace_probe_log_init("event_probe", argc, argv); =20 event =3D 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; =20 mem_error: @@ -996,7 +996,6 @@ static int __trace_eprobe_create(int argc, const char *= argv[]) parse_error: ret =3D -EINVAL; error: - trace_probe_log_clear(); trace_event_probe_cleanup(ep); return ret; } diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index 5cbdc423afeb..5b92376a58fc 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -156,7 +156,7 @@ static const struct fetch_type *find_fetch_type(const c= har *type, unsigned long static struct trace_probe_log trace_probe_log; extern struct mutex dyn_event_ops_mutex; =20 -void trace_probe_log_init(const char *subsystem, int argc, const char **ar= gv) +const char *trace_probe_log_init(const char *subsystem, int argc, const ch= ar **argv) { lockdep_assert_held(&dyn_event_ops_mutex); =20 @@ -164,6 +164,7 @@ void trace_probe_log_init(const char *subsystem, int ar= gc, const char **argv) trace_probe_log.argc =3D argc; trace_probe_log.argv =3D argv; trace_probe_log.index =3D 0; + return subsystem; } =20 void trace_probe_log_clear(void) diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h index 842383fbc03b..76bf2dee8071 100644 --- a/kernel/trace/trace_probe.h +++ b/kernel/trace/trace_probe.h @@ -573,11 +573,13 @@ struct trace_probe_log { int index; }; =20 -void trace_probe_log_init(const char *subsystem, int argc, const char **ar= gv); +const char *trace_probe_log_init(const char *subsystem, int argc, const ch= ar **argv); void trace_probe_log_set_index(int index); void trace_probe_log_clear(void); void __trace_probe_log_err(int offset, int err); =20 +DEFINE_FREE(trace_probe_log_clear, const char *, if (_T) trace_probe_log_c= lear()) + #define trace_probe_log_err(offs, err) \ __trace_probe_log_err(offs, TP_ERR_##err) =20 diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c index 8b0bcc0d8f41..722316b3dc16 100644 --- a/kernel/trace/trace_uprobe.c +++ b/kernel/trace/trace_uprobe.c @@ -539,6 +539,7 @@ static int register_trace_uprobe(struct trace_uprobe *t= u) */ static int __trace_uprobe_create(int argc, const char **argv) { + const char *trlog __free(trace_probe_log_clear) =3D NULL; const char *event =3D NULL, *group =3D 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; =20 - trace_probe_log_init("trace_uprobe", argc, argv); + trlog =3D trace_probe_log_init("trace_uprobe", argc, argv); =20 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; =20 fail_mem: ret =3D -ENOMEM; =20 fail_address_parse: - trace_probe_log_clear(); path_put(&path); kfree(filename); From nobody Sat Oct 4 19:15:56 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA4782EACF6; Wed, 13 Aug 2025 14:29:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755095399; cv=none; b=KVujMB/2TWGzKOO81tyMZtsQwR6slaoOLGYmjKcrcgDBlFiq18GSY2ov0tBR6yFKUkxdgmdeiGooJG3M1w3R9QHloKaUvOILkczXbND8QGIrbFfGLkrzyat2dJBLoQHw5v9pOtm7oiV1ZxGewoLZbN0UvYB36WVmuL060SQGzzQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755095399; c=relaxed/simple; bh=oAEVYAf3dzCEcckSbjnoduKc/tJlsEEvbBAJNtGqAd0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rRa6SbqONNTUhh8kp6qJm2+d0VPPd1YPrHDvccjuJWgHQEkmDDSXgPP7PxgFNcCDcSOSWG+92wrnMDmOQDEADr8zj9y+fV3NX0QVXIadOzUk25VUpu7nO7KStlXZt/hRcqHvmoI79Zjav8/W+C+GicLnuM2gTeeLdmFMWFZMtTY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=f2D2Uu4P; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="f2D2Uu4P" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E875C4CEEB; Wed, 13 Aug 2025 14:29:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755095399; bh=oAEVYAf3dzCEcckSbjnoduKc/tJlsEEvbBAJNtGqAd0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f2D2Uu4PPO9CxjojV19+JqJ6dKOW7c6vk1qiocVZ5I8+9tAHE0bpJkte/VPfiQGLm qYfWDJOFcRxxejH7hQgpwac6W4GnZ8gIkD+woDgvfV1gVx2ilh3UHHdurMR+w6B3qf fWhuVeRjEBndCcLRKI9D4kf2I+VS5rI1cMt/XjHGwpLCigGTUO56C6cSxJ8kFxKcGw NGDPF30EfBZnx433LayklqlS3O7DCW3a05uuxsZAWC28syCE03T1T7DKlUZOb8PXU6 cssZ30Zs2urBdjjcsi6FuwLWWLRyKyyEWK8kSHyDK/cekn4GIIaAvN+KKEGjDiAdtC Dpx1zk+bgPS9Q== From: "Masami Hiramatsu (Google)" To: Steven Rostedt , Mathieu Desnoyers Cc: Masami Hiramatsu , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH 2/4] tracing: eprobe: Cleanup eprobe event using __free() Date: Wed, 13 Aug 2025 23:29:55 +0900 Message-ID: <175509539571.193596.4674012182718751429.stgit@devnote2> X-Mailer: git-send-email 2.43.0 In-Reply-To: <175509537667.193596.9139462012987606126.stgit@devnote2> References: <175509537667.193596.9139462012987606126.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Masami Hiramatsu (Google) Use __free(trace_event_probe_cleanup) to remove unneeded gotos and cleanup the last part of trace_eprobe_parse_filter(). Signed-off-by: Masami Hiramatsu (Google) --- kernel/trace/trace_eprobe.c | 71 ++++++++++++++++++---------------------= ---- 1 file changed, 30 insertions(+), 41 deletions(-) diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c index aaba765d54cf..f7a1ff509d7e 100644 --- a/kernel/trace/trace_eprobe.c +++ b/kernel/trace/trace_eprobe.c @@ -61,6 +61,9 @@ static void trace_event_probe_cleanup(struct trace_eprobe= *ep) kfree(ep); } =20 +DEFINE_FREE(trace_event_probe_cleanup, struct trace_eprobe *, + if (!IS_ERR_OR_NULL(_T)) trace_event_probe_cleanup(_T)) + static struct trace_eprobe *to_trace_eprobe(struct dyn_event *ev) { return container_of(ev, struct trace_eprobe, devent); @@ -197,10 +200,10 @@ static struct trace_eprobe *alloc_event_probe(const c= har *group, struct trace_event_call *event, int nargs) { - struct trace_eprobe *ep; + struct trace_eprobe *ep __free(trace_event_probe_cleanup) =3D NULL; const char *event_name; const char *sys_name; - int ret =3D -ENOMEM; + int ret; =20 if (!event) return ERR_PTR(-ENODEV); @@ -211,25 +214,22 @@ static struct trace_eprobe *alloc_event_probe(const c= har *group, ep =3D kzalloc(struct_size(ep, tp.args, nargs), GFP_KERNEL); if (!ep) { trace_event_put_ref(event); - goto error; + return ERR_PTR(-ENOMEM); } ep->event =3D event; ep->event_name =3D kstrdup(event_name, GFP_KERNEL); if (!ep->event_name) - goto error; + return ERR_PTR(-ENOMEM); ep->event_system =3D kstrdup(sys_name, GFP_KERNEL); if (!ep->event_system) - goto error; + return ERR_PTR(-ENOMEM); =20 ret =3D trace_probe_init(&ep->tp, this_event, group, false, nargs); if (ret < 0) - goto error; + return ERR_PTR(ret); =20 dyn_event_init(&ep->devent, &eprobe_dyn_event_ops); - return ep; -error: - trace_event_probe_cleanup(ep); - return ERR_PTR(ret); + return_ptr(ep); } =20 static int eprobe_event_define_fields(struct trace_event_call *event_call) @@ -856,13 +856,10 @@ static int trace_eprobe_parse_filter(struct trace_epr= obe *ep, int argc, const ch ret =3D create_event_filter(top_trace_array(), ep->event, ep->filter_str, true, &dummy); free_event_filter(dummy); - if (ret) - goto error; - - return 0; -error: - kfree(ep->filter_str); - ep->filter_str =3D NULL; + if (ret) { + kfree(ep->filter_str); + ep->filter_str =3D NULL; + } return ret; } =20 @@ -874,6 +871,7 @@ static int __trace_eprobe_create(int argc, const char *= argv[]) * Fetch args (no space): * =3D$[:TYPE] */ + struct trace_eprobe *ep __free(trace_event_probe_cleanup) =3D NULL; const char *trlog __free(trace_probe_log_clear) =3D NULL; const char *event =3D NULL, *group =3D EPROBE_EVENT_SYSTEM; const char *sys_event =3D NULL, *sys_name =3D NULL; @@ -881,7 +879,6 @@ static int __trace_eprobe_create(int argc, const char *= argv[]) char *buf1 __free(kfree) =3D NULL; char *buf2 __free(kfree) =3D NULL; char *gbuf __free(kfree) =3D NULL; - struct trace_eprobe *ep =3D NULL; int ret =3D 0, filter_idx =3D 0; int i, filter_cnt; =20 @@ -894,12 +891,12 @@ static int __trace_eprobe_create(int argc, const char= *argv[]) if (event) { gbuf =3D kmalloc(MAX_EVENT_NAME_LEN, GFP_KERNEL); if (!gbuf) - goto mem_error; + return -ENOMEM; event++; ret =3D traceprobe_parse_event_name(&event, &group, gbuf, event - argv[0]); if (ret) - goto parse_error; + return -EINVAL; } =20 trace_probe_log_set_index(1); @@ -907,18 +904,18 @@ static int __trace_eprobe_create(int argc, const char= *argv[]) =20 buf2 =3D kmalloc(MAX_EVENT_NAME_LEN, GFP_KERNEL); if (!buf2) - goto mem_error; + return -ENOMEM; =20 ret =3D traceprobe_parse_event_name(&sys_event, &sys_name, buf2, 0); if (ret || !sys_event || !sys_name) { trace_probe_log_err(0, NO_EVENT_INFO); - goto parse_error; + return -EINVAL; } =20 if (!event) { buf1 =3D kstrdup(sys_event, GFP_KERNEL); if (!buf1) - goto mem_error; + return -ENOMEM; event =3D buf1; } =20 @@ -934,8 +931,7 @@ static int __trace_eprobe_create(int argc, const char *= argv[]) if (argc - 2 > MAX_TRACE_ARGS) { trace_probe_log_set_index(2); trace_probe_log_err(0, TOO_MANY_ARGS); - ret =3D -E2BIG; - goto error; + return -E2BIG; } =20 scoped_guard(mutex, &event_mutex) { @@ -949,15 +945,14 @@ static int __trace_eprobe_create(int argc, const char= *argv[]) trace_probe_log_err(0, BAD_ATTACH_EVENT); /* This must return -ENOMEM or missing event, else there is a bug */ WARN_ON_ONCE(ret !=3D -ENOMEM && ret !=3D -ENODEV); - ep =3D NULL; - goto error; + return ret; } =20 if (filter_idx) { trace_probe_log_set_index(filter_idx); ret =3D trace_eprobe_parse_filter(ep, filter_cnt, argv + filter_idx); if (ret) - goto parse_error; + return -EINVAL; } else ep->filter_str =3D NULL; =20 @@ -967,11 +962,12 @@ static int __trace_eprobe_create(int argc, const char= *argv[]) trace_probe_log_set_index(i + 2); ret =3D trace_eprobe_tp_update_arg(ep, argv, i); if (ret) - goto error; + return ret; } ret =3D traceprobe_set_print_fmt(&ep->tp, PROBE_PRINT_EVENT); if (ret < 0) - goto error; + return ret; + init_trace_eprobe_call(ep); scoped_guard(mutex, &event_mutex) { ret =3D trace_probe_register_event_call(&ep->tp); @@ -980,24 +976,17 @@ static int __trace_eprobe_create(int argc, const char= *argv[]) trace_probe_log_set_index(0); trace_probe_log_err(0, EVENT_EXIST); } - goto error; + return ret; } ret =3D dyn_event_add(&ep->devent, &ep->tp.event->call); if (ret < 0) { trace_probe_unregister_event_call(&ep->tp); - goto error; + return ret; } + /* To avoid freeing registered eprobe event, clear ep. */ + ep =3D NULL; } return ret; - -mem_error: - ret =3D -ENOMEM; - goto error; -parse_error: - ret =3D -EINVAL; -error: - trace_event_probe_cleanup(ep); - return ret; } =20 /* From nobody Sat Oct 4 19:15:56 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 035BD19F424; Wed, 13 Aug 2025 14:30:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755095409; cv=none; b=qMQ7R5Nx2bTlzJ3YOQ2NbMZmvn104Kh7x1DlOZonqe3klO0sBZENINKW0IQDrd/7wJtSfMhNOzKChnCEITTYPaHDPy+9pC6PrEhA2nT+RXo4vnkm720X7rDZcAZHCa3OFQw6AYDFPKdk5pOOXh1f5B+HEaz6jpxc5iRbo/Jgiy0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755095409; c=relaxed/simple; bh=f7YCp6FEN6d54fq27DFGuyBRZqienKDzQ2bRuqKKHYI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fMv/YVZI6GkhV9z3s2cCzthvIZliFLYlZXOeImkxgm4P5QPrNUDAVTsbnIe7tNil9yRqhT9p0gEhn+bkEq6LtRnQYjgx45yScqNORmv1rWW8eU+XS7Eu9HTt5Dq8rvghQMhkslPVmq10VwwO+zfOGgFnaTb/9FtkSUByJ+/r93s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OSb3yT/S; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OSb3yT/S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29AB5C4CEEB; Wed, 13 Aug 2025 14:30:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755095408; bh=f7YCp6FEN6d54fq27DFGuyBRZqienKDzQ2bRuqKKHYI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OSb3yT/SOsJYhTeVzx015sM1oaPTV93Eg5KzPRMYFpG5L3aOAVwIgwiRjJKQSYwYf YcMT362zqh7dh4wUbMUmJOPNu5rET8o3jFmr5ha+eHkmkh3MIH1BMYuWKHNDJAfmxj LYu9ZdDyBwfnPIPvDaeJQ60OO37WXgHLwpktjvEyl1VfkGzm9oS0RPw5eeQP77p5j/ sMhX7vi1eN8C8Oof3gaTYVJX9OgQ62RcIqg7O1erQ9T4pAJlmbkqhj5ApmSSxIig3e Du8jvv0PUEyr4mUXDc5TK7sIQJGE0Ea/P/pfwBcq8UPF1ZHAh1/CIOeH1V5yvZNfW6 iQS6FGs3DXu5g== From: "Masami Hiramatsu (Google)" To: Steven Rostedt , Mathieu Desnoyers Cc: Masami Hiramatsu , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH 3/4] tracing: uprobes: Cleanup __trace_uprobe_create() with __free() Date: Wed, 13 Aug 2025 23:30:04 +0900 Message-ID: <175509540482.193596.6541098946023873304.stgit@devnote2> X-Mailer: git-send-email 2.43.0 In-Reply-To: <175509537667.193596.9139462012987606126.stgit@devnote2> References: <175509537667.193596.9139462012987606126.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Masami Hiramatsu (Google) Use __free() to cleanup ugly gotos in __trace_uprobe_create(). Signed-off-by: Masami Hiramatsu (Google) --- kernel/trace/trace_uprobe.c | 68 ++++++++++++++++-----------------------= ---- 1 file changed, 26 insertions(+), 42 deletions(-) diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c index 722316b3dc16..9c628dab3dc6 100644 --- a/kernel/trace/trace_uprobe.c +++ b/kernel/trace/trace_uprobe.c @@ -533,22 +533,25 @@ static int register_trace_uprobe(struct trace_uprobe = *tu) return ret; } =20 +DEFINE_FREE(free_trace_uprobe, struct trace_uprobe *, if (_T) free_trace_u= probe(_T)) + /* * Argument syntax: * - Add uprobe: p|r[:[GRP/][EVENT]] PATH:OFFSET[%return][(REF)] [FETCHAR= GS] */ static int __trace_uprobe_create(int argc, const char **argv) { + struct trace_uprobe *tu __free(free_trace_uprobe) =3D NULL; const char *trlog __free(trace_probe_log_clear) =3D NULL; const char *event =3D NULL, *group =3D UPROBE_EVENT_SYSTEM; - char *arg, *filename, *rctr, *rctr_end, *tmp; + struct path path __free(path_put) =3D {}; unsigned long offset, ref_ctr_offset; + char *filename __free(kfree) =3D NULL; + char *arg, *rctr, *rctr_end, *tmp; char *gbuf __free(kfree) =3D NULL; char *buf __free(kfree) =3D NULL; enum probe_print_type ptype; - struct trace_uprobe *tu; bool is_return =3D false; - struct path path; int i, ret; =20 ref_ctr_offset =3D 0; @@ -586,10 +589,8 @@ static int __trace_uprobe_create(int argc, const char = **argv) =20 /* Find the last occurrence, in case the path contains ':' too. */ arg =3D strrchr(filename, ':'); - if (!arg || !isdigit(arg[1])) { - kfree(filename); + if (!arg || !isdigit(arg[1])) return -ECANCELED; - } =20 trace_probe_log_set_index(1); /* filename is the 2nd argument */ =20 @@ -597,13 +598,11 @@ static int __trace_uprobe_create(int argc, const char= **argv) ret =3D kern_path(filename, LOOKUP_FOLLOW, &path); if (ret) { trace_probe_log_err(0, FILE_NOT_FOUND); - kfree(filename); return ret; } if (!d_is_reg(path.dentry)) { trace_probe_log_err(0, NO_REGULAR_FILE); - ret =3D -EINVAL; - goto fail_address_parse; + return -EINVAL; } =20 /* Parse reference counter offset if specified. */ @@ -611,16 +610,14 @@ static int __trace_uprobe_create(int argc, const char= **argv) if (rctr) { rctr_end =3D strchr(rctr, ')'); if (!rctr_end) { - ret =3D -EINVAL; rctr_end =3D rctr + strlen(rctr); trace_probe_log_err(rctr_end - filename, REFCNT_OPEN_BRACE); - goto fail_address_parse; + return -EINVAL; } else if (rctr_end[1] !=3D '\0') { - ret =3D -EINVAL; trace_probe_log_err(rctr_end + 1 - filename, BAD_REFCNT_SUFFIX); - goto fail_address_parse; + return -EINVAL; } =20 *rctr++ =3D '\0'; @@ -628,7 +625,7 @@ static int __trace_uprobe_create(int argc, const char *= *argv) ret =3D kstrtoul(rctr, 0, &ref_ctr_offset); if (ret) { trace_probe_log_err(rctr - filename, BAD_REFCNT); - goto fail_address_parse; + return ret; } } =20 @@ -640,8 +637,7 @@ static int __trace_uprobe_create(int argc, const char *= *argv) is_return =3D true; } else { trace_probe_log_err(tmp - filename, BAD_ADDR_SUFFIX); - ret =3D -EINVAL; - goto fail_address_parse; + return -EINVAL; } } =20 @@ -649,7 +645,7 @@ static int __trace_uprobe_create(int argc, const char *= *argv) ret =3D kstrtoul(arg, 0, &offset); if (ret) { trace_probe_log_err(arg - filename, BAD_UPROBE_OFFS); - goto fail_address_parse; + return ret; } =20 /* setup a probe */ @@ -657,12 +653,12 @@ static int __trace_uprobe_create(int argc, const char= **argv) if (event) { gbuf =3D kmalloc(MAX_EVENT_NAME_LEN, GFP_KERNEL); if (!gbuf) - goto fail_mem; + return -ENOMEM; =20 ret =3D traceprobe_parse_event_name(&event, &group, gbuf, event - argv[0]); if (ret) - goto fail_address_parse; + return ret; } =20 if (!event) { @@ -671,7 +667,7 @@ static int __trace_uprobe_create(int argc, const char *= *argv) =20 tail =3D kstrdup(kbasename(filename), GFP_KERNEL); if (!tail) - goto fail_mem; + return -ENOMEM; =20 ptr =3D strpbrk(tail, ".-_"); if (ptr) @@ -679,7 +675,7 @@ static int __trace_uprobe_create(int argc, const char *= *argv) =20 buf =3D kmalloc(MAX_EVENT_NAME_LEN, GFP_KERNEL); if (!buf) - goto fail_mem; + return -ENOMEM; snprintf(buf, MAX_EVENT_NAME_LEN, "%c_%s_0x%lx", 'p', tail, offset); event =3D buf; kfree(tail); @@ -693,49 +689,37 @@ static int __trace_uprobe_create(int argc, const char= **argv) ret =3D PTR_ERR(tu); /* This must return -ENOMEM otherwise there is a bug */ WARN_ON_ONCE(ret !=3D -ENOMEM); - goto fail_address_parse; + return ret; } tu->offset =3D offset; tu->ref_ctr_offset =3D ref_ctr_offset; tu->path =3D path; - tu->filename =3D filename; + /* Clear @path so that it will not freed by path_put() */ + memset(&path, 0, sizeof(path)); + tu->filename =3D no_free_ptr(filename); =20 /* parse arguments */ for (i =3D 0; i < argc; i++) { struct traceprobe_parse_context *ctx __free(traceprobe_parse_context) =3D kzalloc(sizeof(*ctx), GFP_KERNEL); =20 - if (!ctx) { - ret =3D -ENOMEM; - goto error; - } + if (!ctx) + return -ENOMEM; ctx->flags =3D (is_return ? TPARG_FL_RETURN : 0) | TPARG_FL_USER; trace_probe_log_set_index(i + 2); ret =3D traceprobe_parse_probe_arg(&tu->tp, i, argv[i], ctx); if (ret) - goto error; + return ret; } =20 ptype =3D is_ret_probe(tu) ? PROBE_PRINT_RETURN : PROBE_PRINT_NORMAL; ret =3D traceprobe_set_print_fmt(&tu->tp, ptype); if (ret < 0) - goto error; + return ret; =20 ret =3D register_trace_uprobe(tu); if (!ret) - goto out; - -error: - free_trace_uprobe(tu); -out: - return ret; - -fail_mem: - ret =3D -ENOMEM; - -fail_address_parse: - path_put(&path); - kfree(filename); + tu =3D NULL; =20 return ret; } From nobody Sat Oct 4 19:15:56 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0150A3C33; Wed, 13 Aug 2025 14:30:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755095418; cv=none; b=j6TwLNyZIW6noLJ16HMGcd+sM/DZ36UFMqoqRChS38lmRz2Dic2MFXM81WJ3LWpalHsUQQ1XYpblhAhljZOcaqhN/4DHAPjgbaJ7WIVWBSyv+vx5aCuycWpcXkk2fTHAHBR4FeRIWqflqCIhbZFiPu2gxfYVvZpz1gvN7LXFWYY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755095418; c=relaxed/simple; bh=MYPEj/1UaAR+SG/EgGexa4okmshAoVUJvRwXGzcaCEY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QHBPVFzItjS359n9y3Gau0JxbDyZPAlO6x59eWAiODJRibroZx9m6qMbuqdQ7QlPR1P2T+bXMUcnTsXdi06iPRsbSlrMIStqZx9b2/gA9PKD49o3V/fVxx/P0tSRR7GCX3oG4gtwT+WMXRLPOTduWHqKA4udyYEztr8e+UsmZTE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aj4BQv+4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aj4BQv+4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45D26C4CEEB; Wed, 13 Aug 2025 14:30:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755095417; bh=MYPEj/1UaAR+SG/EgGexa4okmshAoVUJvRwXGzcaCEY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aj4BQv+4Yz5yRrbbVtZVoCL/+yOYojBoh6/eO9h64fK5ipEo8X/liwRayFmUHP8VE xTdKMxvEephgZf27gQBtLCieXwg1AaM48JhuSE0o/3lIf1JBYvGLthBgdmwBxxTPId Wn+zOckhbkGKgGT9Z4xF9x+X9G4iWsySpf1DERjfW3AnMW0t2rQ7iznWvvGUu8PE6+ VROXFpAij7BosJTTyMt8vdSVh74i1ADiOrA1vHnRLl2HuG3F2SQzhxy3IZw6NVM33v KecrUJ5kYRBuCpOZ8bpU19CLnmkCE2P4Yb87Sa/J3LKvWZa8FrHT/Mmr4SJQCwtXjL TwOi6CdUVm4mQ== From: "Masami Hiramatsu (Google)" To: Steven Rostedt , Mathieu Desnoyers Cc: Masami Hiramatsu , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH 4/4] tracing: uprobe: eprobes: Allocate traceprobe_parse_context per probe Date: Wed, 13 Aug 2025 23:30:14 +0900 Message-ID: <175509541393.193596.16330324746701582114.stgit@devnote2> X-Mailer: git-send-email 2.43.0 In-Reply-To: <175509537667.193596.9139462012987606126.stgit@devnote2> References: <175509537667.193596.9139462012987606126.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Masami Hiramatsu (Google) Since traceprobe_parse_context is reusable among a probe arguments, it is more efficient to allocate it outside of the loop for parsing probe argument as kprobe and fprobe events do. Signed-off-by: Masami Hiramatsu (Google) --- kernel/trace/trace_eprobe.c | 32 ++++++++++++-------------------- kernel/trace/trace_uprobe.c | 12 ++++++------ 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c index f7a1ff509d7e..d58d8702a327 100644 --- a/kernel/trace/trace_eprobe.c +++ b/kernel/trace/trace_eprobe.c @@ -801,25 +801,6 @@ find_and_get_event(const char *system, const char *eve= nt_name) return NULL; } =20 -static int trace_eprobe_tp_update_arg(struct trace_eprobe *ep, const char = *argv[], int i) -{ - struct traceprobe_parse_context *ctx __free(traceprobe_parse_context) =3D= NULL; - int ret; - - ctx =3D kzalloc(sizeof(*ctx), GFP_KERNEL); - if (!ctx) - return -ENOMEM; - ctx->event =3D ep->event; - ctx->flags =3D TPARG_FL_KERNEL | TPARG_FL_TEVENT; - - ret =3D traceprobe_parse_probe_arg(&ep->tp, i, argv[i], ctx); - /* Handle symbols "@" */ - if (!ret) - ret =3D traceprobe_update_arg(&ep->tp.args[i]); - - return ret; -} - static int trace_eprobe_parse_filter(struct trace_eprobe *ep, int argc, co= nst char *argv[]) { struct event_filter *dummy =3D NULL; @@ -871,6 +852,7 @@ static int __trace_eprobe_create(int argc, const char *= argv[]) * Fetch args (no space): * =3D$[:TYPE] */ + struct traceprobe_parse_context *ctx __free(traceprobe_parse_context) =3D= NULL; struct trace_eprobe *ep __free(trace_event_probe_cleanup) =3D NULL; const char *trlog __free(trace_probe_log_clear) =3D NULL; const char *event =3D NULL, *group =3D EPROBE_EVENT_SYSTEM; @@ -956,11 +938,21 @@ static int __trace_eprobe_create(int argc, const char= *argv[]) } else ep->filter_str =3D NULL; =20 + ctx =3D kzalloc(sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + ctx->event =3D ep->event; + ctx->flags =3D TPARG_FL_KERNEL | TPARG_FL_TEVENT; + argc -=3D 2; argv +=3D 2; /* parse arguments */ for (i =3D 0; i < argc; i++) { trace_probe_log_set_index(i + 2); - ret =3D trace_eprobe_tp_update_arg(ep, argv, i); + + ret =3D traceprobe_parse_probe_arg(&ep->tp, i, argv[i], ctx); + /* Handle symbols "@" */ + if (!ret) + ret =3D traceprobe_update_arg(&ep->tp.args[i]); if (ret) return ret; } diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c index 9c628dab3dc6..8f9b95cee786 100644 --- a/kernel/trace/trace_uprobe.c +++ b/kernel/trace/trace_uprobe.c @@ -541,6 +541,7 @@ DEFINE_FREE(free_trace_uprobe, struct trace_uprobe *, i= f (_T) free_trace_uprobe( */ static int __trace_uprobe_create(int argc, const char **argv) { + struct traceprobe_parse_context *ctx __free(traceprobe_parse_context) =3D= NULL; struct trace_uprobe *tu __free(free_trace_uprobe) =3D NULL; const char *trlog __free(trace_probe_log_clear) =3D NULL; const char *event =3D NULL, *group =3D UPROBE_EVENT_SYSTEM; @@ -698,14 +699,13 @@ static int __trace_uprobe_create(int argc, const char= **argv) memset(&path, 0, sizeof(path)); tu->filename =3D no_free_ptr(filename); =20 + ctx =3D kzalloc(sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + ctx->flags =3D (is_return ? TPARG_FL_RETURN : 0) | TPARG_FL_USER; + /* parse arguments */ for (i =3D 0; i < argc; i++) { - struct traceprobe_parse_context *ctx __free(traceprobe_parse_context) - =3D kzalloc(sizeof(*ctx), GFP_KERNEL); - - if (!ctx) - return -ENOMEM; - ctx->flags =3D (is_return ? TPARG_FL_RETURN : 0) | TPARG_FL_USER; trace_probe_log_set_index(i + 2); ret =3D traceprobe_parse_probe_arg(&tu->tp, i, argv[i], ctx); if (ret)