[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1318806187.1985.23.camel@Joe-Laptop>
Date: Sun, 16 Oct 2011 16:03:07 -0700
From: Joe Perches <joe@...ches.com>
To: Dan Carpenter <dan.carpenter@...cle.com>
Cc: "K. Y. Srinivasan" <kys@...rosoft.com>, dmitry.torokhov@...il.com,
Haiyang Zhang <haiyangz@...rosoft.com>, gregkh@...e.de,
linux-kernel@...r.kernel.org, virtualization@...ts.osdl.org,
linux-input@...r.kernel.org, devel@...uxdriverproject.org
Subject: Re: [PATCH 1/1] Staging: hv: mousevsc: Move the mouse driver out of
staging
On Mon, 2011-10-17 at 01:28 +0300, Dan Carpenter wrote:
> On Fri, Oct 14, 2011 at 11:36:36PM -0700, Joe Perches wrote:
[]
> > case 0:
> > if (bytes_recvd <= 0)
> > goto loop;
> In the original we called break here (which is equivelent to a
> return). Btw setting a stack variable and then returning immediately
> like the original code did is pointless.
OK, return it is.
Perhaps this is better. (two of the breaks could be goto loop)
I did add a couple of checks to make sure kmalloc'd
memory was always freed.
Another possible simplification is to always use kmalloc
instead of using stack and/or kmalloc.
static void mousevsc_on_channel_callback(void *context)
{
static const int packetSize = 0x100;
unsigned char packet[packetSize];
int ret;
struct hv_device *device = (struct hv_device *)context;
u32 bytes_recvd;
u64 req_id;
struct vmpacket_descriptor *desc;
unsigned char *buffer = packet;
int bufferlen = packetSize;
bool malloced = false;
loop:
ret = vmbus_bus_recvpacket_raw(device->channel, buffer, bufferlen,
&bytes_recvd, &req_id);
switch (ret) {
case -ENOBUFS: /* Handle large packet */
if (malloced) /* Maybe repeated -ENOBUFS ? */
kfree(buffer);
bufferlen = bytes_recvd;
buffer = kmalloc(bytes_recvd, GFP_ATOMIC);
if (!buffer)
return;
malloced = true;
break;
case 0:
if (bytes_recvd <= 0) {
if (malloced)
kfree(buffer);
return;
}
desc = (struct vmpacket_descriptor *)buffer;
switch (desc->type) {
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 (malloced) {
kfree(buffer);
malloced = false;
buffer = packet;
bufferlen = packetSize;
}
break;
}
goto loop;
}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists