From patchwork Fri Sep 14 08:46:55 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 183845 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2371C2C0084 for ; Fri, 14 Sep 2012 18:49:02 +1000 (EST) Received: from localhost ([::1]:43241 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TCRa8-0006Rd-9I for incoming@patchwork.ozlabs.org; Fri, 14 Sep 2012 04:49:00 -0400 Received: from eggs.gnu.org ([208.118.235.92]:50233) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TCRYj-0004b6-7C for qemu-devel@nongnu.org; Fri, 14 Sep 2012 04:47:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TCRYi-0000uN-0C for qemu-devel@nongnu.org; Fri, 14 Sep 2012 04:47:33 -0400 Received: from mail-wi0-f175.google.com ([209.85.212.175]:57077) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TCRYh-0000uG-Q3 for qemu-devel@nongnu.org; Fri, 14 Sep 2012 04:47:31 -0400 Received: by wibhm2 with SMTP id hm2so5783529wib.10 for ; Fri, 14 Sep 2012 01:47:31 -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:x-mailer:in-reply-to:references; bh=m3GfmRtNWhUMhRlBtOZPJEBlG3YmJuRGgtT5MVNY/mI=; b=GmhmTfKxuGMpWkQ031szv6iMIteuk0uGpNBp4Zo5xMzTVdcYJON2G9cHhIo3CQ+I4N 8WacSS9VjxoLds+THdtNFoMIva3sqlGZey4AA1l0TAlR5u7MbuB+oNdsBQlu/oNpRn/n W80eYp7zcRqM32dpkGWtK+bT3+kj+3g6SSm4l80mQomhFJ8W5XSyV5wwSIZaaonL6Xp+ 243gyLQB8YUk3KHvh+QfuI/ORKi0l+1cEpeUjniaJ707UXrFiyheDDxLqPPcDETkTfGJ oRk+Vso+nL5jVC1/pt0L1db1X54pqeiO/FCgotCq1n4Aa9/oYoC0Vmq6niZQL5eSspd4 yc2g== Received: by 10.216.241.198 with SMTP id g48mr982283wer.161.1347612451044; Fri, 14 Sep 2012 01:47:31 -0700 (PDT) Received: from localhost ([109.224.133.37]) by mx.google.com with ESMTPS id k2sm2619729wiz.7.2012.09.14.01.47.30 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 14 Sep 2012 01:47:30 -0700 (PDT) From: Stefan Hajnoczi To: Anthony Liguori Date: Fri, 14 Sep 2012 09:46:55 +0100 Message-Id: <1347612420-5704-9-git-send-email-stefanha@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1347612420-5704-1-git-send-email-stefanha@gmail.com> References: <1347612420-5704-1-git-send-email-stefanha@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.212.175 Cc: qemu-devel@nongnu.org, Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 08/13] net: clean up usbnet_receive() 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: Stefan Hajnoczi The USB network interface has two code paths depending on whether or not RNDIS mode is enabled. Refactor usbnet_receive() so that there is a common path throughout the function instead of duplicating everything across if (is_rndis(s)) ... else ... code paths. Clean up coding style and 80 character line wrap along the way. Signed-off-by: Stefan Hajnoczi --- hw/usb/dev-network.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c index c84892c..0b5cb71 100644 --- a/hw/usb/dev-network.c +++ b/hw/usb/dev-network.c @@ -1250,20 +1250,27 @@ static int usb_net_handle_data(USBDevice *dev, USBPacket *p) static ssize_t usbnet_receive(NetClientState *nc, const uint8_t *buf, size_t size) { USBNetState *s = DO_UPCAST(NICState, nc, nc)->opaque; - struct rndis_packet_msg_type *msg; + uint8_t *in_buf = s->in_buf; + size_t total_size = size; if (is_rndis(s)) { - msg = (struct rndis_packet_msg_type *) s->in_buf; if (s->rndis_state != RNDIS_DATA_INITIALIZED) { return -1; } - if (size + sizeof(struct rndis_packet_msg_type) > sizeof(s->in_buf)) - return -1; + total_size += sizeof(struct rndis_packet_msg_type); + } + if (total_size > sizeof(s->in_buf)) { + return -1; + } + if (is_rndis(s)) { + struct rndis_packet_msg_type *msg; + + msg = (struct rndis_packet_msg_type *)in_buf; memset(msg, 0, sizeof(struct rndis_packet_msg_type)); msg->MessageType = cpu_to_le32(RNDIS_PACKET_MSG); - msg->MessageLength = cpu_to_le32(size + sizeof(struct rndis_packet_msg_type)); - msg->DataOffset = cpu_to_le32(sizeof(struct rndis_packet_msg_type) - 8); + msg->MessageLength = cpu_to_le32(size + sizeof(*msg)); + msg->DataOffset = cpu_to_le32(sizeof(*msg) - 8); msg->DataLength = cpu_to_le32(size); /* msg->OOBDataOffset; * msg->OOBDataLength; @@ -1273,14 +1280,11 @@ static ssize_t usbnet_receive(NetClientState *nc, const uint8_t *buf, size_t siz * msg->VcHandle; * msg->Reserved; */ - memcpy(msg + 1, buf, size); - s->in_len = size + sizeof(struct rndis_packet_msg_type); - } else { - if (size > sizeof(s->in_buf)) - return -1; - memcpy(s->in_buf, buf, size); - s->in_len = size; + in_buf += sizeof(*msg); } + + memcpy(in_buf, buf, size); + s->in_len = total_size; s->in_ptr = 0; return size; }