Skip to content

Commit

Permalink
Drivers: net: hyperv: Cleanup the netvsc receive callback functio
Browse files Browse the repository at this point in the history
Get rid of the buffer allocation in the receive path for normal packets.

Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
KY Srinivasan authored and David S. Miller committed Feb 17, 2014
1 parent 97c1723 commit ee0c4c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
2 changes: 2 additions & 0 deletions drivers/net/hyperv/hyperv_net.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ struct netvsc_device {

/* Holds rndis device info */
void *extension;
/* The recive buffer for this device */
unsigned char cb_buffer[NETVSC_PACKET_SIZE];
};

/* NdisInitialize message */
Expand Down
33 changes: 10 additions & 23 deletions drivers/net/hyperv/netvsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -795,22 +795,16 @@ static void netvsc_channel_cb(void *context)
struct netvsc_device *net_device;
u32 bytes_recvd;
u64 request_id;
unsigned char *packet;
struct vmpacket_descriptor *desc;
unsigned char *buffer;
int bufferlen = NETVSC_PACKET_SIZE;
struct net_device *ndev;

packet = kzalloc(NETVSC_PACKET_SIZE * sizeof(unsigned char),
GFP_ATOMIC);
if (!packet)
return;
buffer = packet;

net_device = get_inbound_net_device(device);
if (!net_device)
goto out;
return;
ndev = net_device->ndev;
buffer = net_device->cb_buffer;

do {
ret = vmbus_recvpacket_raw(device->channel, buffer, bufferlen,
Expand Down Expand Up @@ -838,23 +832,16 @@ static void netvsc_channel_cb(void *context)
break;
}

/* reset */
if (bufferlen > NETVSC_PACKET_SIZE) {
kfree(buffer);
buffer = packet;
bufferlen = NETVSC_PACKET_SIZE;
}
} else {
/* reset */
if (bufferlen > NETVSC_PACKET_SIZE) {
kfree(buffer);
buffer = packet;
bufferlen = NETVSC_PACKET_SIZE;
}

/*
* We are done for this pass.
*/
break;
}

} else if (ret == -ENOBUFS) {
if (bufferlen > NETVSC_PACKET_SIZE)
kfree(buffer);
/* Handle large packet */
buffer = kmalloc(bytes_recvd, GFP_ATOMIC);
if (buffer == NULL) {
Expand All @@ -869,8 +856,8 @@ static void netvsc_channel_cb(void *context)
}
} while (1);

out:
kfree(buffer);
if (bufferlen > NETVSC_PACKET_SIZE)
kfree(buffer);
return;
}

Expand Down

0 comments on commit ee0c4c3

Please sign in to comment.