Skip to content

Commit 545db7e

Browse files
tititiou36rostedt
authored andcommitted
tracing/histograms: Simplify last_cmd_set()
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>
1 parent 845e31e commit 545db7e

1 file changed

Lines changed: 2 additions & 9 deletions

File tree

kernel/trace/trace_events_hist.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -774,23 +774,16 @@ static void last_cmd_set(struct trace_event_file *file, char *str)
774774
{
775775
const char *system = NULL, *name = NULL;
776776
struct trace_event_call *call;
777-
int len;
778777

779778
if (!str)
780779
return;
781780

782-
/* sizeof() contains the nul byte */
783-
len = sizeof(HIST_PREFIX) + strlen(str);
784781
kfree(last_cmd);
785-
last_cmd = kzalloc(len, GFP_KERNEL);
782+
783+
last_cmd = kasprintf(GFP_KERNEL, HIST_PREFIX "%s", str);
786784
if (!last_cmd)
787785
return;
788786

789-
strcpy(last_cmd, HIST_PREFIX);
790-
/* Again, sizeof() contains the nul byte */
791-
len -= sizeof(HIST_PREFIX);
792-
strncat(last_cmd, str, len);
793-
794787
if (file) {
795788
call = file->event_call;
796789
system = call->class->system;

0 commit comments

Comments
 (0)