diff options
| author | Jean Delvare <jdelvare@suse.de> | 2007-04-26 03:44:22 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2007-04-26 03:44:22 -0400 |
| commit | eefa3906283a2b60a6d02a2cda593a7d7d7946c5 (patch) | |
| tree | a4e1f3b8dca04b8dff3cd99dc43f771f798558fb /net/appletalk | |
| parent | 28d8909bc790d936ce33f4402adf7577533bbd4b (diff) | |
[NET]: Clean up sk_buff walkers.
I noticed recently that, in skb_checksum(), "offset" and "start" are
essentially the same thing and have the same value throughout the
function, despite being computed differently. Using a single variable
allows some cleanups and makes the skb_checksum() function smaller,
more readable, and presumably marginally faster.
We appear to have many other "sk_buff walker" functions built on the
exact same model, so the cleanup applies to them, too. Here is a list
of the functions I found to be affected:
net/appletalk/ddp.c:atalk_sum_skb()
net/core/datagram.c:skb_copy_datagram_iovec()
net/core/datagram.c:skb_copy_and_csum_datagram()
net/core/skbuff.c:skb_copy_bits()
net/core/skbuff.c:skb_store_bits()
net/core/skbuff.c:skb_checksum()
net/core/skbuff.c:skb_copy_and_csum_bit()
net/core/user_dma.c:dma_skb_copy_datagram_iovec()
net/xfrm/xfrm_algo.c:skb_icv_walk()
net/xfrm/xfrm_algo.c:skb_to_sgvec()
OTOH, I admit I'm a bit surprised, the cleanup is rather obvious so I'm
really wondering if I am missing something. Can anyone please comment
on this?
Signed-off-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/appletalk')
| -rw-r--r-- | net/appletalk/ddp.c | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/net/appletalk/ddp.c b/net/appletalk/ddp.c index f6a92a0b7a..16eda21fb3 100644 --- a/net/appletalk/ddp.c +++ b/net/appletalk/ddp.c | |||
| @@ -937,11 +937,11 @@ static unsigned long atalk_sum_partial(const unsigned char *data, | |||
| 937 | static unsigned long atalk_sum_skb(const struct sk_buff *skb, int offset, | 937 | static unsigned long atalk_sum_skb(const struct sk_buff *skb, int offset, |
| 938 | int len, unsigned long sum) | 938 | int len, unsigned long sum) |
| 939 | { | 939 | { |
| 940 | int start = skb_headlen(skb); | 940 | int end = skb_headlen(skb); |
| 941 | int i, copy; | 941 | int i, copy; |
| 942 | 942 | ||
| 943 | /* checksum stuff in header space */ | 943 | /* checksum stuff in header space */ |
| 944 | if ( (copy = start - offset) > 0) { | 944 | if ((copy = end - offset) > 0) { |
| 945 | if (copy > len) | 945 | if (copy > len) |
| 946 | copy = len; | 946 | copy = len; |
| 947 | sum = atalk_sum_partial(skb->data + offset, copy, sum); | 947 | sum = atalk_sum_partial(skb->data + offset, copy, sum); |
| @@ -953,11 +953,9 @@ static unsigned long atalk_sum_skb(const struct sk_buff *skb, int offset, | |||
| 953 | 953 | ||
| 954 | /* checksum stuff in frags */ | 954 | /* checksum stuff in frags */ |
| 955 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { | 955 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
| 956 | int end; | 956 | BUG_TRAP(len >= 0); |
| 957 | 957 | ||
| 958 | BUG_TRAP(start <= offset + len); | 958 | end = offset + skb_shinfo(skb)->frags[i].size; |
| 959 | |||
| 960 | end = start + skb_shinfo(skb)->frags[i].size; | ||
| 961 | if ((copy = end - offset) > 0) { | 959 | if ((copy = end - offset) > 0) { |
| 962 | u8 *vaddr; | 960 | u8 *vaddr; |
| 963 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; | 961 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| @@ -965,36 +963,31 @@ static unsigned long atalk_sum_skb(const struct sk_buff *skb, int offset, | |||
| 965 | if (copy > len) | 963 | if (copy > len) |
| 966 | copy = len; | 964 | copy = len; |
| 967 | vaddr = kmap_skb_frag(frag); | 965 | vaddr = kmap_skb_frag(frag); |
| 968 | sum = atalk_sum_partial(vaddr + frag->page_offset + | 966 | sum = atalk_sum_partial(vaddr + frag->page_offset, |
| 969 | offset - start, copy, sum); | 967 | copy, sum); |
| 970 | kunmap_skb_frag(vaddr); | 968 | kunmap_skb_frag(vaddr); |
| 971 | 969 | ||
| 972 | if (!(len -= copy)) | 970 | if (!(len -= copy)) |
| 973 | return sum; | 971 | return sum; |
| 974 | offset += copy; | 972 | offset += copy; |
| 975 | } | 973 | } |
| 976 | start = end; | ||
| 977 | } | 974 | } |
| 978 | 975 | ||
| 979 | if (skb_shinfo(skb)->frag_list) { | 976 | if (skb_shinfo(skb)->frag_list) { |
| 980 | struct sk_buff *list = skb_shinfo(skb)->frag_list; | 977 | struct sk_buff *list = skb_shinfo(skb)->frag_list; |
| 981 | 978 | ||
| 982 | for (; list; list = list->next) { | 979 | for (; list; list = list->next) { |
| 983 | int end; | 980 | BUG_TRAP(len >= 0); |
| 984 | |||
| 985 | BUG_TRAP(start <= offset + len); | ||
| 986 | 981 | ||
| 987 | end = start + list->len; | 982 | end = offset + list->len; |
| 988 | if ((copy = end - offset) > 0) { | 983 | if ((copy = end - offset) > 0) { |
| 989 | if (copy > len) | 984 | if (copy > len) |
| 990 | copy = len; | 985 | copy = len; |
| 991 | sum = atalk_sum_skb(list, offset - start, | 986 | sum = atalk_sum_skb(list, 0, copy, sum); |
| 992 | copy, sum); | ||
| 993 | if ((len -= copy) == 0) | 987 | if ((len -= copy) == 0) |
| 994 | return sum; | 988 | return sum; |
| 995 | offset += copy; | 989 | offset += copy; |
| 996 | } | 990 | } |
| 997 | start = end; | ||
| 998 | } | 991 | } |
| 999 | } | 992 | } |
| 1000 | 993 | ||
