Commit 3b5632ef authored by K. Y. Srinivasan's avatar K. Y. Srinivasan Committed by Greg Kroah-Hartman

Staging: hv: mousevsc: Cleanup mousevsc_on_channel_callback()

Cleanup mousevsc_on_channel_callback(). This is based on the code provided
by Joe Perches <joe@perches.com>.
Signed-off-by: default avatarK. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: default avatarHaiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 32325302
...@@ -313,24 +313,29 @@ static void mousevsc_on_receive(struct hv_device *device, ...@@ -313,24 +313,29 @@ static void mousevsc_on_receive(struct hv_device *device,
static void mousevsc_on_channel_callback(void *context) static void mousevsc_on_channel_callback(void *context)
{ {
const int packetSize = 0x100; const int packet_size = 0x100;
int ret = 0; int ret;
struct hv_device *device = (struct hv_device *)context; struct hv_device *device = context;
u32 bytes_recvd; u32 bytes_recvd;
u64 req_id; u64 req_id;
unsigned char packet[0x100];
struct vmpacket_descriptor *desc; struct vmpacket_descriptor *desc;
unsigned char *buffer = packet; unsigned char *buffer;
int bufferlen = packetSize; int bufferlen = packet_size;
buffer = kmalloc(bufferlen, GFP_ATOMIC);
if (!buffer)
return;
do { do {
ret = vmbus_recvpacket_raw(device->channel, buffer, ret = vmbus_recvpacket_raw(device->channel, buffer,
bufferlen, &bytes_recvd, &req_id); bufferlen, &bytes_recvd, &req_id);
if (ret == 0) { switch (ret) {
if (bytes_recvd > 0) { case 0:
if (bytes_recvd <= 0) {
kfree(buffer);
return;
}
desc = (struct vmpacket_descriptor *)buffer; desc = (struct vmpacket_descriptor *)buffer;
switch (desc->type) { switch (desc->type) {
...@@ -338,8 +343,7 @@ static void mousevsc_on_channel_callback(void *context) ...@@ -338,8 +343,7 @@ static void mousevsc_on_channel_callback(void *context)
break; break;
case VM_PKT_DATA_INBAND: case VM_PKT_DATA_INBAND:
mousevsc_on_receive( mousevsc_on_receive(device, desc);
device, desc);
break; break;
default: default:
...@@ -350,36 +354,21 @@ static void mousevsc_on_channel_callback(void *context) ...@@ -350,36 +354,21 @@ static void mousevsc_on_channel_callback(void *context)
break; break;
} }
/* reset */ break;
if (bufferlen > packetSize) {
kfree(buffer);
buffer = packet; case -ENOBUFS:
bufferlen = packetSize;
}
} else {
if (bufferlen > packetSize) {
kfree(buffer); kfree(buffer);
buffer = packet;
bufferlen = packetSize;
}
break;
}
} else if (ret == -ENOBUFS) {
/* Handle large packet */ /* Handle large packet */
bufferlen = bytes_recvd; bufferlen = bytes_recvd;
buffer = kzalloc(bytes_recvd, GFP_ATOMIC); buffer = kmalloc(bytes_recvd, GFP_ATOMIC);
if (buffer == NULL) { if (buffer == NULL) {
buffer = packet; return;
bufferlen = packetSize;
break;
} }
break;
} }
} while (1); } while (1);
return;
} }
static int mousevsc_connect_to_vsp(struct hv_device *device) static int mousevsc_connect_to_vsp(struct hv_device *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