Skip to content

Commit 582db7e

Browse files
tklauserdavem330
authored andcommitted
bpf: devmap: pass on return value of bpf_map_precharge_memlock
If bpf_map_precharge_memlock in dev_map_alloc, -ENOMEM is returned regardless of the actual error produced by bpf_map_precharge_memlock. Fix it by passing on the error returned by bpf_map_precharge_memlock. Also return -EINVAL instead of -ENOMEM if the page count overflow check fails. This makes dev_map_alloc match the behavior of other bpf maps' alloc functions wrt. return values. Signed-off-by: Tobias Klauser <tklauser@distanz.ch> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1e3c5ec commit 582db7e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

kernel/bpf/devmap.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ static u64 dev_map_bitmap_size(const union bpf_attr *attr)
7575
static struct bpf_map *dev_map_alloc(union bpf_attr *attr)
7676
{
7777
struct bpf_dtab *dtab;
78+
int err = -EINVAL;
7879
u64 cost;
79-
int err;
8080

8181
/* check sanity of attributes */
8282
if (attr->max_entries == 0 || attr->key_size != 4 ||
@@ -108,6 +108,8 @@ static struct bpf_map *dev_map_alloc(union bpf_attr *attr)
108108
if (err)
109109
goto free_dtab;
110110

111+
err = -ENOMEM;
112+
111113
/* A per cpu bitfield with a bit per possible net device */
112114
dtab->flush_needed = __alloc_percpu(dev_map_bitmap_size(attr),
113115
__alignof__(unsigned long));
@@ -128,7 +130,7 @@ static struct bpf_map *dev_map_alloc(union bpf_attr *attr)
128130
free_dtab:
129131
free_percpu(dtab->flush_needed);
130132
kfree(dtab);
131-
return ERR_PTR(-ENOMEM);
133+
return ERR_PTR(err);
132134
}
133135

134136
static void dev_map_free(struct bpf_map *map)

0 commit comments

Comments
 (0)