diff options
-rw-r--r-- | include/linux/skbuff.h | 24 | ||||
-rw-r--r-- | net/core/skbuff.c | 7 |
2 files changed, 14 insertions, 17 deletions
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 830f58fa03a2..93e4db221585 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h | |||
@@ -975,15 +975,16 @@ static inline void skb_reserve(struct sk_buff *skb, int len) | |||
975 | #define NET_SKB_PAD 16 | 975 | #define NET_SKB_PAD 16 |
976 | #endif | 976 | #endif |
977 | 977 | ||
978 | extern int ___pskb_trim(struct sk_buff *skb, unsigned int len, int realloc); | 978 | extern int ___pskb_trim(struct sk_buff *skb, unsigned int len); |
979 | 979 | ||
980 | static inline void __skb_trim(struct sk_buff *skb, unsigned int len) | 980 | static inline void __skb_trim(struct sk_buff *skb, unsigned int len) |
981 | { | 981 | { |
982 | if (!skb->data_len) { | 982 | if (unlikely(skb->data_len)) { |
983 | skb->len = len; | 983 | WARN_ON(1); |
984 | skb->tail = skb->data + len; | 984 | return; |
985 | } else | 985 | } |
986 | ___pskb_trim(skb, len, 0); | 986 | skb->len = len; |
987 | skb->tail = skb->data + len; | ||
987 | } | 988 | } |
988 | 989 | ||
989 | /** | 990 | /** |
@@ -993,6 +994,7 @@ static inline void __skb_trim(struct sk_buff *skb, unsigned int len) | |||
993 | * | 994 | * |
994 | * Cut the length of a buffer down by removing data from the tail. If | 995 | * Cut the length of a buffer down by removing data from the tail. If |
995 | * the buffer is already under the length specified it is not modified. | 996 | * the buffer is already under the length specified it is not modified. |
997 | * The skb must be linear. | ||
996 | */ | 998 | */ |
997 | static inline void skb_trim(struct sk_buff *skb, unsigned int len) | 999 | static inline void skb_trim(struct sk_buff *skb, unsigned int len) |
998 | { | 1000 | { |
@@ -1003,12 +1005,10 @@ static inline void skb_trim(struct sk_buff *skb, unsigned int len) | |||
1003 | 1005 | ||
1004 | static inline int __pskb_trim(struct sk_buff *skb, unsigned int len) | 1006 | static inline int __pskb_trim(struct sk_buff *skb, unsigned int len) |
1005 | { | 1007 | { |
1006 | if (!skb->data_len) { | 1008 | if (skb->data_len) |
1007 | skb->len = len; | 1009 | return ___pskb_trim(skb, len); |
1008 | skb->tail = skb->data+len; | 1010 | __skb_trim(skb, len); |
1009 | return 0; | 1011 | return 0; |
1010 | } | ||
1011 | return ___pskb_trim(skb, len, 1); | ||
1012 | } | 1012 | } |
1013 | 1013 | ||
1014 | static inline int pskb_trim(struct sk_buff *skb, unsigned int len) | 1014 | static inline int pskb_trim(struct sk_buff *skb, unsigned int len) |
diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 96cdcbe24ba2..bb7210f4005e 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c | |||
@@ -801,12 +801,10 @@ struct sk_buff *skb_pad(struct sk_buff *skb, int pad) | |||
801 | return nskb; | 801 | return nskb; |
802 | } | 802 | } |
803 | 803 | ||
804 | /* Trims skb to length len. It can change skb pointers, if "realloc" is 1. | 804 | /* Trims skb to length len. It can change skb pointers. |
805 | * If realloc==0 and trimming is impossible without change of data, | ||
806 | * it is BUG(). | ||
807 | */ | 805 | */ |
808 | 806 | ||
809 | int ___pskb_trim(struct sk_buff *skb, unsigned int len, int realloc) | 807 | int ___pskb_trim(struct sk_buff *skb, unsigned int len) |
810 | { | 808 | { |
811 | int offset = skb_headlen(skb); | 809 | int offset = skb_headlen(skb); |
812 | int nfrags = skb_shinfo(skb)->nr_frags; | 810 | int nfrags = skb_shinfo(skb)->nr_frags; |
@@ -816,7 +814,6 @@ int ___pskb_trim(struct sk_buff *skb, unsigned int len, int realloc) | |||
816 | int end = offset + skb_shinfo(skb)->frags[i].size; | 814 | int end = offset + skb_shinfo(skb)->frags[i].size; |
817 | if (end > len) { | 815 | if (end > len) { |
818 | if (skb_cloned(skb)) { | 816 | if (skb_cloned(skb)) { |
819 | BUG_ON(!realloc); | ||
820 | if (pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) | 817 | if (pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) |
821 | return -ENOMEM; | 818 | return -ENOMEM; |
822 | } | 819 | } |