bpf: Clean code with bpf_copy_to_user
PATCH v2 1/1 bpf: Clean code with bpf_copy_to_user
No logic change, just use bpf_copy_to_user to clean code.
Signed-off-by Tao Chen <[email protected]>
--- kernel/bpf/syscall.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-)
Change list:
v1 -> v2:
- do not directly return when handle err ENOSPC.(Yonghong)
v1:
https://lore.kernel.org/bpf/[email protected]
kernel/bpf/syscall.c +3 -14
@@ -5208,21 +5208,10 @@ static int bpf_task_fd_query_copy(const union bpf_attr *attr,if (put_user (zero, ubuf))return -EFAULT ; - }else if (input_len >= len +1 ) { -/* ubuf can hold the string with NULL terminator */ -if (copy_to_user (ubuf, buf, len +1 )) -return -EFAULT ; }else { -/* ubuf cannot hold the string with NULL terminator, -* do a partial copy with NULL terminator. -*/ -char zero ='\0' ; - - err = -ENOSPC ; -if (copy_to_user (ubuf, buf, input_len -1 )) -return -EFAULT ; -if (put_user (zero, ubuf + input_len -1 )) -return -EFAULT ; + err =bpf_copy_to_user (ubuf, buf, input_len, len); +if (err == -EFAULT ) +return err; } }
Signature · 1 line
2.48.1
Quoted 3 lines · Tao Chen
No logic change, just use
bpf_copy_to_userto clean code.Signed-off-by Tao Chen <[email protected]>
Acked-by Yonghong Song <[email protected]>
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 8 lines · On Fri, 4 Jul 2025 00:37:00 +0800 you wrote:
No logic change, just use
bpf_copy_to_userto clean code.Signed-off-by Tao Chen <[email protected]>--- kernel/bpf/syscall.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-)[...]
Here is the summary with links:
- [bpf-next,v2] bpf: Clean code with bpf_copy_to_user
https://git.kernel.org/bpf/bpf-next/c/3413bc0cf16e
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html