Skip to content

Commit 7c80b03

Browse files
edumazetkuba-moo
authored andcommitted
net: fix sk_wmem_schedule() and sk_rmem_schedule() errors
If sk->sk_forward_alloc is 150000, and we need to schedule 150001 bytes, we want to allocate 1 byte more (rounded up to one page), instead of 150001 :/ Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Shakeel Butt <shakeelb@google.com> Acked-by: Soheil Hassas Yeganeh <soheil@google.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 3cd3399 commit 7c80b03

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

include/net/sock.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,19 +1575,23 @@ static inline bool sk_has_account(struct sock *sk)
15751575

15761576
static inline bool sk_wmem_schedule(struct sock *sk, int size)
15771577
{
1578+
int delta;
1579+
15781580
if (!sk_has_account(sk))
15791581
return true;
1580-
return size <= sk->sk_forward_alloc ||
1581-
__sk_mem_schedule(sk, size, SK_MEM_SEND);
1582+
delta = size - sk->sk_forward_alloc;
1583+
return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_SEND);
15821584
}
15831585

15841586
static inline bool
15851587
sk_rmem_schedule(struct sock *sk, struct sk_buff *skb, int size)
15861588
{
1589+
int delta;
1590+
15871591
if (!sk_has_account(sk))
15881592
return true;
1589-
return size <= sk->sk_forward_alloc ||
1590-
__sk_mem_schedule(sk, size, SK_MEM_RECV) ||
1593+
delta = size - sk->sk_forward_alloc;
1594+
return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_RECV) ||
15911595
skb_pfmemalloc(skb);
15921596
}
15931597

0 commit comments

Comments
 (0)