Skip to contentSkip to conversation

virtio: Fix wrong type cast from pointer to long

PATCH Applied Stefan Weil 5 participants 6 messages Sep 24, 2014 – Sep 25, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio: Fix wrong type cast from pointer to long

Compiler warning (w32, w64):

include/hw/virtio/virtio_ring.h:142:26: warning:
cast from pointer to integer of different size [-Wpointer-to-int-cast]

When sizeof(long) < sizeof(void *), this is not only a warning but a real program error.

Add also missing blanks in the same statement.

---

Peter, could you please apply this bug fix directly without pull request?

Thanks
Stefan

 include/hw/virtio/virtio_ring.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/hw/virtio/virtio_ring.h +2 -2
index 8f58bc9..0b42e6e 100644
@@ -139,8 +139,8 @@ static inline void vring_init(struct vring *vr, unsigned int num, void *p,
     vr->num = num;
     vr->desc = p;
     vr->avail = p + num*sizeof(struct vring_desc);
-    vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + sizeof(uint16_t)
-        + align-1) & ~(align - 1));
+    vr->used = (void *)(((uintptr_t)&vr->avail->ring[num] + sizeof(uint16_t)
+        + align - 1) & ~(align - 1));
 }
 
 static inline unsigned vring_size(unsigned int num, unsigned long align)
Signature · 1 line
1.7.10.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Stefan Weil

Compiler warning (w32, w64):

include/hw/virtio/virtio_ring.h:142:26: warning:
cast from pointer to integer of different size [-Wpointer-to-int-cast]

When sizeof(long) < sizeof(void *), this is not only a warning but a real program error.

Add also missing blanks in the same statement.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Stefan Weil
Quoted 39 lines · Stefan Weil

Compiler warning (w32, w64):

include/hw/virtio/virtio_ring.h:142:26: warning:
cast from pointer to integer of different size [-Wpointer-to-int-cast]

When sizeof(long) < sizeof(void *), this is not only a warning but a real program error.

Add also missing blanks in the same statement.

---

Peter, could you please apply this bug fix directly without pull request?

Thanks
Stefan

 include/hw/virtio/virtio_ring.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/hw/virtio/virtio_ring.h +2 -2
index 8f58bc9..0b42e6e 100644
@@ -139,8 +139,8 @@ static inline void vring_init(struct vring *vr, unsigned int num, void *p,
     vr->num = num;
     vr->desc = p;
     vr->avail = p + num*sizeof(struct vring_desc);
-    vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + sizeof(uint16_t)
-        + align-1) & ~(align - 1));
+    vr->used = (void *)(((uintptr_t)&vr->avail->ring[num] + sizeof(uint16_t)
+        + align - 1) & ~(align - 1));
 }
 
 static inline unsigned vring_size(unsigned int num, unsigned long align)
Signature · 1 line
1.7.10.4

That was from copy&paste /usr/include/linux/virtio_ring.h. The patch looks good to me, should linux also need this fix?

Fam

#3 lore raw
Quoted 9 lines · Fam Zheng
Quoted 8 lines · Stefan Weil

Compiler warning (w32, w64):

include/hw/virtio/virtio_ring.h:142:26: warning:
cast from pointer to integer of different size [-Wpointer-to-int-cast]

When sizeof(long) < sizeof(void *), this is not only a warning but a real program error.

Quoted 6 lines
Quoted 6 lines

Add also missing blanks in the same statement.

---

Peter, could you please apply this bug fix directly without pull request?

Applied to master, thanks.

Quoted 14 lines
Quoted 14 lines
include/hw/virtio/virtio_ring.h +2 -2
index 8f58bc9..0b42e6e 100644
@@ -139,8 +139,8 @@ static inline void vring_init(struct vring *vr, unsigned int num, void *p,
     vr->num = num;
     vr->desc = p;
     vr->avail = p + num*sizeof(struct vring_desc);
-    vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + sizeof(uint16_t)
-        + align-1) & ~(align - 1));
+    vr->used = (void *)(((uintptr_t)&vr->avail->ring[num] + sizeof(uint16_t)
+        + align - 1) & ~(align - 1));
 }
 
Quoted 7 lines
Quoted 4 lines
include/hw/virtio/virtio_ring.h +0 -1
 static inline unsigned vring_size(unsigned int num, unsigned long align)
--

1.7.10.4

That was from copy&paste /usr/include/linux/virtio_ring.h. The patch looks good to me, should linux also need this fix?

In Linux the "long" type is always the same as the size of a pointer; it's only Windows that went for the LLP64 model rather than LP64.

thanks
-- PMM

#4 lore raw
Quoted 41 lines · Peter Maydell
Quoted 9 lines · Fam Zheng
Quoted 8 lines · Stefan Weil

Compiler warning (w32, w64):

include/hw/virtio/virtio_ring.h:142:26: warning:
cast from pointer to integer of different size [-Wpointer-to-int-cast]

When sizeof(long) < sizeof(void *), this is not only a warning but a real program error.

Quoted 6 lines
Quoted 6 lines

Add also missing blanks in the same statement.

---

Peter, could you please apply this bug fix directly without pull request?

Applied to master, thanks.

Quoted 14 lines
Quoted 14 lines
include/hw/virtio/virtio_ring.h +2 -2
index 8f58bc9..0b42e6e 100644
@@ -139,8 +139,8 @@ static inline void vring_init(struct vring *vr, unsigned int num, void *p,
     vr->num = num;
     vr->desc = p;
     vr->avail = p + num*sizeof(struct vring_desc);
-    vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + sizeof(uint16_t)
-        + align-1) & ~(align - 1));
+    vr->used = (void *)(((uintptr_t)&vr->avail->ring[num] + sizeof(uint16_t)
+        + align - 1) & ~(align - 1));
 }
 
Quoted 7 lines
Quoted 4 lines
include/hw/virtio/virtio_ring.h +0 -1
 static inline unsigned vring_size(unsigned int num, unsigned long align)
--

1.7.10.4

That was from copy&paste /usr/include/linux/virtio_ring.h. The patch looks good to me, should linux also need this fix?

Quoted 3 lines

In Linux the "long" type is always the same as the size of a pointer; it's only Windows that went for the LLP64 model rather than LP64.

Okay, Thanks for explaining!

Fam

Reviewed-by on v1 1/1
#5 lore raw
In reply to Stefan Weil
Quoted 13 lines · Stefan Weil

Compiler warning (w32, w64):

include/hw/virtio/virtio_ring.h:142:26: warning:
cast from pointer to integer of different size [-Wpointer-to-int-cast]

When sizeof(long) < sizeof(void *), this is not only a warning but a real program error.

Add also missing blanks in the same statement.

---

Quoted 7 lines

Peter, could you please apply this bug fix directly without pull request?

Thanks
Stefan

 include/hw/virtio/virtio_ring.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)