Skip to content

Commit 1fe9b6f

Browse files
mstsirkintorvalds
authored andcommitted
virtio: fix oops on OOM
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]>
1 parent 2e65a20 commit 1fe9b6f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/virtio/virtio_ring.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ int virtqueue_add_buf_gfp(struct virtqueue *_vq,
164164
gfp_t gfp)
165165
{
166166
struct vring_virtqueue *vq = to_vvq(_vq);
167-
unsigned int i, avail, head, uninitialized_var(prev);
167+
unsigned int i, avail, uninitialized_var(prev);
168+
int head;
168169

169170
START_USE(vq);
170171

@@ -174,7 +175,7 @@ int virtqueue_add_buf_gfp(struct virtqueue *_vq,
174175
* buffers, then go indirect. FIXME: tune this threshold */
175176
if (vq->indirect && (out + in) > 1 && vq->num_free) {
176177
head = vring_add_indirect(vq, sg, out, in, gfp);
177-
if (head != vq->vring.num)
178+
if (likely(head >= 0))
178179
goto add_head;
179180
}
180181

0 commit comments

Comments
 (0)