From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60546) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZlgE3-0002nM-HZ for qemu-devel@nongnu.org; Mon, 12 Oct 2015 12:45:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZlgE2-0001ol-Ma for qemu-devel@nongnu.org; Mon, 12 Oct 2015 12:45:27 -0400 Received: from mail-pa0-x22c.google.com ([2607:f8b0:400e:c03::22c]:35029) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZlgE2-0001oe-HY for qemu-devel@nongnu.org; Mon, 12 Oct 2015 12:45:26 -0400 Received: by pabve7 with SMTP id ve7so100501464pab.2 for ; Mon, 12 Oct 2015 09:45:26 -0700 (PDT) Sender: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= From: marcandre.lureau@redhat.com Date: Mon, 12 Oct 2015 18:41:08 +0200 Message-Id: <1444668104-22955-15-git-send-email-marcandre.lureau@redhat.com> In-Reply-To: <1444668104-22955-1-git-send-email-marcandre.lureau@redhat.com> References: <1444668104-22955-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PULL v2 14/50] ivshmem: allocate eventfds in resize_peers() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, drjones@redhat.com, claudio.fontana@huawei.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, cam@cs.ualberta.ca From: Marc-André Lureau It simplifies a bit the code to allocate the array when setting the number of peers instead of lazily when receiving the first vector. Signed-off-by: Marc-André Lureau Reviewed-by: Claudio Fontana --- hw/misc/ivshmem.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index 6f41960..19640bb 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -437,9 +437,8 @@ static int resize_peers(IVShmemState *s, int new_min_size) s->peers = g_realloc(s->peers, s->nb_peers * sizeof(Peer)); - /* zero out new pointers */ for (j = old_size; j < s->nb_peers; j++) { - s->peers[j].eventfds = NULL; + s->peers[j].eventfds = g_new0(EventNotifier, s->vectors); s->peers[j].nb_eventfds = 0; } @@ -517,8 +516,7 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size) if (incoming_fd == -1) { /* if posn is positive and unseen before then this is our posn*/ - if ((incoming_posn >= 0) && - (s->peers[incoming_posn].eventfds == NULL)) { + if (incoming_posn >= 0 && s->vm_id == -1) { /* receive our posn */ s->vm_id = incoming_posn; return; @@ -569,11 +567,6 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size) * guests for each VM */ guest_max_eventfd = s->peers[incoming_posn].nb_eventfds; - if (guest_max_eventfd == 0) { - /* one eventfd per MSI vector */ - s->peers[incoming_posn].eventfds = g_new(EventNotifier, s->vectors); - } - /* this is an eventfd for a particular guest VM */ IVSHMEM_DPRINTF("eventfds[%ld][%d] = %d\n", incoming_posn, guest_max_eventfd, incoming_fd); -- 2.4.3