public inbox for [email protected]
 help / color / mirror / Atom feed
From: Wan Jiabing <[email protected]>
To: Steven Rostedt <[email protected]>,
	Ingo Molnar <[email protected]>,
	Alexei Starovoitov <[email protected]>,
	Daniel Borkmann <[email protected]>,
	Andrii Nakryiko <[email protected]>,
	Martin KaFai Lau <[email protected]>, Song Liu <[email protected]>,
	Yonghong Song <[email protected]>,
	John Fastabend <[email protected]>,
	KP Singh <[email protected]>,
	[email protected], [email protected],
	[email protected]
Cc: Wan Jiabing <[email protected]>
Subject: [PATCH 1/3] bpf: use 'error_xxx' tags in bpf_kprobe_multi_link_attach
Date: Thu, 12 May 2022 22:17:08 +0800	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

Use 'error_addrs', 'error_cookies' and 'error_link' tags to make error
handling more efficient.

Signed-off-by: Wan Jiabing <[email protected]>
---
 kernel/trace/bpf_trace.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 2eaac094caf8..3a8b69ef9a0d 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2467,20 +2467,20 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
 	if (uaddrs) {
 		if (copy_from_user(addrs, uaddrs, size)) {
 			err = -EFAULT;
-			goto error;
+			goto error_addrs;
 		}
 	} else {
 		struct user_syms us;
 
 		err = copy_user_syms(&us, usyms, cnt);
 		if (err)
-			goto error;
+			goto error_addrs;
 
 		sort(us.syms, cnt, sizeof(*us.syms), symbols_cmp, NULL);
 		err = ftrace_lookup_symbols(us.syms, cnt, addrs);
 		free_user_syms(&us);
 		if (err)
-			goto error;
+			goto error_addrs;
 	}
 
 	ucookies = u64_to_user_ptr(attr->link_create.kprobe_multi.cookies);
@@ -2488,18 +2488,18 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
 		cookies = kvmalloc(size, GFP_KERNEL);
 		if (!cookies) {
 			err = -ENOMEM;
-			goto error;
+			goto error_addrs;
 		}
 		if (copy_from_user(cookies, ucookies, size)) {
 			err = -EFAULT;
-			goto error;
+			goto error_cookies;
 		}
 	}
 
 	link = kzalloc(sizeof(*link), GFP_KERNEL);
 	if (!link) {
 		err = -ENOMEM;
-		goto error;
+		goto error_cookies;
 	}
 
 	bpf_link_init(&link->link, BPF_LINK_TYPE_KPROBE_MULTI,
@@ -2507,7 +2507,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
 
 	err = bpf_link_prime(&link->link, &link_primer);
 	if (err)
-		goto error;
+		goto error_link;
 
 	if (flags & BPF_F_KPROBE_MULTI_RETURN)
 		link->fp.exit_handler = kprobe_multi_link_handler;
@@ -2539,10 +2539,12 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
 
 	return bpf_link_settle(&link_primer);
 
-error:
+error_link:
 	kfree(link);
-	kvfree(addrs);
+error_cookies:
 	kvfree(cookies);
+error_addrs:
+	kvfree(addrs);
 	return err;
 }
 #else /* !CONFIG_FPROBE */
-- 
2.35.1



  reply	other threads:[~2022-05-12 14:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-12 14:17 [PATCH 0/3] bpf: optimize the bpf_kprobe_multi_link_attach function Wan Jiabing
2022-05-12 14:17 ` Wan Jiabing [this message]
2022-05-12 16:40   ` [PATCH 1/3] bpf: use 'error_xxx' tags in bpf_kprobe_multi_link_attach Song Liu
2022-05-12 17:05   ` David Vernet
2022-05-12 14:17 ` [PATCH 2/3] bpf: simplify if-if to if " Wan Jiabing
2022-05-12 16:44   ` Song Liu
2022-05-12 14:17 ` [PATCH 3/3] bpf: use vmemdup_user instead of kvmalloc and copy_from_user Wan Jiabing
2022-05-12 16:45   ` Song Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox