| Submitter | Eric Dumazet |
|---|---|
| Date | Oct. 5, 2012, 12:37 p.m. |
| Message ID | <1349440667.21172.54.camel@edumazet-glaptop> |
| Download | mbox | patch |
| Permalink | /patch/189471/ |
| State | RFC |
| Delegated to: | David Miller |
| Headers | show |
Comments
On Fri, 2012-10-05 at 14:37 +0200, Eric Dumazet wrote: > 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)); -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Patch
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)); + if (skb_shared(skb)) BUG(); @@ -1074,7 +1085,7 @@ int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail, /* Copy only real data... and, alas, header. This should be * optimized for the cases when header is void. */ - memcpy(data + nhead, skb->head, skb_tail_pointer(skb) - skb->head); + memcpy(data + nhead, skb->head, tail_offset); memcpy((struct skb_shared_info *)(data + size), skb_shinfo(skb),