Skip to content

Commit 242b32d

Browse files
Jinjie Ruanrostedt
authored andcommitted
tracing: Replace strncpy() with strscpy() when copying comm
Replace the depreciated[1] strncpy() calls with strscpy() when copying comm. Link: KSPP#90 [1] Cc: <mhiramat@kernel.org> Cc: <mathieu.desnoyers@efficios.com> Link: https://lore.kernel.org/20241031120139.1343025-1-ruanjinjie@huawei.com Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent ee3685a commit 242b32d

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

kernel/trace/trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1921,7 +1921,7 @@ __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
19211921
max_data->critical_start = data->critical_start;
19221922
max_data->critical_end = data->critical_end;
19231923

1924-
strncpy(max_data->comm, tsk->comm, TASK_COMM_LEN);
1924+
strscpy(max_data->comm, tsk->comm);
19251925
max_data->pid = tsk->pid;
19261926
/*
19271927
* If tsk == current, then use current_uid(), as that does not use

kernel/trace/trace_events_hist.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,7 @@ static inline void save_comm(char *comm, struct task_struct *task)
15991599
return;
16001600
}
16011601

1602-
strncpy(comm, task->comm, TASK_COMM_LEN);
1602+
strscpy(comm, task->comm, TASK_COMM_LEN);
16031603
}
16041604

16051605
static void hist_elt_data_free(struct hist_elt_data *elt_data)
@@ -3405,7 +3405,7 @@ static bool cond_snapshot_update(struct trace_array *tr, void *cond_data)
34053405
elt_data = context->elt->private_data;
34063406
track_elt_data = track_data->elt.private_data;
34073407
if (elt_data->comm)
3408-
strncpy(track_elt_data->comm, elt_data->comm, TASK_COMM_LEN);
3408+
strscpy(track_elt_data->comm, elt_data->comm, TASK_COMM_LEN);
34093409

34103410
track_data->updated = true;
34113411

kernel/trace/trace_sched_switch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ static inline char *get_saved_cmdlines(int idx)
187187

188188
static inline void set_cmdline(int idx, const char *cmdline)
189189
{
190-
strncpy(get_saved_cmdlines(idx), cmdline, TASK_COMM_LEN);
190+
strscpy(get_saved_cmdlines(idx), cmdline, TASK_COMM_LEN);
191191
}
192192

193193
static void free_saved_cmdlines_buffer(struct saved_cmdlines_buffer *s)

0 commit comments

Comments
 (0)