net: clean up usbnet_receive()
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 <stefanha@linux.vnet.ibm.com>
This commit is contained in:
		
							parent
							
								
									08d12022c7
								
							
						
					
					
						commit
						f237ddbb89
					
				@ -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)
 | 
					static ssize_t usbnet_receive(NetClientState *nc, const uint8_t *buf, size_t size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    USBNetState *s = DO_UPCAST(NICState, nc, nc)->opaque;
 | 
					    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)) {
 | 
					    if (is_rndis(s)) {
 | 
				
			||||||
        msg = (struct rndis_packet_msg_type *) s->in_buf;
 | 
					 | 
				
			||||||
        if (s->rndis_state != RNDIS_DATA_INITIALIZED) {
 | 
					        if (s->rndis_state != RNDIS_DATA_INITIALIZED) {
 | 
				
			||||||
            return -1;
 | 
					            return -1;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (size + sizeof(struct rndis_packet_msg_type) > sizeof(s->in_buf))
 | 
					        total_size += sizeof(struct rndis_packet_msg_type);
 | 
				
			||||||
            return -1;
 | 
					    }
 | 
				
			||||||
 | 
					    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));
 | 
					        memset(msg, 0, sizeof(struct rndis_packet_msg_type));
 | 
				
			||||||
        msg->MessageType = cpu_to_le32(RNDIS_PACKET_MSG);
 | 
					        msg->MessageType = cpu_to_le32(RNDIS_PACKET_MSG);
 | 
				
			||||||
        msg->MessageLength = cpu_to_le32(size + sizeof(struct rndis_packet_msg_type));
 | 
					        msg->MessageLength = cpu_to_le32(size + sizeof(*msg));
 | 
				
			||||||
        msg->DataOffset = cpu_to_le32(sizeof(struct rndis_packet_msg_type) - 8);
 | 
					        msg->DataOffset = cpu_to_le32(sizeof(*msg) - 8);
 | 
				
			||||||
        msg->DataLength = cpu_to_le32(size);
 | 
					        msg->DataLength = cpu_to_le32(size);
 | 
				
			||||||
        /* msg->OOBDataOffset;
 | 
					        /* msg->OOBDataOffset;
 | 
				
			||||||
         * msg->OOBDataLength;
 | 
					         * msg->OOBDataLength;
 | 
				
			||||||
@ -1273,14 +1280,11 @@ static ssize_t usbnet_receive(NetClientState *nc, const uint8_t *buf, size_t siz
 | 
				
			|||||||
         * msg->VcHandle;
 | 
					         * msg->VcHandle;
 | 
				
			||||||
         * msg->Reserved;
 | 
					         * msg->Reserved;
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
        memcpy(msg + 1, buf, size);
 | 
					        in_buf += sizeof(*msg);
 | 
				
			||||||
        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;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    memcpy(in_buf, buf, size);
 | 
				
			||||||
 | 
					    s->in_len = total_size;
 | 
				
			||||||
    s->in_ptr = 0;
 | 
					    s->in_ptr = 0;
 | 
				
			||||||
    return size;
 | 
					    return size;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user