aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPrashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>2018-10-08 21:04:49 -0400
committerAlexei Starovoitov <ast@kernel.org>2018-10-10 00:52:20 -0400
commit509db2833e0ddac7faf6e7d2dd6e7f85c98fbee0 (patch)
tree3f3c6e718a575fc14d2292a0d08733c0307e3ad2
parent8af03d1ae2e154a8be3631e8694b87007e1bdbc2 (diff)
bpf: error handling when map_lookup_elem isn't supported
The error value returned by map_lookup_elem doesn't differentiate whether lookup was failed because of invalid key or lookup is not supported. Lets add handling for -EOPNOTSUPP return value of map_lookup_elem() method of map, with expectation from map's implementation that it should return -EOPNOTSUPP if lookup is not supported. The errno for bpf syscall for BPF_MAP_LOOKUP_ELEM command will be set to EOPNOTSUPP if map lookup is not supported. Signed-off-by: Prashant Bhole <bhole_prashant_q7@lab.ntt.co.jp> Acked-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Song Liu <songliubraving@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r--kernel/bpf/syscall.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 5742df21598c..4f416234251f 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -719,10 +719,15 @@ static int map_lookup_elem(union bpf_attr *attr)
719 } else { 719 } else {
720 rcu_read_lock(); 720 rcu_read_lock();
721 ptr = map->ops->map_lookup_elem(map, key); 721 ptr = map->ops->map_lookup_elem(map, key);
722 if (ptr) 722 if (IS_ERR(ptr)) {
723 err = PTR_ERR(ptr);
724 } else if (!ptr) {
725 err = -ENOENT;
726 } else {
727 err = 0;
723 memcpy(value, ptr, value_size); 728 memcpy(value, ptr, value_size);
729 }
724 rcu_read_unlock(); 730 rcu_read_unlock();
725 err = ptr ? 0 : -ENOENT;
726 } 731 }
727 732
728 if (err) 733 if (err)