Commit 582db7e0 authored by Tobias Klauser's avatar Tobias Klauser Committed by David S. Miller

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: default avatarTobias Klauser <tklauser@distanz.ch>
Acked-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1e3c5ec6
...@@ -75,8 +75,8 @@ static u64 dev_map_bitmap_size(const union bpf_attr *attr) ...@@ -75,8 +75,8 @@ static u64 dev_map_bitmap_size(const union bpf_attr *attr)
static struct bpf_map *dev_map_alloc(union bpf_attr *attr) static struct bpf_map *dev_map_alloc(union bpf_attr *attr)
{ {
struct bpf_dtab *dtab; struct bpf_dtab *dtab;
int err = -EINVAL;
u64 cost; u64 cost;
int err;
/* check sanity of attributes */ /* check sanity of attributes */
if (attr->max_entries == 0 || attr->key_size != 4 || if (attr->max_entries == 0 || attr->key_size != 4 ||
...@@ -108,6 +108,8 @@ static struct bpf_map *dev_map_alloc(union bpf_attr *attr) ...@@ -108,6 +108,8 @@ static struct bpf_map *dev_map_alloc(union bpf_attr *attr)
if (err) if (err)
goto free_dtab; goto free_dtab;
err = -ENOMEM;
/* A per cpu bitfield with a bit per possible net device */ /* A per cpu bitfield with a bit per possible net device */
dtab->flush_needed = __alloc_percpu(dev_map_bitmap_size(attr), dtab->flush_needed = __alloc_percpu(dev_map_bitmap_size(attr),
__alignof__(unsigned long)); __alignof__(unsigned long));
...@@ -128,7 +130,7 @@ static struct bpf_map *dev_map_alloc(union bpf_attr *attr) ...@@ -128,7 +130,7 @@ static struct bpf_map *dev_map_alloc(union bpf_attr *attr)
free_dtab: free_dtab:
free_percpu(dtab->flush_needed); free_percpu(dtab->flush_needed);
kfree(dtab); kfree(dtab);
return ERR_PTR(-ENOMEM); return ERR_PTR(err);
} }
static void dev_map_free(struct bpf_map *map) static void dev_map_free(struct bpf_map *map)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment