Patchwork [07/14] virtio-net: first s/g is always at start of buf

login
register
mail settings
Submitter Michael S. Tsirkin
Date Sept. 24, 2012, 11:04 p.m.
Message ID <0a5b42d30237d61a9c1d14c599ddd62f7b98db3d.1348527749.git.mst@redhat.com>
Download mbox | patch
Permalink /patch/186606/
State New
Headers show

Comments

Michael S. Tsirkin - Sept. 24, 2012, 11:04 p.m.
We know offset is 0, assert that.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/virtio-net.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Anthony Liguori - Sept. 25, 2012, 12:39 a.m.
"Michael S. Tsirkin" <mst@redhat.com> writes:

> We know offset is 0, assert that.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>

Regards,

Anthony Liguori

> ---
>  hw/virtio-net.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/hw/virtio-net.c b/hw/virtio-net.c
> index 3a0d1a7..6e6f5f3 100644
> --- a/hw/virtio-net.c
> +++ b/hw/virtio-net.c
> @@ -630,6 +630,7 @@ static ssize_t virtio_net_receive(NetClientState *nc, const uint8_t *buf, size_t
>          }
>  
>          if (i == 0) {
> +            assert(offset == 0);
>              if (n->mergeable_rx_bufs) {
>                  mhdr_cnt = iov_cpy(mhdr_sg, ARRAY_SIZE(mhdr_sg),
>                                     sg, elem.in_num,
> @@ -637,8 +638,8 @@ static ssize_t virtio_net_receive(NetClientState *nc, const uint8_t *buf, size_t
>                                     sizeof(mhdr.num_buffers));
>              }
>  
> -            receive_header(n, sg, elem.in_num, buf + offset, size - offset);
> -            offset += n->host_hdr_len;
> +            receive_header(n, sg, elem.in_num, buf, size);
> +            offset = n->host_hdr_len;
>              total += n->guest_hdr_len;
>              guest_offset = n->guest_hdr_len;
>          } else {
> -- 
> MST

Patch

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 3a0d1a7..6e6f5f3 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -630,6 +630,7 @@  static ssize_t virtio_net_receive(NetClientState *nc, const uint8_t *buf, size_t
         }
 
         if (i == 0) {
+            assert(offset == 0);
             if (n->mergeable_rx_bufs) {
                 mhdr_cnt = iov_cpy(mhdr_sg, ARRAY_SIZE(mhdr_sg),
                                    sg, elem.in_num,
@@ -637,8 +638,8 @@  static ssize_t virtio_net_receive(NetClientState *nc, const uint8_t *buf, size_t
                                    sizeof(mhdr.num_buffers));
             }
 
-            receive_header(n, sg, elem.in_num, buf + offset, size - offset);
-            offset += n->host_hdr_len;
+            receive_header(n, sg, elem.in_num, buf, size);
+            offset = n->host_hdr_len;
             total += n->guest_hdr_len;
             guest_offset = n->guest_hdr_len;
         } else {