Skip to content

Commit 9e838b0

Browse files
iamkafaiAlexei Starovoitov
authored andcommitted
bpf: Folding omem_charge() into sk_storage_charge()
sk_storage_charge() is the only user of omem_charge(). This patch simplifies it by folding omem_charge() into sk_storage_charge(). Signed-off-by: Martin KaFai Lau <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Song Liu <[email protected]> Acked-by: KP Singh <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 0a58a65 commit 9e838b0

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

net/core/bpf_sk_storage.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,6 @@
1515

1616
DEFINE_BPF_STORAGE_CACHE(sk_cache);
1717

18-
static int omem_charge(struct sock *sk, unsigned int size)
19-
{
20-
/* same check as in sock_kmalloc() */
21-
if (size <= sysctl_optmem_max &&
22-
atomic_read(&sk->sk_omem_alloc) + size < sysctl_optmem_max) {
23-
atomic_add(size, &sk->sk_omem_alloc);
24-
return 0;
25-
}
26-
27-
return -ENOMEM;
28-
}
29-
3018
static struct bpf_local_storage_data *
3119
sk_storage_lookup(struct sock *sk, struct bpf_map *map, bool cacheit_lockit)
3220
{
@@ -316,7 +304,16 @@ BPF_CALL_2(bpf_sk_storage_delete, struct bpf_map *, map, struct sock *, sk)
316304
static int sk_storage_charge(struct bpf_local_storage_map *smap,
317305
void *owner, u32 size)
318306
{
319-
return omem_charge(owner, size);
307+
struct sock *sk = (struct sock *)owner;
308+
309+
/* same check as in sock_kmalloc() */
310+
if (size <= sysctl_optmem_max &&
311+
atomic_read(&sk->sk_omem_alloc) + size < sysctl_optmem_max) {
312+
atomic_add(size, &sk->sk_omem_alloc);
313+
return 0;
314+
}
315+
316+
return -ENOMEM;
320317
}
321318

322319
static void sk_storage_uncharge(struct bpf_local_storage_map *smap,

0 commit comments

Comments
 (0)