From: Joe Perches <joe@perches.com>
To: "K. Y. Srinivasan" <kys@microsoft.com>
Cc: gregkh@suse.de, linux-kernel@vger.kernel.org,
devel@linuxdriverproject.org, virtualization@lists.osdl.org,
dmitry.torokhov@gmail.com, linux-input@vger.kernel.org,
Haiyang Zhang <haiyangz@microsoft.com>
Subject: Re: [PATCH 1/1] Staging: hv: mousevsc: Move the mouse driver out of staging
Date: Fri, 14 Oct 2011 23:36:36 -0700 [thread overview]
Message-ID: <1318660596.6035.27.camel@Joe-Laptop> (raw)
In-Reply-To: <1318658907-16698-1-git-send-email-kys@microsoft.com>
On Fri, 2011-10-14 at 23:08 -0700, K. Y. Srinivasan wrote:
> In preparation for moving the mouse driver out of staging, seek community
> review of the mouse driver code.
>
> Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
> Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Just some stylistic things, none of which should
prevent any code movement.
> +++ b/drivers/hid/hv_mouse.c
[]
> +struct mousevsc_dev {
> + struct hv_device *device;
> + unsigned char init_complete;
bool?
[]
> +static void mousevsc_on_channel_callback(void *context)
> +{
> + const int packetSize = 0x100;
> + int ret = 0;
> + struct hv_device *device = (struct hv_device *)context;
> +
> + u32 bytes_recvd;
> + u64 req_id;
> + unsigned char packet[0x100];
[packetSize];
> + struct vmpacket_descriptor *desc;
> + unsigned char *buffer = packet;
> + int bufferlen = packetSize;
> +
> +
trivial extra blank line
> + do {
> + ret = vmbus_recvpacket_raw(device->channel, buffer,
> + bufferlen, &bytes_recvd, &req_id);
> +
> + if (ret == 0) {
> + if (bytes_recvd > 0) {
> + 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;
> + }
> +
> + /* reset */
> + if (bufferlen > packetSize) {
> + kfree(buffer);
> +
> + buffer = packet;
> + bufferlen = packetSize;
> + }
> + } else {
> + if (bufferlen > packetSize) {
> + kfree(buffer);
> +
> + buffer = packet;
> + bufferlen = packetSize;
> + }
> + break;
> + }
> + } else if (ret == -ENOBUFS) {
> + /* Handle large packet */
> + bufferlen = bytes_recvd;
> + buffer = kzalloc(bytes_recvd, GFP_ATOMIC);
> +
> + if (buffer == NULL) {
> + buffer = packet;
> + bufferlen = packetSize;
> + break;
> + }
> + }
> + } while (1);
This do {} while (1); seems like it could be simpler,
less indented and less confusing if it used continues
or gotos like below (if I wrote it correctly...)
loop:
ret = vmbus_bus_recvpacket_raw(device->channel, buffer,
bufferlen, &bytes_recvd, &req_id);
switch (ret) {
case -ENOBUFS:
/* Handle large packet */
bufferlen = bytes_recvd;
buffer = kzalloc(bytes_recvd, GFP_ATOMIC);
/*
Why kzalloc and not kmalloc?
The stack variable packet is not memset to 0,
why should buffer be zeroed?
*/
if (!buffer)
return;
goto loop;
case 0:
if (bytes_recvd <= 0)
goto loop;
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;
}
/* reset to original buffers */
if (bufferlen > packetSize) {
kfree(buffer);
buffer = packet;
bufferlen = packetSize;
}
}
goto loop;
}
> +
> +static int mousevsc_connect_to_vsp(struct hv_device *device)
> +{
[]
> + if (!response->response.approved) {
> + pr_err("synthhid protocol request failed (version %d)",
> + SYNTHHID_INPUT_VERSION);
Missing \n at end of format string
[]
> +static int mousevsc_on_device_add(struct hv_device *device)
> +{
[]
> + ret = vmbus_open(device->channel,
> + INPUTVSC_SEND_RING_BUFFER_SIZE,
> + INPUTVSC_RECV_RING_BUFFER_SIZE,
> + NULL,
> + 0,
> + mousevsc_on_channel_callback,
> + device
> + );
Nicer if aligned to open paren I think.
ret = vmbus_open(device->channel,
INPUTVSC_SEND_RING_BUFFER_SIZE,
INPUTVSC_RECV_RING_BUFFER_SIZE,
NULL, 0, mousevsc_on_channel_callback,
device);
next prev parent reply other threads:[~2011-10-15 6:36 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-15 6:08 [PATCH 1/1] Staging: hv: mousevsc: Move the mouse driver out of staging K. Y. Srinivasan
2011-10-15 6:36 ` Joe Perches [this message]
2011-10-15 13:24 ` KY Srinivasan
2011-10-16 22:28 ` Dan Carpenter
2011-10-16 23:03 ` Joe Perches
2011-10-23 7:24 ` Dmitry Torokhov
2011-10-23 14:33 ` KY Srinivasan
2011-10-23 15:45 ` KY Srinivasan
2011-10-27 0:09 ` Dmitry Torokhov
2011-10-27 1:19 ` KY Srinivasan
2011-10-27 4:31 ` Dmitry Torokhov
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=1318660596.6035.27.camel@Joe-Laptop \
--to=joe@perches.com \
--cc=devel@linuxdriverproject.org \
--cc=dmitry.torokhov@gmail.com \
--cc=gregkh@suse.de \
--cc=haiyangz@microsoft.com \
--cc=kys@microsoft.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=virtualization@lists.osdl.org \
/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