From patchwork Sat Jun 4 21:33:12 2016 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: 9154969 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9582360777 for ; Sat, 4 Jun 2016 21:34:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8773E28327 for ; Sat, 4 Jun 2016 21:34:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7AEF02832D; Sat, 4 Jun 2016 21:34:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2924528327 for ; Sat, 4 Jun 2016 21:34:14 +0000 (UTC) Received: from localhost ([::1]:34191 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9JCv-0005qh-Ai for patchwork-qemu-devel@patchwork.kernel.org; Sat, 04 Jun 2016 17:34:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44708) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9JCK-0005oI-4r for qemu-devel@nongnu.org; Sat, 04 Jun 2016 17:33:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b9JCI-0005iX-5z for qemu-devel@nongnu.org; Sat, 04 Jun 2016 17:33:35 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:33033) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9JCH-0005iQ-Vz for qemu-devel@nongnu.org; Sat, 04 Jun 2016 17:33:34 -0400 Received: by mail-wm0-x242.google.com with SMTP id a136so7294021wme.0 for ; Sat, 04 Jun 2016 14:33:33 -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-transfer-encoding; bh=+18xkcHXTMVwB1A6FlZ4GoIyRualPWK1nEuCZHFvPW8=; b=Wk2k+JHdRqEqfWoCDbwxLqYvzlPPWXErvSmwXKpHJlP3pvzWwR2BL44tYVK+m3qV+I siZoqcuX04AKi9IBp0YqILuDKLMdHdwq8x6c0ZCNpemVbNmDucVBW+I61p1VJQNASphJ obV3u0dZYwhcvqYAcSEhlNXg4efYMda6cJKJArNhXCB2Xmce9lGmpe7qdMjnukn1JAKR 9Sk5+TrwmoQzD4RrusSsIsqbkCz9+gO7hTJHf7n9ptqf06PET+7QFt/qjaCJ59kOApnG etZ5YOkMBdogLVB+zybxzCIEyWUE8WhyTvnoc5jA9v8DfHnrmilIzkCsRkoXma35uCOW k4Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=+18xkcHXTMVwB1A6FlZ4GoIyRualPWK1nEuCZHFvPW8=; b=cGvPbdjgCMV4CZEzxi5ljF8hlbhq9Nu8kga77Xmc+fFepGHhkFVkvRZnhrLSXr6TUY nSnZvwsYRWiWSkdvImrYKlJ//EBb/ySp3ecskMPFoRZyzYfhPhR/uY2xZo05d570izf7 SY3WvX85/y1zFn10YqORYYxMPSxUJ94elniZOmeHIsnJ/V344wcpYe61xyAu4bAtacdk gagx0ECTFbETwYhjFSNlxjwAXLZ0kpTvbkaWKP05k5V1PgOAjidjD8DTGVh/Zqxug70y 7XLw1i26r9fE3N447riOSisd60pJLMD+ttjPdcLNq3iPCyAL86Sj0Xw6qKsRYQWYO3W2 QcDA== X-Gm-Message-State: ALyK8tLAzf+IOv3gmgt8YHWYXyYAniYFEZZuzp/U6uwA8oIYcpean1jStjuioEL3psF2dw== X-Received: by 10.194.147.131 with SMTP id tk3mr9860839wjb.100.1465076013307; Sat, 04 Jun 2016 14:33:33 -0700 (PDT) Received: from localhost (APoitiers-110-1-1-235.w193-248.abo.wanadoo.fr. [193.248.103.235]) by smtp.gmail.com with ESMTPSA id r76sm4462561wme.14.2016.06.04.14.33.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Jun 2016 14:33:32 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Sat, 4 Jun 2016 23:33:12 +0200 Message-Id: <1465076003-26291-4-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1465076003-26291-1-git-send-email-marcandre.lureau@redhat.com> References: <1465076003-26291-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::242 Subject: [Qemu-devel] [RFC 03/14] vhost-user: split vhost_user_read() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , kraxel@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Marc-André Lureau Split vhost_user_read(), so only header can be read with vhost_user_read_header(). Signed-off-by: Marc-André Lureau --- hw/virtio/vhost-user.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 495e09f..63ffe48 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -112,7 +112,7 @@ static bool ioeventfd_enabled(void) return kvm_enabled() && kvm_eventfds_enabled(); } -static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) +static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg) { CharDriverState *chr = dev->opaque; uint8_t *p = (uint8_t *) msg; @@ -122,7 +122,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) if (r != size) { error_report("Failed to read msg header. Read %d instead of %d." " Original request %d.", r, size, msg->request); - goto fail; + return -1; } /* validate received flags */ @@ -130,7 +130,20 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) error_report("Failed to read msg header." " Flags 0x%x instead of 0x%x.", msg->flags, VHOST_USER_REPLY_MASK | VHOST_USER_VERSION); - goto fail; + return -1; + } + + return 0; +} + +static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) +{ + CharDriverState *chr = dev->opaque; + uint8_t *p = (uint8_t *) msg; + int r, size; + + if (vhost_user_read_header(dev, msg) < 0) { + return -1; } /* validate message size is sane */ @@ -138,7 +151,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) error_report("Failed to read msg header." " Size %d exceeds the maximum %zu.", msg->size, VHOST_USER_PAYLOAD_SIZE); - goto fail; + return -1; } if (msg->size) { @@ -148,14 +161,11 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) if (r != size) { error_report("Failed to read msg payload." " Read %d instead of %d.", r, msg->size); - goto fail; + return -1; } } return 0; - -fail: - return -1; } static bool vhost_user_one_time_request(VhostUserRequest request) @@ -458,7 +468,7 @@ static int vhost_user_get_u64(struct vhost_dev *dev, int request, uint64_t *u64) vhost_user_write(dev, &msg, NULL, 0); if (vhost_user_read(dev, &msg) < 0) { - return 0; + return -1; } if (msg.request != request) {