Re: [PATCH v2 3/6] treewide: Replace memcpy(..., current->comm) with strscpy()
From: David Laight <hidden>
Date: 2026-05-27 09:18:46
Also in:
linux-mm, lkml
From: David Laight <hidden>
Date: 2026-05-27 09:18:46
Also in:
linux-mm, lkml
On Tue, 26 May 2026 19:06:25 -0400 Steven Rostedt [off-list ref] wrote:
On Sun, 24 May 2026 19:38:53 -0300 André Almeida [off-list ref] wrote:quoted
In order to increase the size of current->comm[] and to avoid breaking any existing code, replace memcpy() with strscpy(). The later function makes sure that the copy is NUL terminated. This is crucial given that the source buffer might be larger than the destination buffer and could truncate the NUL character out of it.
...
As tracing now slows it down by 3.9% which is a significant increase from 2.7% I really rather keep memcpy() here.
I suspect the copies could/should be replaced by a copy_task_comm() function that can perform optimisations that strscpy[_pad]() can't do because it can (for example) assume that the source is terminated. When the src and dst are the same size it can also degenerate to memcpy() - which should get inlined. The cost of copying 64 bytes might still be rather more than copying just 16. A compromise of 32 may be better. -- David
-- Steve