linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Chuang Wang <nashuiliang@gmail.com>
Subject: [for-next][PATCH 08/11] tracing/perf: Use strndup_user instead of kzalloc/strncpy_from_user
Date: Thu, 24 Nov 2022 09:50:27 -0500	[thread overview]
Message-ID: <20221124145046.573437905@goodmis.org> (raw)
In-Reply-To: 20221124145019.782980678@goodmis.org

From: Chuang Wang <nashuiliang@gmail.com>

This patch uses strndup_user instead of kzalloc + strncpy_from_user,
which makes the code more concise.

Link: https://lkml.kernel.org/r/20221121080831.707409-1-nashuiliang@gmail.com

Signed-off-by: Chuang Wang <nashuiliang@gmail.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 kernel/trace/trace_event_perf.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c
index 61e3a2620fa3..05e791241812 100644
--- a/kernel/trace/trace_event_perf.c
+++ b/kernel/trace/trace_event_perf.c
@@ -251,16 +251,12 @@ int perf_kprobe_init(struct perf_event *p_event, bool is_retprobe)
 	struct trace_event_call *tp_event;
 
 	if (p_event->attr.kprobe_func) {
-		func = kzalloc(KSYM_NAME_LEN, GFP_KERNEL);
-		if (!func)
-			return -ENOMEM;
-		ret = strncpy_from_user(
-			func, u64_to_user_ptr(p_event->attr.kprobe_func),
-			KSYM_NAME_LEN);
-		if (ret == KSYM_NAME_LEN)
-			ret = -E2BIG;
-		if (ret < 0)
-			goto out;
+		func = strndup_user(u64_to_user_ptr(p_event->attr.kprobe_func),
+				    KSYM_NAME_LEN);
+		if (IS_ERR(func)) {
+			ret = PTR_ERR(func);
+			return (ret == -EINVAL) ? -E2BIG : ret;
+		}
 
 		if (func[0] == '\0') {
 			kfree(func);
-- 
2.35.1



  parent reply	other threads:[~2022-11-24 14:51 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-24 14:50 [for-next][PATCH 00/11] tracing: Updates for 6.2 Steven Rostedt
2022-11-24 14:50 ` [for-next][PATCH 01/11] ftrace: Clean comments related to FTRACE_OPS_FL_PER_CPU Steven Rostedt
2022-11-24 14:50 ` [for-next][PATCH 02/11] tracing: Add __cpumask to denote a trace event field that is a cpumask_t Steven Rostedt
2022-12-12 14:53   ` Douglas Raillard
2022-12-12 16:12     ` Steven Rostedt
2022-12-12 17:04       ` Steven Rostedt
2022-12-12 22:19       ` Douglas Raillard
2022-12-12 23:53         ` Steven Rostedt
2022-12-13 14:20           ` Douglas Raillard
2022-12-13 15:11             ` Steven Rostedt
2022-12-13 17:40               ` Douglas Raillard
2022-12-13 19:44                 ` Steven Rostedt
2022-12-13 21:14                   ` Douglas Raillard
2022-12-13 19:50             ` Douglas Raillard
2022-11-24 14:50 ` [for-next][PATCH 03/11] tracing: Add trace_trigger kernel command line option Steven Rostedt
2022-11-24 14:50 ` [for-next][PATCH 04/11] ring_buffer: Remove unused "event" parameter Steven Rostedt
2022-11-24 14:50 ` [for-next][PATCH 05/11] tracing/osnoise: Add osnoise/options file Steven Rostedt
2022-11-24 17:31   ` Daniel Bristot de Oliveira
2022-11-24 19:28     ` Steven Rostedt
2022-11-24 14:50 ` [for-next][PATCH 06/11] tracing/osnoise: Add OSNOISE_WORKLOAD option Steven Rostedt
2022-11-24 14:50 ` [for-next][PATCH 07/11] Documentation/osnoise: Add osnoise/options documentation Steven Rostedt
2022-11-24 14:50 ` Steven Rostedt [this message]
2022-11-24 14:50 ` [for-next][PATCH 09/11] tracing: Make tracepoint_print_iter static Steven Rostedt
2022-11-24 14:50 ` [for-next][PATCH 11/11] ftrace: Avoid needless updates of the ftrace function call Steven Rostedt

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 \
    --in-reply-to=20221124145046.573437905@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=nashuiliang@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).