Patchwork [4/6] Endian fixes for virtfs

login
register
mail settings
Submitter David Gibson
Date Feb. 24, 2012, 12:23 a.m.
Message ID <1330043012-30556-5-git-send-email-david@gibson.dropbear.id.au>
Download mbox | patch
Permalink /patch/142734/
State New
Headers show

Comments

David Gibson - Feb. 24, 2012, 12:23 a.m.
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>

This patch fixes several endian bugs in virtfs.

Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 hw/9pfs/virtio-9p.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
Aneesh Kumar K.V - Feb. 24, 2012, 8:29 a.m.
On Fri, 24 Feb 2012 11:23:30 +1100, David Gibson <david@gibson.dropbear.id.au> wrote:
> From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> 
> This patch fixes several endian bugs in virtfs.
> 
> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
> 
> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> ---
>  hw/9pfs/virtio-9p.c |    8 +++++---
>  1 files changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
> index a72ffc3..c633fb9 100644
> --- a/hw/9pfs/virtio-9p.c
> +++ b/hw/9pfs/virtio-9p.c
> @@ -1349,7 +1349,9 @@ static void v9fs_open(void *opaque)
>      if (s->proto_version == V9FS_PROTO_2000L) {
>          err = pdu_unmarshal(pdu, offset, "dd", &fid, &mode);
>      } else {
> -        err = pdu_unmarshal(pdu, offset, "db", &fid, &mode);
> +        uint8_t modebyte;
> +        err = pdu_unmarshal(pdu, offset, "db", &fid, &modebyte);
> +        mode = modebyte;
>      }
>      if (err < 0) {
>          goto out_nofid;
> @@ -3260,9 +3262,9 @@ void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq)
> 
>          ptr = pdu->elem.out_sg[0].iov_base;
> 
> -        memcpy(&pdu->size, ptr, 4);
> +        pdu->size = le32_to_cpu(*(uint32_t *)ptr);
>          pdu->id = ptr[4];
> -        memcpy(&pdu->tag, ptr + 5, 2);
> +        pdu->tag = le16_to_cpu(*(uint16_t *)(ptr + 5));
>          qemu_co_queue_init(&pdu->complete);
>          submit_pdu(s, pdu);
>      }

Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>

-aneesh

Patch

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index a72ffc3..c633fb9 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -1349,7 +1349,9 @@  static void v9fs_open(void *opaque)
     if (s->proto_version == V9FS_PROTO_2000L) {
         err = pdu_unmarshal(pdu, offset, "dd", &fid, &mode);
     } else {
-        err = pdu_unmarshal(pdu, offset, "db", &fid, &mode);
+        uint8_t modebyte;
+        err = pdu_unmarshal(pdu, offset, "db", &fid, &modebyte);
+        mode = modebyte;
     }
     if (err < 0) {
         goto out_nofid;
@@ -3260,9 +3262,9 @@  void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq)
 
         ptr = pdu->elem.out_sg[0].iov_base;
 
-        memcpy(&pdu->size, ptr, 4);
+        pdu->size = le32_to_cpu(*(uint32_t *)ptr);
         pdu->id = ptr[4];
-        memcpy(&pdu->tag, ptr + 5, 2);
+        pdu->tag = le16_to_cpu(*(uint16_t *)(ptr + 5));
         qemu_co_queue_init(&pdu->complete);
         submit_pdu(s, pdu);
     }