Skip to content

Commit 3b4a63f

Browse files
pbholeAlexei Starovoitov
authored andcommitted
bpf: return EOPNOTSUPP when map lookup isn't supported
Return ERR_PTR(-EOPNOTSUPP) from map_lookup_elem() methods of below map types: - BPF_MAP_TYPE_PROG_ARRAY - BPF_MAP_TYPE_STACK_TRACE - BPF_MAP_TYPE_XSKMAP - BPF_MAP_TYPE_SOCKMAP/BPF_MAP_TYPE_SOCKHASH 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>
1 parent 509db28 commit 3b4a63f

4 files changed

Lines changed: 4 additions & 4 deletions

File tree

‎kernel/bpf/arraymap.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ static void fd_array_map_free(struct bpf_map *map)
449449

450450
static void *fd_array_map_lookup_elem(struct bpf_map *map, void *key)
451451
{
452-
return NULL;
452+
return ERR_PTR(-EOPNOTSUPP);
453453
}
454454

455455
/* only called from syscall */

‎kernel/bpf/sockmap.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2096,7 +2096,7 @@ int sockmap_get_from_fd(const union bpf_attr *attr, int type,
20962096

20972097
static void *sock_map_lookup(struct bpf_map *map, void *key)
20982098
{
2099-
return NULL;
2099+
return ERR_PTR(-EOPNOTSUPP);
21002100
}
21012101

21022102
static int sock_map_update_elem(struct bpf_map *map,

‎kernel/bpf/stackmap.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ const struct bpf_func_proto bpf_get_stack_proto = {
505505
/* Called from eBPF program */
506506
static void *stack_map_lookup_elem(struct bpf_map *map, void *key)
507507
{
508-
return NULL;
508+
return ERR_PTR(-EOPNOTSUPP);
509509
}
510510

511511
/* Called from syscall */

‎kernel/bpf/xskmap.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void __xsk_map_flush(struct bpf_map *map)
154154

155155
static void *xsk_map_lookup_elem(struct bpf_map *map, void *key)
156156
{
157-
return NULL;
157+
return ERR_PTR(-EOPNOTSUPP);
158158
}
159159

160160
static int xsk_map_update_elem(struct bpf_map *map, void *key, void *value,

0 commit comments

Comments
 (0)