From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dexuan Cui Subject: [PATCH] HID: hyperv: Use in-place iterator API in the channel callback Date: Tue, 20 Aug 2019 02:56:34 +0000 Message-ID: <1566269763-26817-1-git-send-email-decui@microsoft.com> Reply-To: Dexuan Cui Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org To: "jikos@kernel.org" , "benjamin.tissoires@redhat.com" , "linux-input@vger.kernel.org" , "linux-hyperv@vger.kernel.org" , Stephen Hemminger , Sasha Levin , "sashal@kernel.org" , Haiyang Zhang , KY Srinivasan , Michael Kelley Cc: "gregkh@linuxfoundation.org" , "linux-kernel@vger.kernel.org" , Dexuan Cui List-Id: linux-input@vger.kernel.org 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 --- Hi Jiri, Benjamin, can this patch go through Sasha's hyperv tree: https://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux.git This is a purely Hyper-V specific change. drivers/hid/hid-hyperv.c | 56 +++++++++-----------------------------------= ---- 1 file changed, 10 insertions(+), 46 deletions(-) diff --git a/drivers/hid/hid-hyperv.c b/drivers/hid/hid-hyperv.c index 7795831..f363163 100644 --- a/drivers/hid/hid-hyperv.c +++ b/drivers/hid/hid-hyperv.c @@ -314,60 +314,24 @@ static void mousevsc_on_receive(struct hv_device *dev= ice, =20 static void mousevsc_on_channel_callback(void *context) { - const int packet_size =3D 0x100; - int ret; struct hv_device *device =3D context; - u32 bytes_recvd; - u64 req_id; struct vmpacket_descriptor *desc; - unsigned char *buffer; - int bufferlen =3D packet_size; - - buffer =3D kmalloc(bufferlen, GFP_ATOMIC); - if (!buffer) - return; - - do { - ret =3D vmbus_recvpacket_raw(device->channel, buffer, - bufferlen, &bytes_recvd, &req_id); - - switch (ret) { - case 0: - if (bytes_recvd <=3D 0) { - kfree(buffer); - return; - } - desc =3D (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; - } =20 + foreach_vmbus_pkt(desc, device->channel) { + switch (desc->type) { + case VM_PKT_COMP: break; =20 - case -ENOBUFS: - kfree(buffer); - /* Handle large packet */ - bufferlen =3D bytes_recvd; - buffer =3D kmalloc(bytes_recvd, GFP_ATOMIC); - - if (!buffer) - return; + case VM_PKT_DATA_INBAND: + mousevsc_on_receive(device, desc); + break; =20 + default: + pr_err("Unhandled packet type %d, tid %llx len %d\n", + desc->type, desc->trans_id, desc->len8 * 8); break; } - } while (1); - + } } =20 static int mousevsc_connect_to_vsp(struct hv_device *device) --=20 1.8.3.1