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/xfrm | |
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/xfrm')
-rw-r--r-- | net/xfrm/xfrm_algo.c | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/net/xfrm/xfrm_algo.c b/net/xfrm/xfrm_algo.c index 6249a9405bb8..be529c4241a6 100644 --- a/net/xfrm/xfrm_algo.c +++ b/net/xfrm/xfrm_algo.c | |||
@@ -532,8 +532,8 @@ EXPORT_SYMBOL_GPL(xfrm_count_enc_supported); | |||
532 | int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *desc, | 532 | int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *desc, |
533 | int offset, int len, icv_update_fn_t icv_update) | 533 | int offset, int len, icv_update_fn_t icv_update) |
534 | { | 534 | { |
535 | int start = skb_headlen(skb); | 535 | int end = skb_headlen(skb); |
536 | int i, copy = start - offset; | 536 | int i, copy = end - offset; |
537 | int err; | 537 | int err; |
538 | struct scatterlist sg; | 538 | struct scatterlist sg; |
539 | 539 | ||
@@ -556,11 +556,9 @@ int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *desc, | |||
556 | } | 556 | } |
557 | 557 | ||
558 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { | 558 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
559 | int end; | 559 | BUG_TRAP(len >= 0); |
560 | 560 | ||
561 | BUG_TRAP(start <= offset + len); | 561 | end = offset + skb_shinfo(skb)->frags[i].size; |
562 | |||
563 | end = start + skb_shinfo(skb)->frags[i].size; | ||
564 | if ((copy = end - offset) > 0) { | 562 | if ((copy = end - offset) > 0) { |
565 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; | 563 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
566 | 564 | ||
@@ -568,7 +566,7 @@ int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *desc, | |||
568 | copy = len; | 566 | copy = len; |
569 | 567 | ||
570 | sg.page = frag->page; | 568 | sg.page = frag->page; |
571 | sg.offset = frag->page_offset + offset-start; | 569 | sg.offset = frag->page_offset; |
572 | sg.length = copy; | 570 | sg.length = copy; |
573 | 571 | ||
574 | err = icv_update(desc, &sg, copy); | 572 | err = icv_update(desc, &sg, copy); |
@@ -579,22 +577,19 @@ int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *desc, | |||
579 | return 0; | 577 | return 0; |
580 | offset += copy; | 578 | offset += copy; |
581 | } | 579 | } |
582 | start = end; | ||
583 | } | 580 | } |
584 | 581 | ||
585 | if (skb_shinfo(skb)->frag_list) { | 582 | if (skb_shinfo(skb)->frag_list) { |
586 | struct sk_buff *list = skb_shinfo(skb)->frag_list; | 583 | struct sk_buff *list = skb_shinfo(skb)->frag_list; |
587 | 584 | ||
588 | for (; list; list = list->next) { | 585 | for (; list; list = list->next) { |
589 | int end; | 586 | BUG_TRAP(len >= 0); |
590 | |||
591 | BUG_TRAP(start <= offset + len); | ||
592 | 587 | ||
593 | end = start + list->len; | 588 | end = offset + list->len; |
594 | if ((copy = end - offset) > 0) { | 589 | if ((copy = end - offset) > 0) { |
595 | if (copy > len) | 590 | if (copy > len) |
596 | copy = len; | 591 | copy = len; |
597 | err = skb_icv_walk(list, desc, offset-start, | 592 | err = skb_icv_walk(list, desc, 0, |
598 | copy, icv_update); | 593 | copy, icv_update); |
599 | if (unlikely(err)) | 594 | if (unlikely(err)) |
600 | return err; | 595 | return err; |
@@ -602,7 +597,6 @@ int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *desc, | |||
602 | return 0; | 597 | return 0; |
603 | offset += copy; | 598 | offset += copy; |
604 | } | 599 | } |
605 | start = end; | ||
606 | } | 600 | } |
607 | } | 601 | } |
608 | BUG_ON(len); | 602 | BUG_ON(len); |