Skip to content

Commit

Permalink
virtio: fix oops on OOM
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Rusty Russell <[email protected]>
Tested-by: Chris Mason <[email protected]>
Cc: [email protected] # .34.x
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
mstsirkin authored and torvalds committed Jul 26, 2010
1 parent 2e65a20 commit 1fe9b6f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/virtio/virtio_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ int virtqueue_add_buf_gfp(struct virtqueue *_vq,
gfp_t gfp)
{
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);

Expand All @@ -174,7 +175,7 @@ int virtqueue_add_buf_gfp(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, gfp);
if (head != vq->vring.num)
if (likely(head >= 0))
goto add_head;
}

Expand Down

0 comments on commit 1fe9b6f

Please sign in to comment.