Skip to content

Commit

Permalink
skbuff: simplify __alloc_skb() a bit
Browse files Browse the repository at this point in the history
Use unlikely() annotations for skbuff_head and data similarly to the
two other allocation functions and remove totally redundant goto.

Signed-off-by: Alexander Lobakin <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
solbjorn authored and davem330 committed Feb 13, 2021
1 parent 483126b commit df1ae02
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions net/core/skbuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask,

/* Get the HEAD */
skb = kmem_cache_alloc_node(cache, gfp_mask & ~__GFP_DMA, node);
if (!skb)
goto out;
if (unlikely(!skb))
return NULL;
prefetchw(skb);

/* We do our best to align skb_shared_info on a separate cache
Expand All @@ -351,7 +351,7 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask,
size = SKB_DATA_ALIGN(size);
size += SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
data = kmalloc_reserve(size, gfp_mask, node, &pfmemalloc);
if (!data)
if (unlikely(!data))
goto nodata;
/* kmalloc(size) might give us more room than requested.
* Put skb_shared_info exactly at the end of allocated zone,
Expand Down Expand Up @@ -395,12 +395,11 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask,

skb_set_kcov_handle(skb, kcov_common_handle());

out:
return skb;

nodata:
kmem_cache_free(cache, skb);
skb = NULL;
goto out;
return NULL;
}
EXPORT_SYMBOL(__alloc_skb);

Expand Down

0 comments on commit df1ae02

Please sign in to comment.