From nobody Tue Dec 16 21:48:18 2025 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 C320FC25B6B for ; Thu, 26 Oct 2023 01:27:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232935AbjJZB17 (ORCPT ); Wed, 25 Oct 2023 21:27:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231288AbjJZB15 (ORCPT ); Wed, 25 Oct 2023 21:27:57 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03EDCCC for ; Wed, 25 Oct 2023 18:27:55 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA0E5C433C9; Thu, 26 Oct 2023 01:27:54 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1qvpA9-00CqSz-1x; Wed, 25 Oct 2023 21:27:53 -0400 Message-ID: <20231026012753.418244796@goodmis.org> User-Agent: quilt/0.66 Date: Wed, 25 Oct 2023 21:27:35 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Christophe JAILLET , Mukesh ojha Subject: [for-next][PATCH 1/4] tracing/histograms: Simplify last_cmd_set() References: <20231026012734.358814002@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: Christophe JAILLET Turn a kzalloc()+strcpy()+strncat() into an equivalent and less verbose kasprintf(). Link: https://lore.kernel.org/linux-trace-kernel/30b6fb04dadc10a03cc1ad08f5= d8a93ef623a167.1697899346.git.christophe.jaillet@wanadoo.fr Cc: Masami Hiramatsu Signed-off-by: Christophe JAILLET Reviewed-by: Mukesh ojha Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_hist.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_h= ist.c index d06938ae0717..1abc07fba1b9 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -774,23 +774,16 @@ static void last_cmd_set(struct trace_event_file *fil= e, char *str) { const char *system =3D NULL, *name =3D NULL; struct trace_event_call *call; - int len; =20 if (!str) return; =20 - /* sizeof() contains the nul byte */ - len =3D sizeof(HIST_PREFIX) + strlen(str); kfree(last_cmd); - last_cmd =3D kzalloc(len, GFP_KERNEL); + + last_cmd =3D kasprintf(GFP_KERNEL, HIST_PREFIX "%s", str); if (!last_cmd) return; =20 - strcpy(last_cmd, HIST_PREFIX); - /* Again, sizeof() contains the nul byte */ - len -=3D sizeof(HIST_PREFIX); - strncat(last_cmd, str, len); - if (file) { call =3D file->event_call; system =3D call->class->system; --=20 2.42.0