From patchwork Fri Jun 26 14:49:25 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: 488890 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 14E8D1400A0 for ; Sat, 27 Jun 2015 01:14:38 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=aROOnU0y; dkim-atps=neutral Received: from localhost ([::1]:60630 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z8VKt-0004Fg-Rt for incoming@patchwork.ozlabs.org; Fri, 26 Jun 2015 11:14:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57282) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z8Uy1-00057P-2y for qemu-devel@nongnu.org; Fri, 26 Jun 2015 10:50:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z8Uxv-0002Kh-Qk for qemu-devel@nongnu.org; Fri, 26 Jun 2015 10:50:56 -0400 Received: from mail-qk0-x231.google.com ([2607:f8b0:400d:c09::231]:35786) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z8Uxv-0002KN-AR for qemu-devel@nongnu.org; Fri, 26 Jun 2015 10:50:51 -0400 Received: by qkbp125 with SMTP id p125so56289965qkb.2 for ; Fri, 26 Jun 2015 07:50:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=fbJjgcHgt409HQuUphvkiRDmllSR+WvLS25ht/Fb7r0=; b=aROOnU0yfzsmBe737rHLsVhalpdlNENQ/Mt/zWoBE46FpT72oli+Q5ZigdikXCcr+o B2Ik1XhpQSNFI65xl2/quNmhj6CvSYiHDt9oeEHfVcrVCJkIggM7NCBiCocA/7/XWWMy enuXByDTNVpL10d3e6e1YB9kG6invdbCHOJYU4q4mj3f92GcSX+2LOmda4oDJbYsToUZ 6at/1X7qN16Wa5CAwls16Aqm8GhJXpxFjREKYkbcFBT7lIBBuq5TglG2kr0FqvLmSgFV 40YbyKUf+l6Gd70GsB6ZOoLaygg8rabBBHYPKgl2Hi4VpVNQ7Iw506oR+hNGcMwLi7/p orig== X-Received: by 10.55.20.39 with SMTP id e39mr4522054qkh.35.1435330251001; Fri, 26 Jun 2015 07:50:51 -0700 (PDT) Received: from localhost (bne75-h02-31-39-163-232.dsl.sta.abo.bbox.fr. [31.39.163.232]) by mx.google.com with ESMTPSA id m48sm6969265qgd.35.2015.06.26.07.50.49 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Jun 2015 07:50:50 -0700 (PDT) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 26 Jun 2015 16:49:25 +0200 Message-Id: <1435330185-23248-20-git-send-email-marcandre.lureau@gmail.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1435330185-23248-1-git-send-email-marcandre.lureau@gmail.com> References: <1435330185-23248-1-git-send-email-marcandre.lureau@gmail.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::231 Cc: cam@cs.ualberta.ca, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , stefanha@redhat.com Subject: [Qemu-devel] [PATCH 19/39] ivshmem: beautify 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 Use more explicit variables. Signed-off-by: Marc-André Lureau --- hw/misc/ivshmem.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index 6f3d2fe..84d8ff1 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -489,9 +489,10 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size) { IVShmemState *s = opaque; int incoming_fd; - int guest_max_eventfd; + int nth_eventfd; long incoming_posn; Error *err = NULL; + Peer *peer; if (!fifo_update_and_get(s, buf, size, &incoming_posn, sizeof(incoming_posn))) { @@ -518,6 +519,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) { @@ -565,27 +568,22 @@ 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; + /* get a new eventfd */ + nth_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++; + nth_eventfd, incoming_fd); + event_notifier_init_fd(&peer->eventfds[nth_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[nth_eventfd] = create_eventfd_chr_device(s, + &s->peers[s->vm_id].eventfds[nth_eventfd], + nth_eventfd); } if (ivshmem_has_feature(s, IVSHMEM_IOEVENTFD)) { - ivshmem_add_eventfd(s, incoming_posn, guest_max_eventfd); + ivshmem_add_eventfd(s, incoming_posn, nth_eventfd); } }