# Re: \[PATCH v2 1/6\] uaccess: Add copy\_from\_user\_nul helper

- From: Alice Ryhl \<aliceryhl@google.com\>
- Date: 2026-01-12 09:23:42 
- List: linux-trace-kernel
- Page: https://ratatoskr.run/linux-trace-kernel/2026/01/3363088
- Thread: https://ratatoskr.run/linux-trace-kernel/2026/01/3362849/t.md

```text
On Mon, Jan 12, 2026 at 03:30:34PM +0800, Fushuai Wang wrote:
> From: Fushuai Wang <redacted>
> 
> Many places call copy_from_user() to copy a buffer from user space,
> and then manually add a NULL terminator to the destination buffer,
> e.g.:
> 
> 	if (copy_from_user(dest, src, len))
> 		return -EFAULT;
> 	dest[len] = '\0';
> 
> This is repetitive and error-prone. Add a copy_from_user_nul() helper to
> simplify such patterns. It copied n bytes from user space to kernel space,
> and NUL-terminates the destination buffer.
> 
> Signed-off-by: Fushuai Wang <redacted>

Hmm, this function is very very similar to strncpy_from_user(). Should
they be using that instead?

Alice
```
