virtio: Initialize vq->data entries to NULL
Amit Shah [Fri, 12 Feb 2010 05:02:14 +0000 (10:02 +0530)]
vq operations depend on vq->data[i] being NULL to figure out if the vq
entry is in use (since the previous patch).

We have to initialize them to NULL to ensure we don't work with junk
data and trigger false BUG_ONs.

Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Cc: Shirley Ma <xma@us.ibm.com>

drivers/virtio/virtio_ring.c

index 782b729..0db906b 100644 (file)
@@ -448,8 +448,11 @@ struct virtqueue *vring_new_virtqueue(unsigned int num,
        /* Put everything in free lists. */
        vq->num_free = num;
        vq->free_head = 0;
-       for (i = 0; i < num-1; i++)
+       for (i = 0; i < num-1; i++) {
                vq->vring.desc[i].next = i+1;
+               vq->data[i] = NULL;
+       }
+       vq->data[i] = NULL;
 
        return &vq->vq;
 }