]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
virtio: fix oops on OOM
authorMichael S. Tsirkin <mst@redhat.com>
Mon, 26 Jul 2010 07:25:30 +0000 (16:55 +0930)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 2 Aug 2010 17:29:51 +0000 (10:29 -0700)
commit 1fe9b6fef11771461e69ecd1bc8935a1c7c90cb5 upstream.

virtio ring was changed to return an error code on OOM,
but one caller was missed and still checks for vq->vring.num.
The fix is just to check for <0 error code.

Long term it might make sense to change goto add_head to
just return an error on oom instead, but let's apply
a minimal fix for 2.6.35.

Reported-by: Chris Mason <chris.mason@oracle.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Tested-by: Chris Mason <chris.mason@oracle.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/virtio/virtio_ring.c

index 6007eba04013bf592db7788b29be352590cf88f6..dd4370b45763dd75747adc93260e05bfc6e507f5 100644 (file)
@@ -162,7 +162,8 @@ static int vring_add_buf(struct virtqueue *_vq,
                         void *data)
 {
        struct vring_virtqueue *vq = to_vvq(_vq);
-       unsigned int i, avail, head, uninitialized_var(prev);
+       unsigned int i, avail, uninitialized_var(prev);
+       int head;
 
        START_USE(vq);
 
@@ -172,7 +173,7 @@ static int vring_add_buf(struct virtqueue *_vq,
         * buffers, then go indirect. FIXME: tune this threshold */
        if (vq->indirect && (out + in) > 1 && vq->num_free) {
                head = vring_add_indirect(vq, sg, out, in);
-               if (head != vq->vring.num)
+               if (likely(head >= 0))
                        goto add_head;
        }