Commit eefa3906 authored by Jean Delvare's avatar Jean Delvare Committed by David S. Miller

[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: default avatarJean Delvare <jdelvare@suse.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 28d8909b
...@@ -937,11 +937,11 @@ static unsigned long atalk_sum_partial(const unsigned char *data, ...@@ -937,11 +937,11 @@ static unsigned long atalk_sum_partial(const unsigned char *data,
static unsigned long atalk_sum_skb(const struct sk_buff *skb, int offset, static unsigned long atalk_sum_skb(const struct sk_buff *skb, int offset,
int len, unsigned long sum) int len, unsigned long sum)
{ {
int start = skb_headlen(skb); int end = skb_headlen(skb);
int i, copy; int i, copy;
/* checksum stuff in header space */ /* checksum stuff in header space */
if ( (copy = start - offset) > 0) { if ((copy = end - offset) > 0) {
if (copy > len) if (copy > len)
copy = len; copy = len;
sum = atalk_sum_partial(skb->data + offset, copy, sum); 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,11 +953,9 @@ static unsigned long atalk_sum_skb(const struct sk_buff *skb, int offset,
/* checksum stuff in frags */ /* checksum stuff in frags */
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
int end; BUG_TRAP(len >= 0);
BUG_TRAP(start <= offset + len);
end = start + skb_shinfo(skb)->frags[i].size; end = offset + skb_shinfo(skb)->frags[i].size;
if ((copy = end - offset) > 0) { if ((copy = end - offset) > 0) {
u8 *vaddr; u8 *vaddr;
skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; 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,36 +963,31 @@ static unsigned long atalk_sum_skb(const struct sk_buff *skb, int offset,
if (copy > len) if (copy > len)
copy = len; copy = len;
vaddr = kmap_skb_frag(frag); vaddr = kmap_skb_frag(frag);
sum = atalk_sum_partial(vaddr + frag->page_offset + sum = atalk_sum_partial(vaddr + frag->page_offset,
offset - start, copy, sum); copy, sum);
kunmap_skb_frag(vaddr); kunmap_skb_frag(vaddr);
if (!(len -= copy)) if (!(len -= copy))
return sum; return sum;
offset += copy; offset += copy;
} }
start = end;
} }
if (skb_shinfo(skb)->frag_list) { if (skb_shinfo(skb)->frag_list) {
struct sk_buff *list = skb_shinfo(skb)->frag_list; struct sk_buff *list = skb_shinfo(skb)->frag_list;
for (; list; list = list->next) { for (; list; list = list->next) {
int end; BUG_TRAP(len >= 0);
BUG_TRAP(start <= offset + len); end = offset + list->len;
end = start + list->len;
if ((copy = end - offset) > 0) { if ((copy = end - offset) > 0) {
if (copy > len) if (copy > len)
copy = len; copy = len;
sum = atalk_sum_skb(list, offset - start, sum = atalk_sum_skb(list, 0, copy, sum);
copy, sum);
if ((len -= copy) == 0) if ((len -= copy) == 0)
return sum; return sum;
offset += copy; offset += copy;
} }
start = end;
} }
} }
......
...@@ -247,8 +247,8 @@ EXPORT_SYMBOL(skb_kill_datagram); ...@@ -247,8 +247,8 @@ EXPORT_SYMBOL(skb_kill_datagram);
int skb_copy_datagram_iovec(const struct sk_buff *skb, int offset, int skb_copy_datagram_iovec(const struct sk_buff *skb, int offset,
struct iovec *to, int len) struct iovec *to, int len)
{ {
int start = skb_headlen(skb); int end = skb_headlen(skb);
int i, copy = start - offset; int i, copy = end - offset;
/* Copy header. */ /* Copy header. */
if (copy > 0) { if (copy > 0) {
...@@ -263,11 +263,9 @@ int skb_copy_datagram_iovec(const struct sk_buff *skb, int offset, ...@@ -263,11 +263,9 @@ int skb_copy_datagram_iovec(const struct sk_buff *skb, int offset,
/* Copy paged appendix. Hmm... why does this look so complicated? */ /* Copy paged appendix. Hmm... why does this look so complicated? */
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
int end; BUG_TRAP(len >= 0);
BUG_TRAP(start <= offset + len); end = offset + skb_shinfo(skb)->frags[i].size;
end = start + skb_shinfo(skb)->frags[i].size;
if ((copy = end - offset) > 0) { if ((copy = end - offset) > 0) {
int err; int err;
u8 *vaddr; u8 *vaddr;
...@@ -277,8 +275,8 @@ int skb_copy_datagram_iovec(const struct sk_buff *skb, int offset, ...@@ -277,8 +275,8 @@ int skb_copy_datagram_iovec(const struct sk_buff *skb, int offset,
if (copy > len) if (copy > len)
copy = len; copy = len;
vaddr = kmap(page); vaddr = kmap(page);
err = memcpy_toiovec(to, vaddr + frag->page_offset + err = memcpy_toiovec(to, vaddr + frag->page_offset,
offset - start, copy); copy);
kunmap(page); kunmap(page);
if (err) if (err)
goto fault; goto fault;
...@@ -286,30 +284,24 @@ int skb_copy_datagram_iovec(const struct sk_buff *skb, int offset, ...@@ -286,30 +284,24 @@ int skb_copy_datagram_iovec(const struct sk_buff *skb, int offset,
return 0; return 0;
offset += copy; offset += copy;
} }
start = end;
} }
if (skb_shinfo(skb)->frag_list) { if (skb_shinfo(skb)->frag_list) {
struct sk_buff *list = skb_shinfo(skb)->frag_list; struct sk_buff *list = skb_shinfo(skb)->frag_list;
for (; list; list = list->next) { for (; list; list = list->next) {
int end; BUG_TRAP(len >= 0);
BUG_TRAP(start <= offset + len);
end = start + list->len; end = offset + list->len;
if ((copy = end - offset) > 0) { if ((copy = end - offset) > 0) {
if (copy > len) if (copy > len)
copy = len; copy = len;
if (skb_copy_datagram_iovec(list, if (skb_copy_datagram_iovec(list, 0, to, copy))
offset - start,
to, copy))
goto fault; goto fault;
if ((len -= copy) == 0) if ((len -= copy) == 0)
return 0; return 0;
offset += copy; offset += copy;
} }
start = end;
} }
} }
if (!len) if (!len)
...@@ -323,9 +315,9 @@ static int skb_copy_and_csum_datagram(const struct sk_buff *skb, int offset, ...@@ -323,9 +315,9 @@ static int skb_copy_and_csum_datagram(const struct sk_buff *skb, int offset,
u8 __user *to, int len, u8 __user *to, int len,
__wsum *csump) __wsum *csump)
{ {
int start = skb_headlen(skb); int end = skb_headlen(skb);
int pos = 0; int pos = 0;
int i, copy = start - offset; int i, copy = end - offset;
/* Copy header. */ /* Copy header. */
if (copy > 0) { if (copy > 0) {
...@@ -344,11 +336,9 @@ static int skb_copy_and_csum_datagram(const struct sk_buff *skb, int offset, ...@@ -344,11 +336,9 @@ static int skb_copy_and_csum_datagram(const struct sk_buff *skb, int offset,
} }
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
int end; BUG_TRAP(len >= 0);
BUG_TRAP(start <= offset + len); end = offset + skb_shinfo(skb)->frags[i].size;
end = start + skb_shinfo(skb)->frags[i].size;
if ((copy = end - offset) > 0) { if ((copy = end - offset) > 0) {
__wsum csum2; __wsum csum2;
int err = 0; int err = 0;
...@@ -360,8 +350,7 @@ static int skb_copy_and_csum_datagram(const struct sk_buff *skb, int offset, ...@@ -360,8 +350,7 @@ static int skb_copy_and_csum_datagram(const struct sk_buff *skb, int offset,
copy = len; copy = len;
vaddr = kmap(page); vaddr = kmap(page);
csum2 = csum_and_copy_to_user(vaddr + csum2 = csum_and_copy_to_user(vaddr +
frag->page_offset + frag->page_offset,
offset - start,
to, copy, 0, &err); to, copy, 0, &err);
kunmap(page); kunmap(page);
if (err) if (err)
...@@ -373,24 +362,20 @@ static int skb_copy_and_csum_datagram(const struct sk_buff *skb, int offset, ...@@ -373,24 +362,20 @@ static int skb_copy_and_csum_datagram(const struct sk_buff *skb, int offset,
to += copy; to += copy;
pos += copy; pos += copy;
} }
start = end;
} }
if (skb_shinfo(skb)->frag_list) { if (skb_shinfo(skb)->frag_list) {
struct sk_buff *list = skb_shinfo(skb)->frag_list; struct sk_buff *list = skb_shinfo(skb)->frag_list;
for (; list; list=list->next) { for (; list; list=list->next) {
int end; BUG_TRAP(len >= 0);
BUG_TRAP(start <= offset + len);
end = start + list->len; end = offset + list->len;
if ((copy = end - offset) > 0) { if ((copy = end - offset) > 0) {
__wsum csum2 = 0; __wsum csum2 = 0;
if (copy > len) if (copy > len)
copy = len; copy = len;
if (skb_copy_and_csum_datagram(list, if (skb_copy_and_csum_datagram(list, 0,
offset - start,
to, copy, to, copy,
&csum2)) &csum2))
goto fault; goto fault;
...@@ -401,7 +386,6 @@ static int skb_copy_and_csum_datagram(const struct sk_buff *skb, int offset, ...@@ -401,7 +386,6 @@ static int skb_copy_and_csum_datagram(const struct sk_buff *skb, int offset,
to += copy; to += copy;
pos += copy; pos += copy;
} }
start = end;
} }
} }
if (!len) if (!len)
......
...@@ -1045,13 +1045,13 @@ unsigned char *__pskb_pull_tail(struct sk_buff *skb, int delta) ...@@ -1045,13 +1045,13 @@ unsigned char *__pskb_pull_tail(struct sk_buff *skb, int delta)
int skb_copy_bits(const struct sk_buff *skb, int offset, void *to, int len) int skb_copy_bits(const struct sk_buff *skb, int offset, void *to, int len)
{ {
int i, copy; int i, copy;
int start = skb_headlen(skb); int end = skb_headlen(skb);
if (offset > (int)skb->len - len) if (offset > (int)skb->len - len)
goto fault; goto fault;
/* Copy header. */ /* Copy header. */
if ((copy = start - offset) > 0) { if ((copy = end - offset) > 0) {
if (copy > len) if (copy > len)
copy = len; copy = len;
skb_copy_from_linear_data_offset(skb, offset, to, copy); skb_copy_from_linear_data_offset(skb, offset, to, copy);
...@@ -1062,11 +1062,9 @@ int skb_copy_bits(const struct sk_buff *skb, int offset, void *to, int len) ...@@ -1062,11 +1062,9 @@ int skb_copy_bits(const struct sk_buff *skb, int offset, void *to, int len)
} }
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
int end; BUG_TRAP(len >= 0);
BUG_TRAP(start <= offset + len);
end = start + skb_shinfo(skb)->frags[i].size; end = offset + skb_shinfo(skb)->frags[i].size;
if ((copy = end - offset) > 0) { if ((copy = end - offset) > 0) {
u8 *vaddr; u8 *vaddr;
...@@ -1075,8 +1073,8 @@ int skb_copy_bits(const struct sk_buff *skb, int offset, void *to, int len) ...@@ -1075,8 +1073,8 @@ int skb_copy_bits(const struct sk_buff *skb, int offset, void *to, int len)
vaddr = kmap_skb_frag(&skb_shinfo(skb)->frags[i]); vaddr = kmap_skb_frag(&skb_shinfo(skb)->frags[i]);
memcpy(to, memcpy(to,
vaddr + skb_shinfo(skb)->frags[i].page_offset+ vaddr + skb_shinfo(skb)->frags[i].page_offset,
offset - start, copy); copy);
kunmap_skb_frag(vaddr); kunmap_skb_frag(vaddr);
if ((len -= copy) == 0) if ((len -= copy) == 0)
...@@ -1084,30 +1082,25 @@ int skb_copy_bits(const struct sk_buff *skb, int offset, void *to, int len) ...@@ -1084,30 +1082,25 @@ int skb_copy_bits(const struct sk_buff *skb, int offset, void *to, int len)
offset += copy; offset += copy;
to += copy; to += copy;
} }
start = end;
} }
if (skb_shinfo(skb)->frag_list) { if (skb_shinfo(skb)->frag_list) {
struct sk_buff *list = skb_shinfo(skb)->frag_list; struct sk_buff *list = skb_shinfo(skb)->frag_list;
for (; list; list = list->next) { for (; list; list = list->next) {
int end; BUG_TRAP(len >= 0);
BUG_TRAP(start <= offset + len); end = offset + list->len;
end = start + list->len;
if ((copy = end - offset) > 0) { if ((copy = end - offset) > 0) {
if (copy > len) if (copy > len)
copy = len; copy = len;
if (skb_copy_bits(list, offset - start, if (skb_copy_bits(list, 0, to, copy))
to, copy))
goto fault; goto fault;
if ((len -= copy) == 0) if ((len -= copy) == 0)
return 0; return 0;
offset += copy; offset += copy;
to += copy; to += copy;
} }
start = end;
} }
} }
if (!len) if (!len)
...@@ -1132,12 +1125,12 @@ int skb_copy_bits(const struct sk_buff *skb, int offset, void *to, int len) ...@@ -1132,12 +1125,12 @@ int skb_copy_bits(const struct sk_buff *skb, int offset, void *to, int len)
int skb_store_bits(struct sk_buff *skb, int offset, const void *from, int len) int skb_store_bits(struct sk_buff *skb, int offset, const void *from, int len)
{ {
int i, copy; int i, copy;
int start = skb_headlen(skb); int end = skb_headlen(skb);
if (offset > (int)skb->len - len) if (offset > (int)skb->len - len)
goto fault; goto fault;
if ((copy = start - offset) > 0) { if ((copy = end - offset) > 0) {
if (copy > len) if (copy > len)
copy = len; copy = len;
skb_copy_to_linear_data_offset(skb, offset, from, copy); skb_copy_to_linear_data_offset(skb, offset, from, copy);
...@@ -1149,11 +1142,9 @@ int skb_store_bits(struct sk_buff *skb, int offset, const void *from, int len) ...@@ -1149,11 +1142,9 @@ int skb_store_bits(struct sk_buff *skb, int offset, const void *from, int len)
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
int end; BUG_TRAP(len >= 0);
BUG_TRAP(start <= offset + len); end = offset + frag->size;
end = start + frag->size;
if ((copy = end - offset) > 0) { if ((copy = end - offset) > 0) {
u8 *vaddr; u8 *vaddr;
...@@ -1161,8 +1152,7 @@ int skb_store_bits(struct sk_buff *skb, int offset, const void *from, int len) ...@@ -1161,8 +1152,7 @@ int skb_store_bits(struct sk_buff *skb, int offset, const void *from, int len)
copy = len; copy = len;
vaddr = kmap_skb_frag(frag); vaddr = kmap_skb_frag(frag);
memcpy(vaddr + frag->page_offset + offset - start, memcpy(vaddr + frag->page_offset, from, copy);
from, copy);
kunmap_skb_frag(vaddr); kunmap_skb_frag(vaddr);
if ((len -= copy) == 0) if ((len -= copy) == 0)
...@@ -1170,30 +1160,25 @@ int skb_store_bits(struct sk_buff *skb, int offset, const void *from, int len) ...@@ -1170,30 +1160,25 @@ int skb_store_bits(struct sk_buff *skb, int offset, const void *from, int len)
offset += copy; offset += copy;
from += copy; from += copy;
} }
start = end;
} }
if (skb_shinfo(skb)->frag_list) { if (skb_shinfo(skb)->frag_list) {
struct sk_buff *list = skb_shinfo(skb)->frag_list; struct sk_buff *list = skb_shinfo(skb)->frag_list;
for (; list; list = list->next) { for (; list; list = list->next) {
int end; BUG_TRAP(len >= 0);
BUG_TRAP(start <= offset + len);
end = start + list->len; end = offset + list->len;
if ((copy = end - offset) > 0) { if ((copy = end - offset) > 0) {
if (copy > len) if (copy > len)
copy = len; copy = len;
if (skb_store_bits(list, offset - start, if (skb_store_bits(list, 0, from, copy))
from, copy))
goto fault; goto fault;
if ((len -= copy) == 0) if ((len -= copy) == 0)
return 0; return 0;
offset += copy; offset += copy;
from += copy; from += copy;
} }
start = end;
} }
} }
if (!len) if (!len)
...@@ -1210,8 +1195,8 @@ EXPORT_SYMBOL(skb_store_bits); ...@@ -1210,8 +1195,8 @@ EXPORT_SYMBOL(skb_store_bits);
__wsum skb_checksum(const struct sk_buff *skb, int offset, __wsum skb_checksum(const struct sk_buff *skb, int offset,
int len, __wsum csum) int len, __wsum csum)
{ {
int start = skb_headlen(skb); int end = skb_headlen(skb);
int i, copy = start - offset; int i, copy = end - offset;
int pos = 0; int pos = 0;
/* Checksum header. */ /* Checksum header. */
...@@ -1226,11 +1211,9 @@ __wsum skb_checksum(const struct sk_buff *skb, int offset, ...@@ -1226,11 +1211,9 @@ __wsum skb_checksum(const struct sk_buff *skb, int offset,
} }
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
int end; BUG_TRAP(len >= 0);
BUG_TRAP(start <= offset + len); end = offset + skb_shinfo(skb)->frags[i].size;
end = start + skb_shinfo(skb)->frags[i].size;
if ((copy = end - offset) > 0) { if ((copy = end - offset) > 0) {
__wsum csum2; __wsum csum2;
u8 *vaddr; u8 *vaddr;
...@@ -1239,8 +1222,8 @@ __wsum skb_checksum(const struct sk_buff *skb, int offset, ...@@ -1239,8 +1222,8 @@ __wsum skb_checksum(const struct sk_buff *skb, int offset,
if (copy > len) if (copy > len)
copy = len; copy = len;
vaddr = kmap_skb_frag(frag); vaddr = kmap_skb_frag(frag);
csum2 = csum_partial(vaddr + frag->page_offset + csum2 = csum_partial(vaddr + frag->page_offset,
offset - start, copy, 0); copy, 0);
kunmap_skb_frag(vaddr); kunmap_skb_frag(vaddr);
csum = csum_block_add(csum, csum2, pos); csum = csum_block_add(csum, csum2, pos);
if (!(len -= copy)) if (!(len -= copy))
...@@ -1248,31 +1231,26 @@ __wsum skb_checksum(const struct sk_buff *skb, int offset, ...@@ -1248,31 +1231,26 @@ __wsum skb_checksum(const struct sk_buff *skb, int offset,
offset += copy; offset += copy;
pos += copy; pos += copy;
} }
start = end;
} }
if (skb_shinfo(skb)->frag_list) { if (skb_shinfo(skb)->frag_list) {
struct sk_buff *list = skb_shinfo(skb)->frag_list; struct sk_buff *list = skb_shinfo(skb)->frag_list;
for (; list; list = list->next) { for (; list; list = list->next) {
int end; BUG_TRAP(len >= 0);
BUG_TRAP(start <= offset + len); end = offset + list->len;
end = start + list->len;
if ((copy = end - offset) > 0) { if ((copy = end - offset) > 0) {
__wsum csum2; __wsum csum2;
if (copy > len) if (copy > len)
copy = len; copy = len;
csum2 = skb_checksum(list, offset - start, csum2 = skb_checksum(list, 0, copy, 0);
copy, 0);
csum = csum_block_add(csum, csum2, pos); csum = csum_block_add(csum, csum2, pos);
if ((len -= copy) == 0) if ((len -= copy) == 0)
return csum; return csum;
offset += copy; offset += copy;
pos += copy; pos += copy;
} }
start = end;
} }
} }
BUG_ON(len); BUG_ON(len);
...@@ -1285,8 +1263,8 @@ __wsum skb_checksum(const struct sk_buff *skb, int offset, ...@@ -1285,8 +1263,8 @@ __wsum skb_checksum(const struct sk_buff *skb, int offset,
__wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset, __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,
u8 *to, int len, __wsum csum) u8 *to, int len, __wsum csum)
{ {
int start = skb_headlen(skb); int end = skb_headlen(skb);
int i, copy = start - offset; int i, copy = end - offset;
int pos = 0; int pos = 0;
/* Copy header. */ /* Copy header. */
...@@ -1303,11 +1281,9 @@ __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset, ...@@ -1303,11 +1281,9 @@ __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,
} }
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
int end; BUG_TRAP(len >= 0);
BUG_TRAP(start <= offset + len); end = offset + skb_shinfo(skb)->frags[i].size;
end = start + skb_shinfo(skb)->frags[i].size;
if ((copy = end - offset) > 0) { if ((copy = end - offset) > 0) {
__wsum csum2; __wsum csum2;
u8 *vaddr; u8 *vaddr;
...@@ -1317,9 +1293,8 @@ __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset, ...@@ -1317,9 +1293,8 @@ __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,
copy = len; copy = len;
vaddr = kmap_skb_frag(frag); vaddr = kmap_skb_frag(frag);
csum2 = csum_partial_copy_nocheck(vaddr + csum2 = csum_partial_copy_nocheck(vaddr +
frag->page_offset + frag->page_offset,
offset - start, to, to, copy, 0);
copy, 0);
kunmap_skb_frag(vaddr); kunmap_skb_frag(vaddr);
csum = csum_block_add(csum, csum2, pos); csum = csum_block_add(csum, csum2, pos);
if (!(len -= copy)) if (!(len -= copy))
...@@ -1328,7 +1303,6 @@ __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset, ...@@ -1328,7 +1303,6 @@ __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,
to += copy; to += copy;
pos += copy; pos += copy;
} }
start = end;
} }
if (skb_shinfo(skb)->frag_list) { if (skb_shinfo(skb)->frag_list) {
...@@ -1336,16 +1310,13 @@ __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset, ...@@ -1336,16 +1310,13 @@ __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,
for (; list; list = list->next) { for (; list; list = list->next) {
__wsum csum2; __wsum csum2;
int end; BUG_TRAP(len >= 0);
BUG_TRAP(start <= offset + len);
end = start + list->len; end = offset + list->len;
if ((copy = end - offset) > 0) { if ((copy = end - offset) > 0) {
if (copy > len) if (copy > len)
copy = len; copy = len;
csum2 = skb_copy_and_csum_bits(list, csum2 = skb_copy_and_csum_bits(list, 0,
offset - start,
to, copy, 0); to, copy, 0);
csum = csum_block_add(csum, csum2, pos); csum = csum_block_add(csum, csum2, pos);
if ((len -= copy) == 0) if ((len -= copy) == 0)
...@@ -1354,7 +1325,6 @@ __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset, ...@@ -1354,7 +1325,6 @@ __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,
to += copy; to += copy;
pos += copy; pos += copy;
} }
start = end;
} }
} }
BUG_ON(len); BUG_ON(len);
...@@ -2026,8 +1996,8 @@ void __init skb_init(void) ...@@ -2026,8 +1996,8 @@ void __init skb_init(void)
int int
skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int offset, int len) skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int offset, int len)
{ {
int start = skb_headlen(skb); int end = skb_headlen(skb);
int i, copy = start - offset; int i, copy = end - offset;
int elt = 0; int elt = 0;
if (copy > 0) { if (copy > 0) {
...@@ -2043,45 +2013,39 @@ skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int offset, int len) ...@@ -2043,45 +2013,39 @@ skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int offset, int len)
} }
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
int end; BUG_TRAP(len >= 0);
BUG_TRAP(start <= offset + len); end = offset + skb_shinfo(skb)->frags[i].size;
end = start + skb_shinfo(skb)->frags[i].size;
if ((copy = end - offset) > 0) { if ((copy = end - offset) > 0) {
skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
if (copy > len) if (copy > len)
copy = len; copy = len;
sg[elt].page = frag->page; sg[elt].page = frag->page;
sg[elt].offset = frag->page_offset+offset-start; sg[elt].offset = frag->page_offset;
sg[elt].length = copy; sg[elt].length = copy;
elt++; elt++;
if (!(len -= copy)) if (!(len -= copy))
return elt; return elt;
offset += copy; offset += copy;
} }
start = end;
} }
if (skb_shinfo(skb)->frag_list) { if (skb_shinfo(skb)->frag_list) {
struct sk_buff *list = skb_shinfo(skb)->frag_list; struct sk_buff *list = skb_shinfo(skb)->frag_list;
for (; list; list = list->next) { for (; list; list = list->next) {
int end; BUG_TRAP(len >= 0);
BUG_TRAP(start <= offset + len);
end = start + list->len; end = offset + list->len;
if ((copy = end - offset) > 0) { if ((copy = end - offset) > 0) {
if (copy > len) if (copy > len)
copy = len; copy = len;
elt += skb_to_sgvec(list, sg+elt, offset - start, copy); elt += skb_to_sgvec(list, sg+elt, 0, copy);
if ((len -= copy) == 0) if ((len -= copy) == 0)
return elt; return elt;
offset += copy; offset += copy;
} }
start = end;
} }
} }
BUG_ON(len); BUG_ON(len);
......
...@@ -49,8 +49,8 @@ int dma_skb_copy_datagram_iovec(struct dma_chan *chan, ...@@ -49,8 +49,8 @@ int dma_skb_copy_datagram_iovec(struct dma_chan *chan,
struct sk_buff *skb, int offset, struct iovec *to, struct sk_buff *skb, int offset, struct iovec *to,
size_t len, struct dma_pinned_list *pinned_list) size_t len, struct dma_pinned_list *pinned_list)
{ {
int start = skb_headlen(skb); int end = skb_headlen(skb);
int i, copy = start - offset; int i, copy = end - offset;
dma_cookie_t cookie = 0; dma_cookie_t cookie = 0;
/* Copy header. */ /* Copy header. */
...@@ -69,11 +69,9 @@ int dma_skb_copy_datagram_iovec(struct dma_chan *chan, ...@@ -69,11 +69,9 @@ int dma_skb_copy_datagram_iovec(struct dma_chan *chan,
/* Copy paged appendix. Hmm... why does this look so complicated? */ /* Copy paged appendix. Hmm... why does this look so complicated? */
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
int end; BUG_TRAP(len >= 0);
BUG_TRAP(start <= offset + len); end = offset + skb_shinfo(skb)->frags[i].size;
end = start + skb_shinfo(skb)->frags[i].size;
copy = end - offset; copy = end - offset;
if ((copy = end - offset) > 0) { if ((copy = end - offset) > 0) {
skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
...@@ -82,8 +80,8 @@ int dma_skb_copy_datagram_iovec(struct dma_chan *chan, ...@@ -82,8 +80,8 @@ int dma_skb_copy_datagram_iovec(struct dma_chan *chan,
if (copy > len) if (copy > len)
copy = len; copy = len;
cookie = dma_memcpy_pg_to_iovec(chan, to, pinned_list, page, cookie = dma_memcpy_pg_to_iovec(chan, to, pinned_list,
frag->page_offset + offset - start, copy); page, frag->page_offset, copy);
if (cookie < 0) if (cookie < 0)
goto fault; goto fault;
len -= copy; len -= copy;
...@@ -91,25 +89,21 @@ int dma_skb_copy_datagram_iovec(struct dma_chan *chan, ...@@ -91,25 +89,21 @@ int dma_skb_copy_datagram_iovec(struct dma_chan *chan,
goto end; goto end;
offset += copy; offset += copy;
} }
start = end;
} }
if (skb_shinfo(skb)->frag_list) { if (skb_shinfo(skb)->frag_list) {
struct sk_buff *list = skb_shinfo(skb)->frag_list; struct sk_buff *list = skb_shinfo(skb)->frag_list;
for (; list; list = list->next) { for (; list; list = list->next) {
int end; BUG_TRAP(len >= 0);
BUG_TRAP(start <= offset + len);
end = start + list->len; end = offset + list->len;
copy = end - offset; copy = end - offset;
if (copy > 0) { if (copy > 0) {
if (copy > len) if (copy > len)
copy = len; copy = len;
cookie = dma_skb_copy_datagram_iovec(chan, list, cookie = dma_skb_copy_datagram_iovec(chan, list,
offset - start, to, copy, 0, to, copy, pinned_list);
pinned_list);
if (cookie < 0) if (cookie < 0)
goto fault; goto fault;
len -= copy; len -= copy;
...@@ -117,7 +111,6 @@ int dma_skb_copy_datagram_iovec(struct dma_chan *chan, ...@@ -117,7 +111,6 @@ int dma_skb_copy_datagram_iovec(struct dma_chan *chan,
goto end; goto end;
offset += copy; offset += copy;
} }
start = end;
} }
} }
......
...@@ -532,8 +532,8 @@ EXPORT_SYMBOL_GPL(xfrm_count_enc_supported); ...@@ -532,8 +532,8 @@ EXPORT_SYMBOL_GPL(xfrm_count_enc_supported);
int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *desc, int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *desc,
int offset, int len, icv_update_fn_t icv_update) int offset, int len, icv_update_fn_t icv_update)
{ {
int start = skb_headlen(skb); int end = skb_headlen(skb);
int i, copy = start - offset; int i, copy = end - offset;
int err; int err;
struct scatterlist sg; struct scatterlist sg;
...@@ -556,11 +556,9 @@ int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *desc, ...@@ -556,11 +556,9 @@ int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *desc,
} }
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
int end; BUG_TRAP(len >= 0);
BUG_TRAP(start <= offset + len); end = offset + skb_shinfo(skb)->frags[i].size;
end = start + skb_shinfo(skb)->frags[i].size;
if ((copy = end - offset) > 0) { if ((copy = end - offset) > 0) {
skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
...@@ -568,7 +566,7 @@ int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *desc, ...@@ -568,7 +566,7 @@ int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *desc,
copy = len; copy = len;
sg.page = frag->page; sg.page = frag->page;
sg.offset = frag->page_offset + offset-start; sg.offset = frag->page_offset;
sg.length = copy; sg.length = copy;
err = icv_update(desc, &sg, copy); err = icv_update(desc, &sg, copy);
...@@ -579,22 +577,19 @@ int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *desc, ...@@ -579,22 +577,19 @@ int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *desc,
return 0; return 0;
offset += copy; offset += copy;
} }
start = end;
} }
if (skb_shinfo(skb)->frag_list) { if (skb_shinfo(skb)->frag_list) {
struct sk_buff *list = skb_shinfo(skb)->frag_list; struct sk_buff *list = skb_shinfo(skb)->frag_list;
for (; list; list = list->next) { for (; list; list = list->next) {
int end; BUG_TRAP(len >= 0);
BUG_TRAP(start <= offset + len);
end = start + list->len; end = offset + list->len;
if ((copy = end - offset) > 0) { if ((copy = end - offset) > 0) {
if (copy > len) if (copy > len)
copy = len; copy = len;
err = skb_icv_walk(list, desc, offset-start, err = skb_icv_walk(list, desc, 0,
copy, icv_update); copy, icv_update);
if (unlikely(err)) if (unlikely(err))
return err; return err;
...@@ -602,7 +597,6 @@ int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *desc, ...@@ -602,7 +597,6 @@ int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *desc,
return 0; return 0;
offset += copy; offset += copy;
} }
start = end;
} }
} }
BUG_ON(len); BUG_ON(len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment