linux-hyperv.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "dmitry.torokhov@gmail.com" <dmitry.torokhov@gmail.com>
To: Dexuan Cui <decui@microsoft.com>
Cc: "linux-input@vger.kernel.org" <linux-input@vger.kernel.org>,
	"linux-hyperv@vger.kernel.org" <linux-hyperv@vger.kernel.org>,
	Stephen Hemminger <sthemmin@microsoft.com>,
	Sasha Levin <Alexander.Levin@microsoft.com>,
	"sashal@kernel.org" <sashal@kernel.org>,
	Haiyang Zhang <haiyangz@microsoft.com>,
	KY Srinivasan <kys@microsoft.com>,
	Michael Kelley <mikelley@microsoft.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] Input: hyperv-keyboard: Use in-place iterator API in the channel callback
Date: Mon, 19 Aug 2019 20:18:05 -0700	[thread overview]
Message-ID: <20190820031805.GO121898@dtor-ws> (raw)
In-Reply-To: <1566270066-27546-1-git-send-email-decui@microsoft.com>

On Tue, Aug 20, 2019 at 03:01:23AM +0000, Dexuan Cui wrote:
> 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>
> ---
> 
> Hi Dmitry, 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.

Sure, no problem.

Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

> 
>  drivers/input/serio/hyperv-keyboard.c | 35 ++++++-----------------------------
>  1 file changed, 6 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/input/serio/hyperv-keyboard.c b/drivers/input/serio/hyperv-keyboard.c
> index 88ae7c2..e486a8a 100644
> --- a/drivers/input/serio/hyperv-keyboard.c
> +++ b/drivers/input/serio/hyperv-keyboard.c
> @@ -237,40 +237,17 @@ static void hv_kbd_handle_received_packet(struct hv_device *hv_dev,
>  
>  static void hv_kbd_on_channel_callback(void *context)
>  {
> +	struct vmpacket_descriptor *desc;
>  	struct hv_device *hv_dev = context;
> -	void *buffer;
> -	int bufferlen = 0x100; /* Start with sensible size */
>  	u32 bytes_recvd;
>  	u64 req_id;
> -	int error;
>  
> -	buffer = kmalloc(bufferlen, GFP_ATOMIC);
> -	if (!buffer)
> -		return;
> -
> -	while (1) {
> -		error = vmbus_recvpacket_raw(hv_dev->channel, buffer, bufferlen,
> -					     &bytes_recvd, &req_id);
> -		switch (error) {
> -		case 0:
> -			if (bytes_recvd == 0) {
> -				kfree(buffer);
> -				return;
> -			}
> -
> -			hv_kbd_handle_received_packet(hv_dev, buffer,
> -						      bytes_recvd, req_id);
> -			break;
> +	foreach_vmbus_pkt(desc, hv_dev->channel) {
> +		bytes_recvd = desc->len8 * 8;
> +		req_id = desc->trans_id;
>  
> -		case -ENOBUFS:
> -			kfree(buffer);
> -			/* Handle large packet */
> -			bufferlen = bytes_recvd;
> -			buffer = kmalloc(bytes_recvd, GFP_ATOMIC);
> -			if (!buffer)
> -				return;
> -			break;
> -		}
> +		hv_kbd_handle_received_packet(hv_dev, desc, bytes_recvd,
> +					      req_id);
>  	}
>  }
>  
> -- 
> 1.8.3.1
> 

-- 
Dmitry

  reply	other threads:[~2019-08-20  3:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-20  3:01 [PATCH] Input: hyperv-keyboard: Use in-place iterator API in the channel callback Dexuan Cui
2019-08-20  3:18 ` dmitry.torokhov [this message]
2019-08-20 15:29   ` Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190820031805.GO121898@dtor-ws \
    --to=dmitry.torokhov@gmail.com \
    --cc=Alexander.Levin@microsoft.com \
    --cc=decui@microsoft.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=haiyangz@microsoft.com \
    --cc=kys@microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mikelley@microsoft.com \
    --cc=sashal@kernel.org \
    --cc=sthemmin@microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).