mirror of
https://github.com/adulau/aha.git
synced 2025-01-03 22:53:18 +00:00
[NET]: Use non-recursive algorithm in skb_copy_datagram_iovec()
Use iteration instead of recursion. Fraglists within fraglists should never occur, so we BUG check this. Signed-off-by: Daniel Phillips <phillips@istop.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
95001ee925
commit
bc8dfcb939
1 changed files with 26 additions and 55 deletions
|
@ -211,74 +211,45 @@ void skb_free_datagram(struct sock *sk, struct sk_buff *skb)
|
||||||
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 i, err, fraglen, end = 0;
|
||||||
int i, copy = start - offset;
|
struct sk_buff *next = skb_shinfo(skb)->frag_list;
|
||||||
|
next_skb:
|
||||||
|
fraglen = skb_headlen(skb);
|
||||||
|
i = -1;
|
||||||
|
|
||||||
/* Copy header. */
|
while (1) {
|
||||||
if (copy > 0) {
|
int start = end;
|
||||||
if (copy > len)
|
|
||||||
copy = len;
|
|
||||||
if (memcpy_toiovec(to, skb->data + offset, copy))
|
|
||||||
goto fault;
|
|
||||||
if ((len -= copy) == 0)
|
|
||||||
return 0;
|
|
||||||
offset += copy;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Copy paged appendix. Hmm... why does this look so complicated? */
|
if ((end += fraglen) > offset) {
|
||||||
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
|
int copy = end - offset, o = offset - start;
|
||||||
int end;
|
|
||||||
|
|
||||||
BUG_TRAP(start <= offset + len);
|
|
||||||
|
|
||||||
end = start + skb_shinfo(skb)->frags[i].size;
|
|
||||||
if ((copy = end - offset) > 0) {
|
|
||||||
int err;
|
|
||||||
u8 *vaddr;
|
|
||||||
skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
|
|
||||||
struct page *page = frag->page;
|
|
||||||
|
|
||||||
if (copy > len)
|
if (copy > len)
|
||||||
copy = len;
|
copy = len;
|
||||||
vaddr = kmap(page);
|
if (i == -1)
|
||||||
err = memcpy_toiovec(to, vaddr + frag->page_offset +
|
err = memcpy_toiovec(to, skb->data + o, copy);
|
||||||
offset - start, copy);
|
else {
|
||||||
kunmap(page);
|
skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
|
||||||
|
struct page *page = frag->page;
|
||||||
|
void *p = kmap(page) + frag->page_offset + o;
|
||||||
|
err = memcpy_toiovec(to, p, copy);
|
||||||
|
kunmap(page);
|
||||||
|
}
|
||||||
if (err)
|
if (err)
|
||||||
goto fault;
|
goto fault;
|
||||||
if (!(len -= copy))
|
if (!(len -= copy))
|
||||||
return 0;
|
return 0;
|
||||||
offset += copy;
|
offset += copy;
|
||||||
}
|
}
|
||||||
start = end;
|
if (++i >= skb_shinfo(skb)->nr_frags)
|
||||||
|
break;
|
||||||
|
fraglen = skb_shinfo(skb)->frags[i].size;
|
||||||
}
|
}
|
||||||
|
if (next) {
|
||||||
if (skb_shinfo(skb)->frag_list) {
|
skb = next;
|
||||||
struct sk_buff *list = skb_shinfo(skb)->frag_list;
|
BUG_ON(skb_shinfo(skb)->frag_list);
|
||||||
|
next = skb->next;
|
||||||
for (; list; list = list->next) {
|
goto next_skb;
|
||||||
int end;
|
|
||||||
|
|
||||||
BUG_TRAP(start <= offset + len);
|
|
||||||
|
|
||||||
end = start + list->len;
|
|
||||||
if ((copy = end - offset) > 0) {
|
|
||||||
if (copy > len)
|
|
||||||
copy = len;
|
|
||||||
if (skb_copy_datagram_iovec(list,
|
|
||||||
offset - start,
|
|
||||||
to, copy))
|
|
||||||
goto fault;
|
|
||||||
if ((len -= copy) == 0)
|
|
||||||
return 0;
|
|
||||||
offset += copy;
|
|
||||||
}
|
|
||||||
start = end;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!len)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
fault:
|
fault:
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue