From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJspo-0006uI-FF for qemu-devel@nongnu.org; Mon, 27 Jul 2015 20:33:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZJspl-0004tN-9W for qemu-devel@nongnu.org; Mon, 27 Jul 2015 20:33:32 -0400 Received: from mail-qg0-x22b.google.com ([2607:f8b0:400d:c04::22b]:35503) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJspl-0004tJ-6c for qemu-devel@nongnu.org; Mon, 27 Jul 2015 20:33:29 -0400 Received: by qgii95 with SMTP id i95so64560707qgi.2 for ; Mon, 27 Jul 2015 17:33:28 -0700 (PDT) Sender: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 28 Jul 2015 02:32:18 +0200 Message-Id: <1438043577-28636-7-git-send-email-marcandre.lureau@redhat.com> In-Reply-To: <1438043577-28636-1-git-send-email-marcandre.lureau@redhat.com> References: <1438043577-28636-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] [PATCH v2 06/45] ivshmem: remove unnecessary dup() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , drjones@redhat.com, cam@cs.ualberta.ca, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , stefanha@redhat.com From: Marc-André Lureau qemu_chr_fe_get_msgfd() transfer ownership, there is no need to dup the fd. Signed-off-by: Marc-André Lureau --- hw/misc/ivshmem.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index dd15f0e..fbeb731 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -480,7 +480,7 @@ static bool fifo_update_and_get(IVShmemState *s, const uint8_t *buf, int size, static void ivshmem_read(void *opaque, const uint8_t *buf, int size) { IVShmemState *s = opaque; - int incoming_fd, tmp_fd; + int incoming_fd; int guest_max_eventfd; long incoming_posn; @@ -495,21 +495,21 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size) } /* pick off s->server_chr->msgfd and store it, posn should accompany msg */ - tmp_fd = qemu_chr_fe_get_msgfd(s->server_chr); - IVSHMEM_DPRINTF("posn is %ld, fd is %d\n", incoming_posn, tmp_fd); + incoming_fd = qemu_chr_fe_get_msgfd(s->server_chr); + IVSHMEM_DPRINTF("posn is %ld, fd is %d\n", incoming_posn, incoming_fd); /* make sure we have enough space for this guest */ if (incoming_posn >= s->nb_peers) { if (increase_dynamic_storage(s, incoming_posn) < 0) { error_report("increase_dynamic_storage() failed"); - if (tmp_fd != -1) { - close(tmp_fd); + if (incoming_fd != -1) { + close(incoming_fd); } return; } } - if (tmp_fd == -1) { + 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)) { @@ -524,15 +524,6 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size) } } - /* because of the implementation of get_msgfd, we need a dup */ - incoming_fd = dup(tmp_fd); - - if (incoming_fd == -1) { - error_report("could not allocate file descriptor %s", strerror(errno)); - close(tmp_fd); - return; - } - /* if the position is -1, then it's shared memory region fd */ if (incoming_posn == -1) { -- 2.4.3