Skip to content

Commit

Permalink
virtio: Fix typecast of pointer in vring_init()
Browse files Browse the repository at this point in the history
The virtio_ring.h header is used in userspace programs (ie. QEMU),
too. Here we can not assume that sizeof(pointer) is the same as
sizeof(long), e.g. when compiling for Windows, so the typecast in
vring_init() should be done with (uintptr_t) instead of (unsigned long).

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
  • Loading branch information
Thomas Huth authored and Michael S. Tsirkin committed Jul 7, 2015
1 parent 908a554 commit d768f32
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion include/uapi/linux/virtio_ring.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
* SUCH DAMAGE.
*
* Copyright Rusty Russell IBM Corporation 2007. */
#ifndef __KERNEL__
#include <stdint.h>
#endif
#include <linux/types.h>
#include <linux/virtio_types.h>

Expand Down Expand Up @@ -143,7 +146,7 @@ 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(__virtio16)
vr->used = (void *)(((uintptr_t)&vr->avail->ring[num] + sizeof(__virtio16)
+ align-1) & ~(align - 1));
}

Expand Down

0 comments on commit d768f32

Please sign in to comment.