diff options
author | Wang Yufen <wangyufen@huawei.com> | 2022-09-13 11:40:33 +0300 |
---|---|---|
committer | Martin KaFai Lau <martin.lau@kernel.org> | 2022-09-16 21:58:18 +0300 |
commit | a02c118ee9e898612cbae42121b9e8663455b515 (patch) | |
tree | f9e56532a036b10e9059715f50a5a2eae9968481 | |
parent | 47e34cb74d376ddfeaef94abb1d6dfb3c905ee51 (diff) | |
download | linux-a02c118ee9e898612cbae42121b9e8663455b515.tar.xz |
bpf: use kvmemdup_bpfptr helper
Use kvmemdup_bpfptr helper instead of open-coding to
simplify the code.
Signed-off-by: Wang Yufen <wangyufen@huawei.com>
Acked-by: Stanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/r/1663058433-14089-1-git-send-email-wangyufen@huawei.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
-rw-r--r-- | kernel/bpf/syscall.c | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 69be1c612daa..dab156f09f8d 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -1417,19 +1417,14 @@ static int map_update_elem(union bpf_attr *attr, bpfptr_t uattr) } value_size = bpf_map_value_size(map); - - err = -ENOMEM; - value = kvmalloc(value_size, GFP_USER | __GFP_NOWARN); - if (!value) + value = kvmemdup_bpfptr(uvalue, value_size); + if (IS_ERR(value)) { + err = PTR_ERR(value); goto free_key; - - err = -EFAULT; - if (copy_from_bpfptr(value, uvalue, value_size) != 0) - goto free_value; + } err = bpf_map_update_value(map, f, key, value, attr->flags); -free_value: kvfree(value); free_key: kvfree(key); |