diff --git a/net/core/skbuff.c b/net/core/skbuff.c index a12caf373086..3001b05c919c 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -78,7 +78,6 @@ #include #include "datagram.h" -#include "sock_destructor.h" struct kmem_cache *skbuff_head_cache __ro_after_init; static struct kmem_cache *skbuff_fclone_cache __ro_after_init; @@ -1752,39 +1751,30 @@ EXPORT_SYMBOL(skb_realloc_headroom); struct sk_buff *skb_expand_head(struct sk_buff *skb, unsigned int headroom) { int delta = headroom - skb_headroom(skb); - int osize = skb_end_offset(skb); - struct sock *sk = skb->sk; if (WARN_ONCE(delta <= 0, "%s is expecting an increase in the headroom", __func__)) return skb; - delta = SKB_DATA_ALIGN(delta); - /* pskb_expand_head() might crash, if skb is shared. */ - if (skb_shared(skb) || !is_skb_wmem(skb)) { + /* pskb_expand_head() might crash, if skb is shared */ + if (skb_shared(skb)) { struct sk_buff *nskb = skb_clone(skb, GFP_ATOMIC); - if (unlikely(!nskb)) - goto fail; - - if (sk) - skb_set_owner_w(nskb, sk); - consume_skb(skb); + if (likely(nskb)) { + if (skb->sk) + skb_set_owner_w(nskb, skb->sk); + consume_skb(skb); + } else { + kfree_skb(skb); + } skb = nskb; } - if (pskb_expand_head(skb, delta, 0, GFP_ATOMIC)) - goto fail; - - if (sk && is_skb_wmem(skb)) { - delta = skb_end_offset(skb) - osize; - refcount_add(delta, &sk->sk_wmem_alloc); - skb->truesize += delta; + if (skb && + pskb_expand_head(skb, SKB_DATA_ALIGN(delta), 0, GFP_ATOMIC)) { + kfree_skb(skb); + skb = NULL; } return skb; - -fail: - kfree_skb(skb); - return NULL; } EXPORT_SYMBOL(skb_expand_head);