Skip to content

Commit

Permalink
macvtap: zerocopy: fix offset calculation when building skb
Browse files Browse the repository at this point in the history
This patch fixes the offset calculation when building skb:

- offset1 were used as skb data offset not vector offset
- reset offset to zero only when we advance to next vector

Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
  • Loading branch information
Jason Wang authored and Michael S. Tsirkin committed May 2, 2012
1 parent 64d0988 commit 3afc962
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions drivers/net/macvtap.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,11 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
if (copy > size) {
++from;
--count;
}
offset = 0;
} else
offset += size;
copy -= size;
offset1 += size;
offset = 0;
}

if (len == offset1)
Expand All @@ -519,13 +520,13 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
int num_pages;
unsigned long base;

len = from->iov_len - offset1;
len = from->iov_len - offset;
if (!len) {
offset1 = 0;
offset = 0;
++from;
continue;
}
base = (unsigned long)from->iov_base + offset1;
base = (unsigned long)from->iov_base + offset;
size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT;
num_pages = get_user_pages_fast(base, size, 0, &page[i]);
if ((num_pages != size) ||
Expand All @@ -546,7 +547,7 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
len -= size;
i++;
}
offset1 = 0;
offset = 0;
++from;
}
return 0;
Expand Down

0 comments on commit 3afc962

Please sign in to comment.