Message ID | 1460467534-29147-8-git-send-email-stefanha@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Tue, 12 Apr 2016 14:25:31 +0100 Stefan Hajnoczi <stefanha@redhat.com> wrote: > The virtio code uses int, unsigned int, and uint16_t for virtqueue > indices. The uint16_t is used for the low-level descriptor layout in > virtio_ring.h while code that isn't concerned with descriptor layout can > use unsigned int. > > Use of int is problematic because it can result in signed/unsigned > comparison and incompatible int*/unsigned int* pointer types. > > Make the virtqueue_get_avail_bytes() 'i' variable unsigned int. This > eliminates the need to introduce casts and modify code further in the > patches that follow. > > Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> > --- > hw/virtio/virtio.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 48f759e..493d6a7 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -392,7 +392,7 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes, unsigned int max, num_bufs, indirect = 0; VRingDesc desc; hwaddr desc_pa; - int i; + unsigned int i; max = vq->vring.num; num_bufs = total_bufs;
The virtio code uses int, unsigned int, and uint16_t for virtqueue indices. The uint16_t is used for the low-level descriptor layout in virtio_ring.h while code that isn't concerned with descriptor layout can use unsigned int. Use of int is problematic because it can result in signed/unsigned comparison and incompatible int*/unsigned int* pointer types. Make the virtqueue_get_avail_bytes() 'i' variable unsigned int. This eliminates the need to introduce casts and modify code further in the patches that follow. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> --- hw/virtio/virtio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)