virtio: Fix wrong type cast from pointer to long
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
@@ -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
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.
Signed-off-by Stefan Weil <[email protected]>
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.
Signed-off-by Stefan Weil <[email protected]>---
Peter, could you please apply this bug fix directly without pull request?
Thanks
Stefaninclude/hw/virtio/virtio_ring.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)include/hw/virtio/virtio_ring.h +2
-2@@ -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
Peter Maydell
AppliedQuoted 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.
Signed-off-by Stefan Weil <[email protected]>---
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@@ -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
-1static 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
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.
Signed-off-by Stefan Weil <[email protected]>---
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@@ -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
-1static 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
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.
Signed-off-by Stefan Weil <[email protected]>---
Quoted 7 lines
Peter, could you please apply this bug fix directly without pull request?
Thanks
Stefaninclude/hw/virtio/virtio_ring.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)