HID: hyperv: Use in-place iterator API in the channel callback
Simplify the ring buffer handling with the in-place API. Also avoid the dynamic allocation and the memory leak in the channel callback function. Signed-off-by: Dexuan Cui <decui@microsoft.com> Acked-by: Jiri Kosina <jkosina@suse.cz> Signed-off-by: Sasha Levin <sashal@kernel.org>alistair/sunxi64-5.4-dsi
parent
54ecb8f702
commit
6a297c90ef
|
@ -314,60 +314,24 @@ 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 packet_size = 0x100;
|
|
||||||
int ret;
|
|
||||||
struct hv_device *device = context;
|
struct hv_device *device = context;
|
||||||
u32 bytes_recvd;
|
|
||||||
u64 req_id;
|
|
||||||
struct vmpacket_descriptor *desc;
|
struct vmpacket_descriptor *desc;
|
||||||
unsigned char *buffer;
|
|
||||||
int bufferlen = packet_size;
|
|
||||||
|
|
||||||
buffer = kmalloc(bufferlen, GFP_ATOMIC);
|
|
||||||
if (!buffer)
|
|
||||||
return;
|
|
||||||
|
|
||||||
do {
|
|
||||||
ret = vmbus_recvpacket_raw(device->channel, buffer,
|
|
||||||
bufferlen, &bytes_recvd, &req_id);
|
|
||||||
|
|
||||||
switch (ret) {
|
|
||||||
case 0:
|
|
||||||
if (bytes_recvd <= 0) {
|
|
||||||
kfree(buffer);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
desc = (struct vmpacket_descriptor *)buffer;
|
|
||||||
|
|
||||||
switch (desc->type) {
|
|
||||||
case VM_PKT_COMP:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VM_PKT_DATA_INBAND:
|
|
||||||
mousevsc_on_receive(device, desc);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
pr_err("unhandled packet type %d, tid %llx len %d\n",
|
|
||||||
desc->type, req_id, bytes_recvd);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
foreach_vmbus_pkt(desc, device->channel) {
|
||||||
|
switch (desc->type) {
|
||||||
|
case VM_PKT_COMP:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case -ENOBUFS:
|
case VM_PKT_DATA_INBAND:
|
||||||
kfree(buffer);
|
mousevsc_on_receive(device, desc);
|
||||||
/* Handle large packet */
|
break;
|
||||||
bufferlen = bytes_recvd;
|
|
||||||
buffer = kmalloc(bytes_recvd, GFP_ATOMIC);
|
|
||||||
|
|
||||||
if (!buffer)
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
default:
|
||||||
|
pr_err("Unhandled packet type %d, tid %llx len %d\n",
|
||||||
|
desc->type, desc->trans_id, desc->len8 * 8);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (1);
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mousevsc_connect_to_vsp(struct hv_device *device)
|
static int mousevsc_connect_to_vsp(struct hv_device *device)
|
||||||
|
|
Loading…
Reference in New Issue