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-input" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html