]> git.itanic.dy.fi Git - linux-stable/commitdiff
tracing/histograms: Simplify last_cmd_set()
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Sat, 21 Oct 2023 14:42:41 +0000 (16:42 +0200)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Mon, 23 Oct 2023 17:31:14 +0000 (13:31 -0400)
Turn a kzalloc()+strcpy()+strncat() into an equivalent and less verbose
kasprintf().

Link: https://lore.kernel.org/linux-trace-kernel/30b6fb04dadc10a03cc1ad08f5d8a93ef623a167.1697899346.git.christophe.jaillet@wanadoo.fr
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Mukesh ojha <quic_mojha@quicinc.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/trace/trace_events_hist.c

index d06938ae071740ea4c80cff055c29a6c5db1352f..1abc07fba1b91ddea5b1f2c6446d1fe03275ba31 100644 (file)
@@ -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);
-
        if (file) {
                call = file->event_call;
                system = call->class->system;