From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44181) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTosL-0000S1-7L for qemu-devel@nongnu.org; Fri, 06 Mar 2015 04:48:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YTosH-0003yt-8E for qemu-devel@nongnu.org; Fri, 06 Mar 2015 04:48:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35153) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTosG-0003yi-VH for qemu-devel@nongnu.org; Fri, 06 Mar 2015 04:48:53 -0500 Date: Fri, 06 Mar 2015 10:49:04 +0800 From: Jason Wang Message-Id: <1425610144.6400.0@smtp.corp.redhat.com> In-Reply-To: <20150305061231.GB2645@ad.nay.redhat.com> References: <1425534531-6305-1-git-send-email-jasowang@redhat.com> <1425534531-6305-11-git-send-email-jasowang@redhat.com> <20150305061231.GB2645@ad.nay.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Subject: Re: [Qemu-devel] [PATCH V3 10/14] virtio: introduce virtio_queue_get_index() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: qemu-devel@nongnu.org, Anthony Liguori , "Michael S. Tsirkin" On Thu, Mar 5, 2015 at 2:12 PM, Fam Zheng wrote: > On Thu, 03/05 13:48, Jason Wang wrote: >> This patch introduces a helper that can get the queue index of a >> VirtQueue. This is useful when traversing the list of VirtQueues. >> >> Cc: Anthony Liguori >> Cc: Michael S. Tsirkin >> Signed-off-by: Jason Wang >> --- >> hw/virtio/virtio.c | 5 +++++ >> include/hw/virtio/virtio.h | 1 + >> 2 files changed, 6 insertions(+) >> >> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c >> index 5e6b879..bd32518 100644 >> --- a/hw/virtio/virtio.c >> +++ b/hw/virtio/virtio.c >> @@ -725,6 +725,11 @@ hwaddr virtio_queue_get_addr(VirtIODevice >> *vdev, int n) >> return vdev->vq[n].pa; >> } >> >> +int virtio_queue_get_index(VirtIODevice *vdev, VirtQueue *vq) >> +{ >> + return vq - vdev->vq; > > Probably assert the return value is within [0, > virtio_get_queue_max(vdev))? > > Fam Not sure this is necessary. If we add one such here, we probably needs to add more elsewhere.