From patchwork Tue Oct 6 19:19:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 527022 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2A4F11402A2 for ; Wed, 7 Oct 2015 09:00:54 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=RC+dYxay; dkim-atps=neutral Received: from localhost ([::1]:54273 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZjaHz-0002Cw-V5 for incoming@patchwork.ozlabs.org; Tue, 06 Oct 2015 18:00:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38597) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZjaHO-0001s0-Bq for qemu-devel@nongnu.org; Tue, 06 Oct 2015 18:00:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZjXnL-0004gT-19 for qemu-devel@nongnu.org; Tue, 06 Oct 2015 15:21:28 -0400 Received: from mail-qk0-x22a.google.com ([2607:f8b0:400d:c09::22a]:35536) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZjXnK-0004dT-Fx for qemu-devel@nongnu.org; Tue, 06 Oct 2015 15:21:02 -0400 Received: by qkap81 with SMTP id p81so90682791qka.2 for ; Tue, 06 Oct 2015 12:21:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=nJ6z4PbdZklO/LQn3zjxurb32O0AqVWOstWDFL6TRK0=; b=RC+dYxay7ZFGMmVWeSnc9prTE2+tOK0lZSDPScn6wlT9c3i0gZ3ixxw5JTeqFj8KCF R1sg4oSX4nJRQnSLFPqyeQ7zT/8LB6aF9ekPUOtoZ9tsiihJVejaQV9odYlXj0GuXJ58 jTu9tkB6nL4AXBXe4nmO0U8lstVks9SZ1+4yqKvXKEv5z2HqE3IOG/mxFbshBE22yo9x tLE8nAwsNYZBmkujo43dPGQT5w1qexMu3yDKrgrn6GAKfKtGHl+xyOioC/T2SvEutq6R hN+TUSBAtGrzkAOBmP1wxWFCVy/2jN+gg5BBx/NLenjVxDaJ0pALfWQbJ29Voiefw7Aj 9HTg== X-Received: by 10.55.18.82 with SMTP id c79mr20570867qkh.76.1444159262029; Tue, 06 Oct 2015 12:21:02 -0700 (PDT) Received: from localhost (bne75-h02-31-39-163-232.dsl.sta.abo.bbox.fr. [31.39.163.232]) by smtp.gmail.com with ESMTPSA id l91sm309966qkh.46.2015.10.06.12.21.00 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Oct 2015 12:21:01 -0700 (PDT) From: marcandre.lureau@redhat.com To: peter.maydell@linaro.org Date: Tue, 6 Oct 2015 21:19:16 +0200 Message-Id: <1444159184-18153-21-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1444159184-18153-1-git-send-email-marcandre.lureau@redhat.com> References: <1444159184-18153-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c09::22a Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , qemu-devel@nongnu.org Subject: [Qemu-devel] [PULL 20/48] ivshmem: simplify a bit the code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Marc-André Lureau Use some more explicit variables to simplify the code. Signed-off-by: Marc-André Lureau Reviewed-by: Claudio Fontana --- hw/misc/ivshmem.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index 6ee4881..c054e52 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -488,9 +488,10 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size) { IVShmemState *s = opaque; int incoming_fd; - int guest_max_eventfd; + int new_eventfd; long incoming_posn; Error *err = NULL; + Peer *peer; if (!fifo_update_and_get(s, buf, size, &incoming_posn, sizeof(incoming_posn))) { @@ -517,6 +518,8 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size) } } + peer = &s->peers[incoming_posn]; + if (incoming_fd == -1) { /* if posn is positive and unseen before then this is our posn*/ if (incoming_posn >= 0 && s->vm_id == -1) { @@ -564,27 +567,24 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size) return; } - /* each guest has an array of eventfds, and we keep track of how many - * guests for each VM */ - guest_max_eventfd = s->peers[incoming_posn].nb_eventfds; + /* each peer has an associated array of eventfds, and we keep + * track of how many eventfds received so far */ + /* get a new eventfd: */ + new_eventfd = peer->nb_eventfds++; /* this is an eventfd for a particular guest VM */ IVSHMEM_DPRINTF("eventfds[%ld][%d] = %d\n", incoming_posn, - guest_max_eventfd, incoming_fd); - event_notifier_init_fd(&s->peers[incoming_posn].eventfds[guest_max_eventfd], - incoming_fd); - - /* increment count for particular guest */ - s->peers[incoming_posn].nb_eventfds++; + new_eventfd, incoming_fd); + event_notifier_init_fd(&peer->eventfds[new_eventfd], incoming_fd); if (incoming_posn == s->vm_id) { - s->eventfd_chr[guest_max_eventfd] = create_eventfd_chr_device(s, - &s->peers[s->vm_id].eventfds[guest_max_eventfd], - guest_max_eventfd); + s->eventfd_chr[new_eventfd] = create_eventfd_chr_device(s, + &s->peers[s->vm_id].eventfds[new_eventfd], + new_eventfd); } if (ivshmem_has_feature(s, IVSHMEM_IOEVENTFD)) { - ivshmem_add_eventfd(s, incoming_posn, guest_max_eventfd); + ivshmem_add_eventfd(s, incoming_posn, new_eventfd); } }