From: Mukesh Ojha <quic_mojha@quicinc.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <kernel-janitors@vger.kernel.org>,
<linux-trace-kernel@vger.kernel.org>
Subject: Re: [PATCH] tracing/histograms: Simplify last_cmd_set()
Date: Mon, 23 Oct 2023 15:38:48 +0530 [thread overview]
Message-ID: <0ed6de5e-5b47-30cb-68fa-ce6ee7c839a8@quicinc.com> (raw)
In-Reply-To: <30b6fb04dadc10a03cc1ad08f5d8a93ef623a167.1697899346.git.christophe.jaillet@wanadoo.fr>
On 10/21/2023 8:12 PM, Christophe JAILLET wrote:
> Turn a kzalloc()+strcpy()+strncat() into an equivalent and less verbose
> kasprintf().
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> 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_hist.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 *file, char *str)
> {
> const char *system = NULL, *name = NULL;
> struct trace_event_call *call;
> - int len;
>
> if (!str)
> return;
>
> - /* sizeof() contains the nul byte */
> - len = sizeof(HIST_PREFIX) + strlen(str);
> kfree(last_cmd);
> - last_cmd = kzalloc(len, GFP_KERNEL);
> +
> + last_cmd = kasprintf(GFP_KERNEL, HIST_PREFIX "%s", str);
> if (!last_cmd)
> return;
>
> - strcpy(last_cmd, HIST_PREFIX);
> - /* Again, sizeof() contains the nul byte */
> - len -= sizeof(HIST_PREFIX);
> - strncat(last_cmd, str, len);
LGTM, careful optimization., Thanks.
Reviewed-by: Mukesh ojha <quic_mojha@quicinc.com>
-Mukesh
> -
> if (file) {
> call = file->event_call;
> system = call->class->system;
prev parent reply other threads:[~2023-10-23 10:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-21 14:42 Christophe JAILLET
2023-10-23 10:08 ` Mukesh Ojha [this message]
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=0ed6de5e-5b47-30cb-68fa-ce6ee7c839a8@quicinc.com \
--to=quic_mojha@quicinc.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
/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
all inboxes | Powered by JetHome®