linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: "K. Y. Srinivasan" <kys@microsoft.com>,
	dmitry.torokhov@gmail.com, Haiyang Zhang <haiyangz@microsoft.com>,
	gregkh@suse.de, linux-kernel@vger.kernel.org,
	virtualization@lists.osdl.org, linux-input@vger.kernel.org,
	devel@linuxdriverproject.org
Subject: Re: [PATCH 1/1] Staging: hv: mousevsc: Move the mouse driver out of staging
Date: Sun, 16 Oct 2011 16:03:07 -0700	[thread overview]
Message-ID: <1318806187.1985.23.camel@Joe-Laptop> (raw)
In-Reply-To: <20111016222847.GM18470@longonot.mountain>

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;
}

  reply	other threads:[~2011-10-16 23:03 UTC|newest]

Thread overview: 12+ 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
2011-10-15 13:24   ` KY Srinivasan
2011-10-16 22:28   ` Dan Carpenter
2011-10-16 23:03     ` Joe Perches [this message]
2011-10-19 23:48 ` KY Srinivasan
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=1318806187.1985.23.camel@Joe-Laptop \
    --to=joe@perches.com \
    --cc=dan.carpenter@oracle.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;
as well as URLs for NNTP newsgroup(s).