tracing/perf: Use strndup_user instead of kzalloc/strncpy_from_user
authorChuang Wang <nashuiliang@gmail.com>
Mon, 21 Nov 2022 08:08:31 +0000 (16:08 +0800)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Thu, 24 Nov 2022 00:08:31 +0000 (19:08 -0500)
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

index 61e3a2620fa3c9417ac23cf5a18aeb86e7393dcc..05e7912418126b06da9dc771dc9ed94b39c8a069 100644 (file)
@@ -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);