On Fri, 2012-10-05 at 14:37 +0200, Eric Dumazet wrote:
quoted hunk ↗ jump to hunk
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index cdc2859..f6c1f52 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -1053,11 +1053,22 @@ int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail,
{
int i;
u8 *data;
- int size = nhead + skb_end_offset(skb) + ntail;
+ unsigned int tail_offset = skb_tail_pointer(skb) - skb->head;
+ int size = nhead + ntail;
long off;
BUG_ON(nhead < 0);
+ /* callers using nhead == 0 and ntail == 0 wants to get a fresh copy,
+ * so allocate same amount of memory (skb_end_offset)
+ * For others, they want extra head or tail against the currently
+ * used portion of header (skb->head -> skb_tail_pointer).
+ * But we dont shrink the head.
+ */
+ if (size)
+ size += tail_offset;
+ size = max_t(int, size, skb_end_offset(skb));
+
This can be factorized to :
size = tail_offset + nhead + ntail;
size = max_t(int, size, skb_end_offset(skb));