From patchwork Tue Oct 6 19:19:02 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: 527027 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 1EFAB140D71 for ; Wed, 7 Oct 2015 09:08:01 +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=AFQZNx16; dkim-atps=neutral Received: from localhost ([::1]:54304 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZjaOt-0006FB-9f for incoming@patchwork.ozlabs.org; Tue, 06 Oct 2015 18:07:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46156) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZjaOb-0005xi-F2 for qemu-devel@nongnu.org; Tue, 06 Oct 2015 18:07:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZjXmm-00035C-I9 for qemu-devel@nongnu.org; Tue, 06 Oct 2015 15:21:34 -0400 Received: from mail-qg0-x235.google.com ([2607:f8b0:400d:c04::235]:33275) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZjXml-00030g-Hi for qemu-devel@nongnu.org; Tue, 06 Oct 2015 15:20:28 -0400 Received: by qgev79 with SMTP id v79so183459948qge.0 for ; Tue, 06 Oct 2015 12:20:20 -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=udEgIBSg/BnuHH1wW0Y76jrQQjyFzNp7pNYATcgDDwE=; b=AFQZNx16SZlOxKlHIsdp+QyK3qKj7/YUYw3TEtn552bEUNWPHndOkMwseBOLbCdAzd uEpGtqPhMfJQnJLESncp3lEW3ctPzOaaFnw5mBQergdRAmbknhkrPz/mqHVgdCY9931c GX0xZIAacBqFAV93duBkJ8OwfK4QWpjb67lRxBVb3t9Gw+8VjXZV6UcGDkC0OVo3KCC9 HxfIF/+olkMW4nuQzO+wNaK+JnA8dd/nWM3Izhwxj1byOAuGBbYPtSxrT9nE0fXzzSF1 5vHVitVnzd4r9gqlNCELvFxVB2TDNds4NMpWjvYY8JreUVNkKh2/22n+MkNL5pSoIj35 SRWA== X-Received: by 10.140.95.77 with SMTP id h71mr48912149qge.8.1444159220844; Tue, 06 Oct 2015 12:20:20 -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 78sm14415425qhd.40.2015.10.06.12.20.19 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Oct 2015 12:20:19 -0700 (PDT) From: marcandre.lureau@redhat.com To: peter.maydell@linaro.org Date: Tue, 6 Oct 2015 21:19:02 +0200 Message-Id: <1444159184-18153-7-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:c04::235 Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , qemu-devel@nongnu.org Subject: [Qemu-devel] [PULL 06/48] ivshmem: remove unnecessary dup() 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 qemu_chr_fe_get_msgfd() transfers ownership, there is no need to dup the fd. Signed-off-by: Marc-André Lureau Reviewed-by: Claudio Fontana --- 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) {