Commit 12eaaf30 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Linus Torvalds

set_task_comm: kill the pointless memset() + wmb()

set_task_comm() does memset() + wmb() before strlcpy().  This buys
nothing and to add to the confusion, the comment is wrong.

- We do not need memset() to be "safe from non-terminating string
  reads", the final char is always zero and we never change it.

- wmb() is paired with nothing, it cannot prevent from printing
  the mixture of the old/new data unless the reader takes the lock.
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: John Stultz <johnstul@us.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 830e0fc9
...@@ -1027,17 +1027,7 @@ EXPORT_SYMBOL_GPL(get_task_comm); ...@@ -1027,17 +1027,7 @@ EXPORT_SYMBOL_GPL(get_task_comm);
void set_task_comm(struct task_struct *tsk, char *buf) void set_task_comm(struct task_struct *tsk, char *buf)
{ {
task_lock(tsk); task_lock(tsk);
trace_task_rename(tsk, buf); trace_task_rename(tsk, buf);
/*
* Threads may access current->comm without holding
* the task lock, so write the string carefully.
* Readers without a lock may see incomplete new
* names but are safe from non-terminating string reads.
*/
memset(tsk->comm, 0, TASK_COMM_LEN);
wmb();
strlcpy(tsk->comm, buf, sizeof(tsk->comm)); strlcpy(tsk->comm, buf, sizeof(tsk->comm));
task_unlock(tsk); task_unlock(tsk);
perf_event_comm(tsk); perf_event_comm(tsk);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment