Commit c6fcf0ba authored by Bill Pemberton's avatar Bill Pemberton Committed by Greg Kroah-Hartman

Staging: hv: don't use dynamic sized array

NetVscOnChannelCallback() used a dynamic sized array that also made
the frame size over 2048.  Replace it with a buffer allocated from
kzalloc.
Signed-off-by: default avatarBill Pemberton <wfp5p@virginia.edu>
Cc: Hank Janssen <hjanssen@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent a5729c00
...@@ -1288,28 +1288,33 @@ static void NetVscOnReceiveCompletion(void *Context) ...@@ -1288,28 +1288,33 @@ static void NetVscOnReceiveCompletion(void *Context)
void NetVscOnChannelCallback(void *Context) void NetVscOnChannelCallback(void *Context)
{ {
const int netPacketSize = 2048;
int ret; int ret;
struct hv_device *device = Context; struct hv_device *device = Context;
struct netvsc_device *netDevice; struct netvsc_device *netDevice;
u32 bytesRecvd; u32 bytesRecvd;
u64 requestId; u64 requestId;
unsigned char packet[netPacketSize]; unsigned char *packet;
struct vmpacket_descriptor *desc; struct vmpacket_descriptor *desc;
unsigned char *buffer = packet; unsigned char *buffer;
int bufferlen = netPacketSize; int bufferlen = NETVSC_PACKET_SIZE;
DPRINT_ENTER(NETVSC); DPRINT_ENTER(NETVSC);
ASSERT(device); ASSERT(device);
packet = kzalloc(NETVSC_PACKET_SIZE * sizeof(unsigned char),
GFP_KERNEL);
if (!packet)
return;
buffer = packet;
netDevice = GetInboundNetDevice(device); netDevice = GetInboundNetDevice(device);
if (!netDevice) { if (!netDevice) {
DPRINT_ERR(NETVSC, "net device (%p) shutting down..." DPRINT_ERR(NETVSC, "net device (%p) shutting down..."
"ignoring inbound packets", netDevice); "ignoring inbound packets", netDevice);
DPRINT_EXIT(NETVSC); DPRINT_EXIT(NETVSC);
return; goto out;
} }
do { do {
...@@ -1341,17 +1346,17 @@ void NetVscOnChannelCallback(void *Context) ...@@ -1341,17 +1346,17 @@ void NetVscOnChannelCallback(void *Context)
} }
/* reset */ /* reset */
if (bufferlen > netPacketSize) { if (bufferlen > NETVSC_PACKET_SIZE) {
kfree(buffer); kfree(buffer);
buffer = packet; buffer = packet;
bufferlen = netPacketSize; bufferlen = NETVSC_PACKET_SIZE;
} }
} else { } else {
/* reset */ /* reset */
if (bufferlen > netPacketSize) { if (bufferlen > NETVSC_PACKET_SIZE) {
kfree(buffer); kfree(buffer);
buffer = packet; buffer = packet;
bufferlen = netPacketSize; bufferlen = NETVSC_PACKET_SIZE;
} }
break; break;
...@@ -1375,5 +1380,7 @@ void NetVscOnChannelCallback(void *Context) ...@@ -1375,5 +1380,7 @@ void NetVscOnChannelCallback(void *Context)
PutNetDevice(device); PutNetDevice(device);
DPRINT_EXIT(NETVSC); DPRINT_EXIT(NETVSC);
out:
kfree(buffer);
return; return;
} }
...@@ -289,6 +289,7 @@ struct nvsp_message { ...@@ -289,6 +289,7 @@ struct nvsp_message {
/* Preallocated receive packets */ /* Preallocated receive packets */
#define NETVSC_RECEIVE_PACKETLIST_COUNT 256 #define NETVSC_RECEIVE_PACKETLIST_COUNT 256
#define NETVSC_PACKET_SIZE 2048
/* Per netvsc channel-specific */ /* Per netvsc channel-specific */
struct netvsc_device { struct netvsc_device {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment