From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59733) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yj1Bv-0005qv-Gp for qemu-devel@nongnu.org; Fri, 17 Apr 2015 04:00:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yj1Bu-00018Y-JZ for qemu-devel@nongnu.org; Fri, 17 Apr 2015 03:59:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50312) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yj1Bu-00017c-BM for qemu-devel@nongnu.org; Fri, 17 Apr 2015 03:59:58 -0400 From: Fam Zheng Date: Fri, 17 Apr 2015 15:59:18 +0800 Message-Id: <1429257573-7359-4-git-send-email-famz@redhat.com> In-Reply-To: <1429257573-7359-1-git-send-email-famz@redhat.com> References: <1429257573-7359-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH 03/18] virtio: Return error from virtqueue_get_head List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , "Michael S. Tsirkin" , "Aneesh Kumar K.V" , Stefan Hajnoczi , Amit Shah , Paolo Bonzini Return type is changed to int. When data is invalid, return -EINVAL with an error. Signed-off-by: Fam Zheng --- hw/virtio/virtio.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index b02c7a1..a525f8e 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -311,9 +311,10 @@ static int virtqueue_num_heads(VirtQueue *vq, unsigned int idx, Error **errp) return num_heads; } -static unsigned int virtqueue_get_head(VirtQueue *vq, unsigned int idx) +static int virtqueue_get_head(VirtQueue *vq, unsigned int idx, + Error **errp) { - unsigned int head; + int head; /* Grab the next descriptor number they're advertising, and increment * the index we've seen. */ @@ -321,8 +322,8 @@ static unsigned int virtqueue_get_head(VirtQueue *vq, unsigned int idx) /* If their number is silly, that's a fatal mistake. */ if (head >= vq->vring.num) { - error_report("Guest says index %u is available", head); - exit(1); + error_setg(errp, "Guest says index %u is available", head); + return -EINVAL; } return head; @@ -369,7 +370,7 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes, max = vq->vring.num; num_bufs = total_bufs; - i = virtqueue_get_head(vq, idx++); + i = virtqueue_get_head(vq, idx++, &error_abort); desc_pa = vq->vring.desc; if (vring_desc_flags(vdev, desc_pa, i) & VRING_DESC_F_INDIRECT) { @@ -474,7 +475,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem) max = vq->vring.num; - i = head = virtqueue_get_head(vq, vq->last_avail_idx++); + i = head = virtqueue_get_head(vq, vq->last_avail_idx++, &error_abort); if (virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) { vring_set_avail_event(vq, vq->last_avail_idx); } -- 1.9.3