net: use skb_copy_datagram_from_iovec() in zerocopy_sg_from_iovec()
Use skb_copy_datagram_from_iovec() to avoid code duplication and make it easy to be read. Also we can do the skipping inside the zero-copy loop. Signed-off-by: Jason Wang <jasowang@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
0433547aa7
commit
3d9953a2ef
|
@ -591,48 +591,31 @@ int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
|
||||||
int offset, size_t count)
|
int offset, size_t count)
|
||||||
{
|
{
|
||||||
int len = iov_length(from, count) - offset;
|
int len = iov_length(from, count) - offset;
|
||||||
int copy = skb_headlen(skb);
|
int copy = min_t(int, skb_headlen(skb), len);
|
||||||
int size, offset1 = 0;
|
int size;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
/* Skip over from offset */
|
|
||||||
while (count && (offset >= from->iov_len)) {
|
|
||||||
offset -= from->iov_len;
|
|
||||||
++from;
|
|
||||||
--count;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* copy up to skb headlen */
|
/* copy up to skb headlen */
|
||||||
while (count && (copy > 0)) {
|
if (skb_copy_datagram_from_iovec(skb, 0, from, offset, copy))
|
||||||
size = min_t(unsigned int, copy, from->iov_len - offset);
|
return -EFAULT;
|
||||||
if (copy_from_user(skb->data + offset1, from->iov_base + offset,
|
|
||||||
size))
|
|
||||||
return -EFAULT;
|
|
||||||
if (copy > size) {
|
|
||||||
++from;
|
|
||||||
--count;
|
|
||||||
offset = 0;
|
|
||||||
} else
|
|
||||||
offset += size;
|
|
||||||
copy -= size;
|
|
||||||
offset1 += size;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (len == offset1)
|
if (len == copy)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
offset += copy;
|
||||||
while (count--) {
|
while (count--) {
|
||||||
struct page *page[MAX_SKB_FRAGS];
|
struct page *page[MAX_SKB_FRAGS];
|
||||||
int num_pages;
|
int num_pages;
|
||||||
unsigned long base;
|
unsigned long base;
|
||||||
unsigned long truesize;
|
unsigned long truesize;
|
||||||
|
|
||||||
len = from->iov_len - offset;
|
/* Skip over from offset and copied */
|
||||||
if (!len) {
|
if (offset >= from->iov_len) {
|
||||||
offset = 0;
|
offset -= from->iov_len;
|
||||||
++from;
|
++from;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
len = from->iov_len - offset;
|
||||||
base = (unsigned long)from->iov_base + offset;
|
base = (unsigned long)from->iov_base + offset;
|
||||||
size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT;
|
size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT;
|
||||||
if (i + size > MAX_SKB_FRAGS)
|
if (i + size > MAX_SKB_FRAGS)
|
||||||
|
|
Loading…
Reference in New Issue