mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-28 01:21:58 +00:00
bpf: move memory size checks to bpf_map_charge_init()
Most bpf map types doing similar checks and bytes to pages conversion during memory allocation and charging. Let's unify these checks by moving them into bpf_map_charge_init(). Signed-off-by: Roman Gushchin <guro@fb.com> Acked-by: Song Liu <songliubraving@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
b936ca643a
commit
c85d69135a
14 changed files with 20 additions and 67 deletions
|
@ -44,13 +44,7 @@ static struct bpf_map *sock_map_alloc(union bpf_attr *attr)
|
|||
|
||||
/* Make sure page count doesn't overflow. */
|
||||
cost = (u64) stab->map.max_entries * sizeof(struct sock *);
|
||||
if (cost >= U32_MAX - PAGE_SIZE) {
|
||||
err = -EINVAL;
|
||||
goto free_stab;
|
||||
}
|
||||
|
||||
err = bpf_map_charge_init(&stab->map.memory,
|
||||
round_up(cost, PAGE_SIZE) >> PAGE_SHIFT);
|
||||
err = bpf_map_charge_init(&stab->map.memory, cost);
|
||||
if (err)
|
||||
goto free_stab;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue