From nobody Sun Feb 8 03:58:12 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCCE2C433FE for ; Thu, 24 Nov 2022 14:51:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229712AbiKXOvl (ORCPT ); Thu, 24 Nov 2022 09:51:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229839AbiKXOvC (ORCPT ); Thu, 24 Nov 2022 09:51:02 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C604134F26 for ; Thu, 24 Nov 2022 06:50:52 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 11F13B8284A for ; Thu, 24 Nov 2022 14:50:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9251CC43146; Thu, 24 Nov 2022 14:50:47 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1oyDYs-001X5z-2F; Thu, 24 Nov 2022 09:50:46 -0500 Message-ID: <20221124145046.573437905@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 24 Nov 2022 09:50:27 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Chuang Wang Subject: [for-next][PATCH 08/11] tracing/perf: Use strndup_user instead of kzalloc/strncpy_from_user References: <20221124145019.782980678@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Chuang Wang 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.c= om Signed-off-by: Chuang Wang Signed-off-by: Steven Rostedt (Google) --- 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_per= f.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; =20 if (p_event->attr.kprobe_func) { - func =3D kzalloc(KSYM_NAME_LEN, GFP_KERNEL); - if (!func) - return -ENOMEM; - ret =3D strncpy_from_user( - func, u64_to_user_ptr(p_event->attr.kprobe_func), - KSYM_NAME_LEN); - if (ret =3D=3D KSYM_NAME_LEN) - ret =3D -E2BIG; - if (ret < 0) - goto out; + func =3D strndup_user(u64_to_user_ptr(p_event->attr.kprobe_func), + KSYM_NAME_LEN); + if (IS_ERR(func)) { + ret =3D PTR_ERR(func); + return (ret =3D=3D -EINVAL) ? -E2BIG : ret; + } =20 if (func[0] =3D=3D '\0') { kfree(func); --=20 2.35.1