|
|
5544c1 |
From f3f975860db11101ccef2f75238032328de00ce0 Mon Sep 17 00:00:00 2001
|
|
|
5544c1 |
From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
|
|
|
5544c1 |
Date: Fri, 24 Aug 2012 13:32:16 +0100
|
|
|
5544c1 |
Subject: [PATCH] net: clean up usbnet_receive()
|
|
|
5544c1 |
|
|
|
5544c1 |
The USB network interface has two code paths depending on whether or not
|
|
|
5544c1 |
RNDIS mode is enabled. Refactor usbnet_receive() so that there is a
|
|
|
5544c1 |
common path throughout the function instead of duplicating everything
|
|
|
5544c1 |
across if (is_rndis(s)) ... else ... code paths.
|
|
|
5544c1 |
|
|
|
5544c1 |
Clean up coding style and 80 character line wrap along the way.
|
|
|
5544c1 |
|
|
|
5544c1 |
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
|
|
|
5544c1 |
(cherry picked from commit f237ddbb89142c6948a2257c459e49dee7500a7c)
|
|
|
5544c1 |
|
|
|
5544c1 |
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
|
|
|
5544c1 |
---
|
|
|
5544c1 |
hw/usb/dev-network.c | 30 +++++++++++++++++-------------
|
|
|
5544c1 |
1 file changed, 17 insertions(+), 13 deletions(-)
|
|
|
5544c1 |
|
|
|
5544c1 |
diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c
|
|
|
5544c1 |
index c84892c..0b5cb71 100644
|
|
|
5544c1 |
--- a/hw/usb/dev-network.c
|
|
|
5544c1 |
+++ b/hw/usb/dev-network.c
|
|
|
5544c1 |
@@ -1250,20 +1250,27 @@ static int usb_net_handle_data(USBDevice *dev, USBPacket *p)
|
|
|
5544c1 |
static ssize_t usbnet_receive(NetClientState *nc, const uint8_t *buf, size_t size)
|
|
|
5544c1 |
{
|
|
|
5544c1 |
USBNetState *s = DO_UPCAST(NICState, nc, nc)->opaque;
|
|
|
5544c1 |
- struct rndis_packet_msg_type *msg;
|
|
|
5544c1 |
+ uint8_t *in_buf = s->in_buf;
|
|
|
5544c1 |
+ size_t total_size = size;
|
|
|
5544c1 |
|
|
|
5544c1 |
if (is_rndis(s)) {
|
|
|
5544c1 |
- msg = (struct rndis_packet_msg_type *) s->in_buf;
|
|
|
5544c1 |
if (s->rndis_state != RNDIS_DATA_INITIALIZED) {
|
|
|
5544c1 |
return -1;
|
|
|
5544c1 |
}
|
|
|
5544c1 |
- if (size + sizeof(struct rndis_packet_msg_type) > sizeof(s->in_buf))
|
|
|
5544c1 |
- return -1;
|
|
|
5544c1 |
+ total_size += sizeof(struct rndis_packet_msg_type);
|
|
|
5544c1 |
+ }
|
|
|
5544c1 |
+ if (total_size > sizeof(s->in_buf)) {
|
|
|
5544c1 |
+ return -1;
|
|
|
5544c1 |
+ }
|
|
|
5544c1 |
|
|
|
5544c1 |
+ if (is_rndis(s)) {
|
|
|
5544c1 |
+ struct rndis_packet_msg_type *msg;
|
|
|
5544c1 |
+
|
|
|
5544c1 |
+ msg = (struct rndis_packet_msg_type *)in_buf;
|
|
|
5544c1 |
memset(msg, 0, sizeof(struct rndis_packet_msg_type));
|
|
|
5544c1 |
msg->MessageType = cpu_to_le32(RNDIS_PACKET_MSG);
|
|
|
5544c1 |
- msg->MessageLength = cpu_to_le32(size + sizeof(struct rndis_packet_msg_type));
|
|
|
5544c1 |
- msg->DataOffset = cpu_to_le32(sizeof(struct rndis_packet_msg_type) - 8);
|
|
|
5544c1 |
+ msg->MessageLength = cpu_to_le32(size + sizeof(*msg));
|
|
|
5544c1 |
+ msg->DataOffset = cpu_to_le32(sizeof(*msg) - 8);
|
|
|
5544c1 |
msg->DataLength = cpu_to_le32(size);
|
|
|
5544c1 |
/* msg->OOBDataOffset;
|
|
|
5544c1 |
* msg->OOBDataLength;
|
|
|
5544c1 |
@@ -1273,14 +1280,11 @@ static ssize_t usbnet_receive(NetClientState *nc, const uint8_t *buf, size_t siz
|
|
|
5544c1 |
* msg->VcHandle;
|
|
|
5544c1 |
* msg->Reserved;
|
|
|
5544c1 |
*/
|
|
|
5544c1 |
- memcpy(msg + 1, buf, size);
|
|
|
5544c1 |
- s->in_len = size + sizeof(struct rndis_packet_msg_type);
|
|
|
5544c1 |
- } else {
|
|
|
5544c1 |
- if (size > sizeof(s->in_buf))
|
|
|
5544c1 |
- return -1;
|
|
|
5544c1 |
- memcpy(s->in_buf, buf, size);
|
|
|
5544c1 |
- s->in_len = size;
|
|
|
5544c1 |
+ in_buf += sizeof(*msg);
|
|
|
5544c1 |
}
|
|
|
5544c1 |
+
|
|
|
5544c1 |
+ memcpy(in_buf, buf, size);
|
|
|
5544c1 |
+ s->in_len = total_size;
|
|
|
5544c1 |
s->in_ptr = 0;
|
|
|
5544c1 |
return size;
|
|
|
5544c1 |
}
|
|
|
5544c1 |
--
|
|
|
5544c1 |
1.7.12.1
|
|
|
5544c1 |
|