Skip to contentSkip to conversation

Staging: hv: mousevsc cleanup

PATCH In review K. Y. Srinivasan 2 participants 28 messages Sep 29, 2011 – Sep 30, 2011

Subsystems (2)
lore
Share & tools
lore
#4 lore raw

PATCH 4/24 Staging: hv: mousevsc: Change the allocation flags to reflect interrupt context

In reply to K. Y. Srinivasan

Change the allocation flags to reflect interrupt context.

---
 drivers/staging/hv/hv_mouse.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/staging/hv/hv_mouse.c +3 -3
index 016d7e5..b7cc164 100644
@@ -329,7 +329,7 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
 	desc = &device_info->hid_descriptor;
 	WARN_ON(desc->bLength == 0);
 
-	input_device->hid_desc = kzalloc(desc->bLength, GFP_KERNEL);
+	input_device->hid_desc = kzalloc(desc->bLength, GFP_ATOMIC);
 
 	if (!input_device->hid_desc) {
 		pr_err("unable to allocate hid descriptor - size %d",
@@ -342,7 +342,7 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
 	/* Save the report desc */
 	input_device->report_desc_size = desc->desc[0].wDescriptorLength;
 	input_device->report_desc = kzalloc(input_device->report_desc_size,
-					  GFP_KERNEL);
+					  GFP_ATOMIC);
 
 	if (!input_device->report_desc) {
 		pr_err("unable to allocate report descriptor - size %d",
@@ -541,7 +541,7 @@ static void mousevsc_on_channel_callback(void *context)
 		} else if (ret == -ENOBUFS) {
 			/* Handle large packet */
 			bufferlen = bytes_recvd;
-			buffer = kzalloc(bytes_recvd, GFP_KERNEL);
+			buffer = kzalloc(bytes_recvd, GFP_ATOMIC);
 
 			if (buffer == NULL) {
 				buffer = packet;
Signature · 1 line
1.7.4.1
#2 lore raw

PATCH 2/24 Staging: hv: mousevsc: Get rid of the struct input_device_context

In reply to K. Y. Srinivasan

The state maintained in struct input_device_context can easily be included in the struct mousevsc_dev structure. Simplify the code by consolidating the state.

---
 drivers/staging/hv/hv_mouse.c |   51 ++++++++++------------------------------
 1 files changed, 13 insertions(+), 38 deletions(-)
drivers/staging/hv/hv_mouse.c +13 -38
index 44a2b23..69eb00e 100644
@@ -172,15 +172,11 @@ struct mousevsc_dev {
 	unsigned char		*report_desc;
 	u32			report_desc_size;
 	struct hv_input_dev_info hid_dev_info;
-};
-
-struct input_device_context {
-	struct hv_device	*device_ctx;
-	struct hid_device	*hid_device;
-	struct hv_input_dev_info device_info;
 	int			connected;
+	struct hid_device       *hid_device;
 };
 
+
 static struct mousevsc_dev *alloc_input_device(struct hv_device *device)
 {
 	struct mousevsc_dev *input_dev;
@@ -402,7 +398,6 @@ static void mousevsc_on_receive_input_report(struct mousevsc_dev *input_device,
 				struct synthhid_input_report *input_report)
 {
 	struct hv_driver *input_drv;
-	struct input_device_context *input_dev_ctx;
 
 	if (!input_device->init_complete) {
 		pr_info("Initialization incomplete...ignoring input_report msg");
@@ -411,9 +406,8 @@ static void mousevsc_on_receive_input_report(struct mousevsc_dev *input_device,
 
 	input_drv = drv_to_hv_drv(input_device->device->device.driver);
 
-	input_dev_ctx = dev_get_drvdata(&input_device->device->device);
 
-	hid_input_report(input_dev_ctx->hid_device,
+	hid_input_report(input_device->hid_device,
 			      HID_INPUT_REPORT, input_report->buffer, input_report->header.size, 1);
 
 }
@@ -662,9 +656,8 @@ static void mousevsc_hid_close(struct hid_device *hid)
 
 static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len)
 {
-	struct input_device_context *input_device_ctx =
-		dev_get_drvdata(&dev->device);
 	struct hid_device *hid_dev;
+	struct mousevsc_dev *input_device = hv_get_drvdata(dev);
 
 	/* hid_debug = -1; */
 	hid_dev = kmalloc(sizeof(struct hid_device), GFP_KERNEL);
@@ -681,9 +674,9 @@ static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len)
 		hid_dev->ll_driver->close = mousevsc_hid_close;
 
 		hid_dev->bus = BUS_VIRTUAL;
-		hid_dev->vendor = input_device_ctx->device_info.vendor;
-		hid_dev->product = input_device_ctx->device_info.product;
-		hid_dev->version = input_device_ctx->device_info.version;
+		hid_dev->vendor = input_device->hid_dev_info.vendor;
+		hid_dev->product = input_device->hid_dev_info.product;
+		hid_dev->version = input_device->hid_dev_info.version;
 		hid_dev->dev = dev->device;
 
 		sprintf(hid_dev->name, "%s",
@@ -695,7 +688,7 @@ static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len)
 		if (!hidinput_connect(hid_dev, 0)) {
 			hid_dev->claimed |= HID_CLAIMED_INPUT;
 
-			input_device_ctx->connected = 1;
+			input_device->connected = 1;
 
 			DPRINT_INFO(INPUTVSC_DRV,
 				     "HID device claimed by input\n");
@@ -707,7 +700,7 @@ static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len)
 				    "input or hiddev\n");
 		}
 
-		input_device_ctx->hid_device = hid_dev;
+		input_device->hid_device = hid_dev;
 	}
 
 	kfree(hid_dev);
@@ -719,8 +712,6 @@ static int mousevsc_on_device_add(struct hv_device *device,
 	int ret = 0;
 	struct mousevsc_dev *input_dev;
 	struct hv_driver *input_drv;
-	struct hv_input_dev_info dev_info;
-	struct input_device_context *input_device_ctx;
 
 	input_dev = alloc_input_device(device);
 
@@ -761,14 +752,7 @@ static int mousevsc_on_device_add(struct hv_device *device,
 
 	input_drv = drv_to_hv_drv(input_dev->device->device.driver);
 
-	dev_info.vendor = input_dev->hid_dev_info.vendor;
-	dev_info.product = input_dev->hid_dev_info.product;
-	dev_info.version = input_dev->hid_dev_info.version;
 
-	/* Send the device info back up */
-	input_device_ctx = dev_get_drvdata(&device->device);
-	memcpy(&input_device_ctx->device_info, &dev_info,
-	       sizeof(struct hv_input_dev_info));
 
 	/* Send the report desc back up */
 	/* workaround SA-167 */
@@ -828,12 +812,6 @@ static int mousevsc_probe(struct hv_device *dev,
 {
 	int ret = 0;
 
-	struct input_device_context *input_dev_ctx;
-
-	input_dev_ctx = kmalloc(sizeof(struct input_device_context),
-				GFP_KERNEL);
-
-	dev_set_drvdata(&dev->device, input_dev_ctx);
 
 	/* Call to the vsc driver to add the device */
 	ret = mousevsc_on_device_add(dev, NULL);
@@ -849,13 +827,12 @@ static int mousevsc_probe(struct hv_device *dev,
 
 static int mousevsc_remove(struct hv_device *dev)
 {
-	struct input_device_context *input_dev_ctx;
+	struct mousevsc_dev *input_dev = hv_get_drvdata(dev);
 	int ret;
 
-	input_dev_ctx = dev_get_drvdata(&dev->device);
-	if (input_dev_ctx->connected) {
-		hidinput_disconnect(input_dev_ctx->hid_device);
-		input_dev_ctx->connected = 0;
+	if (input_dev->connected) {
+		hidinput_disconnect(input_dev->hid_device);
+		input_dev->connected = 0;
 	}
 
 	/*
@@ -868,8 +845,6 @@ static int mousevsc_remove(struct hv_device *dev)
 			   "unable to remove vsc device (ret %d)", ret);
 	}
 
-	kfree(input_dev_ctx);
-
 	return ret;
 }
 
Signature · 1 line
1.7.4.1
#7 lore raw

PATCH 7/24 Staging: hv: mousevsc: Use completion primitive to synchronize

In reply to K. Y. Srinivasan

Use completion primitive to synchronize.

---
 drivers/staging/hv/hv_mouse.c |   30 ++++++++++--------------------
 1 files changed, 10 insertions(+), 20 deletions(-)
drivers/staging/hv/hv_mouse.c +10 -20
index 74faa26..ea9e1f3 100644
@@ -162,10 +162,7 @@ struct mousevsc_dev {
 	struct mousevsc_prt_msg	protocol_req;
 	struct mousevsc_prt_msg	protocol_resp;
 	/* Synchronize the request/response if needed */
-	wait_queue_head_t	protocol_wait_event;
-	wait_queue_head_t	dev_info_wait_event;
-	int			protocol_wait_condition;
-	int			device_wait_condition;
+	struct completion	wait_event;
 	int			dev_info_status;
 
 	struct hid_descriptor	*hid_desc;
@@ -194,6 +191,7 @@ static struct mousevsc_dev *alloc_input_device(struct hv_device *device)
 
 	input_dev->device = device;
 	hv_set_drvdata(device, input_dev);
+	init_completion(&input_dev->wait_event);
 
 	return input_dev;
 }
@@ -379,8 +377,7 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
 		goto cleanup;
 	}
 
-	input_device->device_wait_condition = 1;
-	wake_up(&input_device->dev_info_wait_event);
+	complete(&input_device->wait_event);
 
 	return;
 
@@ -392,8 +389,7 @@ cleanup:
 	input_device->report_desc = NULL;
 
 	input_device->dev_info_status = -1;
-	input_device->device_wait_condition = 1;
-	wake_up(&input_device->dev_info_wait_event);
+	complete(&input_device->wait_event);
 }
 
 static void mousevsc_on_receive_input_report(struct mousevsc_dev *input_device,
@@ -444,8 +440,7 @@ static void mousevsc_on_receive(struct hv_device *device,
 		memcpy(&input_dev->protocol_resp, pipe_msg,
 		       pipe_msg->size + sizeof(struct pipe_prt_msg) -
 		       sizeof(unsigned char));
-		input_dev->protocol_wait_condition = 1;
-		wake_up(&input_dev->protocol_wait_event);
+		complete(&input_dev->wait_event);
 		break;
 
 	case SynthHidInitialDeviceInfo:
@@ -565,6 +560,7 @@ static void mousevsc_on_channel_callback(void *context)
 static int mousevsc_connect_to_vsp(struct hv_device *device)
 {
 	int ret = 0;
+	int t;
 	struct mousevsc_dev *input_dev;
 	struct mousevsc_prt_msg *request;
 	struct mousevsc_prt_msg *response;
@@ -576,8 +572,6 @@ static int mousevsc_connect_to_vsp(struct hv_device *device)
 		return -1;
 	}
 
-	init_waitqueue_head(&input_dev->protocol_wait_event);
-	init_waitqueue_head(&input_dev->dev_info_wait_event);
 
 	request = &input_dev->protocol_req;
 
@@ -607,10 +601,8 @@ static int mousevsc_connect_to_vsp(struct hv_device *device)
 		goto cleanup;
 	}
 
-	input_dev->protocol_wait_condition = 0;
-	wait_event_timeout(input_dev->protocol_wait_event,
-		input_dev->protocol_wait_condition, msecs_to_jiffies(1000));
-	if (input_dev->protocol_wait_condition == 0) {
+	t = wait_for_completion_timeout(&input_dev->wait_event, 5*HZ);
+	if (t == 0) {
 		ret = -ETIMEDOUT;
 		goto cleanup;
 	}
@@ -624,10 +616,8 @@ static int mousevsc_connect_to_vsp(struct hv_device *device)
 		goto cleanup;
 	}
 
-	input_dev->device_wait_condition = 0;
-	wait_event_timeout(input_dev->dev_info_wait_event,
-		input_dev->device_wait_condition, msecs_to_jiffies(1000));
-	if (input_dev->device_wait_condition == 0) {
+	t = wait_for_completion_timeout(&input_dev->wait_event, 5*HZ);
+	if (t == 0) {
 		ret = -ETIMEDOUT;
 		goto cleanup;
 	}
Signature · 1 line
1.7.4.1
#9 lore raw

PATCH 9/24 Staging: hv: mousevsc: Get rid of unnecessary DPRINT calls

In reply to K. Y. Srinivasan

Get rid of unnecessary DPRINT calls.

---
 drivers/staging/hv/hv_mouse.c |   18 +++---------------
 1 files changed, 3 insertions(+), 15 deletions(-)
drivers/staging/hv/hv_mouse.c +3 -15
index 8d94aef..8dd902a 100644
@@ -665,10 +665,8 @@ static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len)
 	hid_dev->ll_driver = &mousevsc_ll_driver;
 	hid_dev->driver = &mousevsc_hid_driver;
 
-	if (hid_parse_report(hid_dev, packet, len)) {
-		DPRINT_INFO(INPUTVSC_DRV, "Unable to call hd_parse_report");
+	if (hid_parse_report(hid_dev, packet, len))
 		return;
-	}
 
 	hid_dev->bus = BUS_VIRTUAL;
 	hid_dev->vendor = input_device->hid_dev_info.vendor;
@@ -797,11 +795,8 @@ static int mousevsc_probe(struct hv_device *dev,
 	/* Call to the vsc driver to add the device */
 	ret = mousevsc_on_device_add(dev, NULL);
 
-	if (ret != 0) {
-		DPRINT_ERR(INPUTVSC_DRV, "unable to add input vsc device");
-
+	if (ret != 0)
 		return -1;
-	}
 
 	return 0;
 }
@@ -809,7 +804,6 @@ static int mousevsc_probe(struct hv_device *dev,
 static int mousevsc_remove(struct hv_device *dev)
 {
 	struct mousevsc_dev *input_dev = hv_get_drvdata(dev);
-	int ret;
 
 	if (input_dev->connected) {
 		hidinput_disconnect(input_dev->hid_device);
@@ -821,13 +815,7 @@ static int mousevsc_remove(struct hv_device *dev)
 	 * Call to the vsc driver to let it know that the device
 	 * is being removed
 	 */
-	ret = mousevsc_on_device_remove(dev);
-	if (ret != 0) {
-		DPRINT_ERR(INPUTVSC_DRV,
-			   "unable to remove vsc device (ret %d)", ret);
-	}
-
-	return ret;
+	return mousevsc_on_device_remove(dev);
 }
 
 static const struct hv_vmbus_device_id id_table[] = {
Signature · 1 line
1.7.4.1
#24 lore raw

PATCH 24/24 Staging: hv: mousevsc: Get rid of unnecessary comments

In reply to K. Y. Srinivasan

Get rid of unnecessary comments.

---
 drivers/staging/hv/hv_mouse.c |   21 ---------------------
 1 files changed, 0 insertions(+), 21 deletions(-)
drivers/staging/hv/hv_mouse.c +0 -21
index 71b460b..edbb479 100644
@@ -26,9 +26,6 @@
 #include "hyperv.h"
 
 
-/*
- * Data types
- */
 struct hv_input_dev_info {
 	unsigned int size;
 	unsigned short vendor;
@@ -137,9 +134,6 @@ struct pipe_prt_msg {
 	char data[1];
 };
 
-/*
- * Data types
- */
 struct  mousevsc_prt_msg {
 	enum pipe_prot_msg_type type;
 	u32 size;
@@ -206,11 +200,9 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
 	/* Assume success for now */
 	input_device->dev_info_status = 0;
 
-	/* Save the device attr */
 	memcpy(&input_device->hid_dev_info, &device_info->hid_dev_info,
 		sizeof(struct hv_input_dev_info));
 
-	/* Save the hid desc */
 	desc = &device_info->hid_descriptor;
 	WARN_ON(desc->bLength == 0);
 
@@ -221,7 +213,6 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
 
 	memcpy(input_device->hid_desc, desc, desc->bLength);
 
-	/* Save the report desc */
 	input_device->report_desc_size = desc->desc[0].wDescriptorLength;
 	if (input_device->report_desc_size == 0)
 		goto cleanup;
@@ -368,10 +359,6 @@ static void mousevsc_on_channel_callback(void *context)
 					bufferlen = packetSize;
 				}
 			} else {
-				/*
-				 * pr_debug("nothing else to read...");
-				 * reset
-				 */
 				if (bufferlen > packetSize) {
 					kfree(buffer);
 
@@ -388,8 +375,6 @@ static void mousevsc_on_channel_callback(void *context)
 			if (buffer == NULL) {
 				buffer = packet;
 				bufferlen = packetSize;
-
-				/* Try again next time around */
 				break;
 			}
 		}
@@ -409,9 +394,6 @@ static int mousevsc_connect_to_vsp(struct hv_device *device)
 
 	request = &input_dev->protocol_req;
 
-	/*
-	 * Now, initiate the vsc/vsp initialization protocol on the open channel
-	 */
 	memset(request, 0, sizeof(struct mousevsc_prt_msg));
 
 	request->type = PIPE_MESSAGE_DATA;
@@ -525,7 +507,6 @@ static int mousevsc_on_device_add(struct hv_device *device)
 
 	input_dev->init_complete = false;
 
-	/* Open the channel */
 	ret = vmbus_open(device->channel,
 		INPUTVSC_SEND_RING_BUFFER_SIZE,
 		INPUTVSC_RECV_RING_BUFFER_SIZE,
@@ -550,7 +531,6 @@ static int mousevsc_on_device_add(struct hv_device *device)
 	}
 
 
-	/* Send the report desc back up */
 	/* workaround SA-167 */
 	if (input_dev->report_desc[14] == 0x25)
 		input_dev->report_desc[14] = 0x29;
@@ -567,7 +547,6 @@ static int mousevsc_probe(struct hv_device *dev,
 			const struct hv_vmbus_device_id *dev_id)
 {
 
-	/* Call to the vsc driver to add the device */
 	return mousevsc_on_device_add(dev);
 
 }
Signature · 1 line
1.7.4.1
#23 lore raw

PATCH 23/24 Staging: hv: mousevsc: Enable autoloading of the mouse driver

In reply to K. Y. Srinivasan

Now that the mouse driver is functional, enable the auto-loading of the driver.

---
 drivers/staging/hv/hv_mouse.c |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)
drivers/staging/hv/hv_mouse.c +1 -4
index 98ae062..71b460b 100644
@@ -596,10 +596,7 @@ static const struct hv_vmbus_device_id id_table[] = {
 	{ },
 };
 
-/*
- * The mouse driver is not functional; do not auto-load it.
- */
-/* MODULE_DEVICE_TABLE(vmbus, id_table); */
+MODULE_DEVICE_TABLE(vmbus, id_table);
 
 static struct  hv_driver mousevsc_drv = {
 	.name = "mousevsc",
Signature · 1 line
1.7.4.1
#21 lore raw

PATCH 21/24 Staging: hv: mousevsc: Get rid of mousevsc_on_receive_input_report() by inlining

In reply to K. Y. Srinivasan

Get rid of mousevsc_on_receive_input_report() by inlining the code.

---
 drivers/staging/hv/hv_mouse.c |   27 ++++++++-------------------
 1 files changed, 8 insertions(+), 19 deletions(-)
drivers/staging/hv/hv_mouse.c +8 -19
index 6621326..a526ba5 100644
@@ -270,28 +270,13 @@ cleanup:
 	complete(&input_device->wait_event);
 }
 
-static void mousevsc_on_receive_input_report(struct mousevsc_dev *input_device,
-				struct synthhid_input_report *input_report)
-{
-	struct hv_driver *input_drv;
-
-	if (!input_device->init_complete)
-		return;
-
-	input_drv = drv_to_hv_drv(input_device->device->device.driver);
-
-
-	hid_input_report(input_device->hid_device,
-			      HID_INPUT_REPORT, input_report->buffer, input_report->header.size, 1);
-
-}
-
 static void mousevsc_on_receive(struct hv_device *device,
 				struct vmpacket_descriptor *packet)
 {
 	struct pipe_prt_msg *pipe_msg;
 	struct synthhid_msg *hid_msg;
 	struct mousevsc_dev *input_dev = hv_get_drvdata(device);
+	struct synthhid_input_report *input_report;
 
 	pipe_msg = (struct pipe_prt_msg *)((unsigned long)packet +
 						(packet->offset8 << 3));
@@ -320,9 +305,13 @@ static void mousevsc_on_receive(struct hv_device *device,
 			(struct synthhid_device_info *)&pipe_msg->data[0]);
 		break;
 	case SYNTH_HID_INPUT_REPORT:
-		mousevsc_on_receive_input_report(input_dev,
-			(struct synthhid_input_report *)&pipe_msg->data[0]);
-
+		input_report =
+			(struct synthhid_input_report *)&pipe_msg->data[0];
+		if (!input_dev->init_complete)
+			break;
+		hid_input_report(input_dev->hid_device,
+				HID_INPUT_REPORT, input_report->buffer,
+				input_report->header.size, 1);
 		break;
 	default:
 		pr_err("unsupported hid msg type - type %d len %d",
Signature · 1 line
1.7.4.1
#19 lore raw

PATCH 19/24 Staging: hv: mousevsc: Get rid of ref_count state in struct mousevsc_dev

In reply to K. Y. Srinivasan

Now get rid of the machinery for managing the life-cycle of the mousevsc_dev as this is not needed.

---
 drivers/staging/hv/hv_mouse.c |   54 ++--------------------------------------
 1 files changed, 3 insertions(+), 51 deletions(-)
drivers/staging/hv/hv_mouse.c +3 -51
index 317d2be..e57e0b4 100644
@@ -155,8 +155,6 @@ struct  mousevsc_prt_msg {
  */
 struct mousevsc_dev {
 	struct hv_device	*device;
-	/* 0 indicates the device is being destroyed */
-	atomic_t		ref_count;
 	unsigned char		init_complete;
 	struct mousevsc_prt_msg	protocol_req;
 	struct mousevsc_prt_msg	protocol_resp;
@@ -182,12 +180,6 @@ static struct mousevsc_dev *alloc_input_device(struct hv_device *device)
 	if (!input_dev)
 		return NULL;
 
-	/*
-	 * Set to 2 to allow both inbound and outbound traffics
-	 * (ie get_input_device() and must_get_input_device()) to proceed.
-	 */
-	atomic_set(&input_dev->ref_count, 2);
-
 	input_dev->device = device;
 	hv_set_drvdata(device, input_dev);
 	init_completion(&input_dev->wait_event);
@@ -203,32 +195,6 @@ static void free_input_device(struct mousevsc_dev *device)
 	kfree(device);
 }
 
-/*
- * Get the inputdevice object iff exists and its refcount > 0
- */
-static struct mousevsc_dev *must_get_input_device(struct hv_device *device)
-{
-	struct mousevsc_dev *input_dev;
-
-	input_dev = hv_get_drvdata(device);
-
-	if (input_dev && atomic_read(&input_dev->ref_count))
-		atomic_inc(&input_dev->ref_count);
-	else
-		input_dev = NULL;
-
-	return input_dev;
-}
-
-static void put_input_device(struct hv_device *device)
-{
-	struct mousevsc_dev *input_dev;
-
-	input_dev = hv_get_drvdata(device);
-
-	atomic_dec(&input_dev->ref_count);
-}
-
 
 static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
 				struct synthhid_device_info *device_info)
@@ -325,19 +291,13 @@ static void mousevsc_on_receive(struct hv_device *device,
 {
 	struct pipe_prt_msg *pipe_msg;
 	struct synthhid_msg *hid_msg;
-	struct mousevsc_dev *input_dev;
-
-	input_dev = must_get_input_device(device);
-	if (!input_dev)
-		return;
+	struct mousevsc_dev *input_dev = hv_get_drvdata(device);
 
 	pipe_msg = (struct pipe_prt_msg *)((unsigned long)packet +
 						(packet->offset8 << 3));
 
-	if (pipe_msg->type != PipeMessageData) {
-		put_input_device(device);
-		return ;
-	}
+	if (pipe_msg->type != PipeMessageData)
+		return;
 
 	hid_msg = (struct synthhid_msg *)&pipe_msg->data[0];
 
@@ -370,7 +330,6 @@ static void mousevsc_on_receive(struct hv_device *device,
 		break;
 	}
 
-	put_input_device(device);
 }
 
 static void mousevsc_on_channel_callback(void *context)
@@ -378,7 +337,6 @@ static void mousevsc_on_channel_callback(void *context)
 	const int packetSize = 0x100;
 	int ret = 0;
 	struct hv_device *device = (struct hv_device *)context;
-	struct mousevsc_dev *input_dev;
 
 	u32 bytes_recvd;
 	u64 req_id;
@@ -387,10 +345,6 @@ static void mousevsc_on_channel_callback(void *context)
 	unsigned char	*buffer = packet;
 	int	bufferlen = packetSize;
 
-	input_dev = must_get_input_device(device);
-
-	if (!input_dev)
-		return;
 
 	do {
 		ret = vmbus_recvpacket_raw(device->channel, buffer,
@@ -452,8 +406,6 @@ static void mousevsc_on_channel_callback(void *context)
 		}
 	} while (1);
 
-	put_input_device(device);
-
 	return;
 }
 
Signature · 1 line
1.7.4.1
#17 lore raw

PATCH 17/24 Staging: hv: mousevsc: Get rid of mousevsc_on_device_remove() by inlining code

In reply to K. Y. Srinivasan

Get rid of mousevsc_on_device_remove() by inlining code.

---
 drivers/staging/hv/hv_mouse.c |   47 ++++++++++++++--------------------------
 1 files changed, 17 insertions(+), 30 deletions(-)
drivers/staging/hv/hv_mouse.c +17 -30
index 75ea2db..5324429 100644
@@ -660,33 +660,6 @@ static int mousevsc_on_device_add(struct hv_device *device,
 	return ret;
 }
 
-static int mousevsc_on_device_remove(struct hv_device *device)
-{
-	struct mousevsc_dev *input_dev;
-	int ret = 0;
-
-
-	input_dev = release_input_device(device);
-
-
-	/*
-	 * At this point, all outbound traffic should be disable. We only
-	 * allow inbound traffic (responses) to proceed
-	 *
-	 * so that outstanding requests can be completed.
-	 */
-
-	input_dev = final_release_input_device(device);
-
-	/* Close the channel */
-	vmbus_close(device->channel);
-
-	free_input_device(input_dev);
-
-	return ret;
-}
-
-
 static int mousevsc_probe(struct hv_device *dev,
 			const struct hv_vmbus_device_id *dev_id)
 {
@@ -706,11 +679,25 @@ static int mousevsc_remove(struct hv_device *dev)
 		hid_destroy_device(input_dev->hid_device);
 	}
 
+
+	release_input_device(dev);
+
+
 	/*
-	 * Call to the vsc driver to let it know that the device
-	 * is being removed
+	 * At this point, all outbound traffic should be disable. We only
+	 * allow inbound traffic (responses) to proceed
+	 *
+	 * so that outstanding requests can be completed.
 	 */
-	return mousevsc_on_device_remove(dev);
+
+	input_dev = final_release_input_device(dev);
+
+	/* Close the channel */
+	vmbus_close(dev->channel);
+
+	free_input_device(input_dev);
+
+	return 0;
 }
 
 static const struct hv_vmbus_device_id id_table[] = {
Signature · 1 line
1.7.4.1
#15 lore raw

PATCH 15/24 Staging: hv: mousevsc: Get rid of mousevsc_on_send_completion()

In reply to K. Y. Srinivasan

We don't need to handle the "send complete" callback - nothing needs to be done here; get rid of the code.

---
 drivers/staging/hv/hv_mouse.c |   21 ---------------------
 1 files changed, 0 insertions(+), 21 deletions(-)
drivers/staging/hv/hv_mouse.c +0 -21
index 38e31ae..fc0ba68 100644
@@ -288,25 +288,6 @@ static struct mousevsc_dev *final_release_input_device(struct hv_device *device)
 	return input_dev;
 }
 
-static void mousevsc_on_send_completion(struct hv_device *device,
-					struct vmpacket_descriptor *packet)
-{
-	struct mousevsc_dev *input_dev;
-	void *request;
-
-	input_dev = must_get_input_device(device);
-	if (!input_dev)
-		return;
-
-	request = (void *)(unsigned long)packet->trans_id;
-
-	if (request == &input_dev->protocol_req) {
-		/* FIXME */
-		/* Shouldn't we be doing something here? */
-	}
-
-	put_input_device(device);
-}
 
 static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
 				struct synthhid_device_info *device_info)
@@ -480,8 +461,6 @@ static void mousevsc_on_channel_callback(void *context)
 
 				switch (desc->type) {
 				case VM_PKT_COMP:
-					mousevsc_on_send_completion(
-						device, desc);
 					break;
 
 				case VM_PKT_DATA_INBAND:
Signature · 1 line
1.7.4.1
#11 lore raw

PATCH 11/24 Staging: hv: mousevsc: Get rid of unnecessary pr_* calls

In reply to K. Y. Srinivasan

Get rid of unnecessary pr_* calls.

---
 drivers/staging/hv/hv_mouse.c |   64 +++++++----------------------------------
 1 files changed, 11 insertions(+), 53 deletions(-)
drivers/staging/hv/hv_mouse.c +11 -53
index fc1f3e6..57bc4a3 100644
@@ -294,10 +294,8 @@ static void mousevsc_on_send_completion(struct hv_device *device,
 	void *request;
 
 	input_dev = must_get_input_device(device);
-	if (!input_dev) {
-		pr_err("unable to get input device...device being destroyed?");
+	if (!input_dev)
 		return;
-	}
 
 	request = (void *)(unsigned long)packet->trans_id;
 
@@ -329,11 +327,8 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
 
 	input_device->hid_desc = kzalloc(desc->bLength, GFP_ATOMIC);
 
-	if (!input_device->hid_desc) {
-		pr_err("unable to allocate hid descriptor - size %d",
-			 desc->bLength);
+	if (!input_device->hid_desc)
 		goto cleanup;
-	}
 
 	memcpy(input_device->hid_desc, desc, desc->bLength);
 
@@ -344,11 +339,8 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
 	input_device->report_desc = kzalloc(input_device->report_desc_size,
 					  GFP_ATOMIC);
 
-	if (!input_device->report_desc) {
-		pr_err("unable to allocate report descriptor - size %d",
-			   input_device->report_desc_size);
+	if (!input_device->report_desc)
 		goto cleanup;
-	}
 
 	memcpy(input_device->report_desc,
 	       ((unsigned char *)desc) + desc->bLength,
@@ -371,11 +363,8 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
 			(unsigned long)&ack,
 			VM_PKT_DATA_INBAND,
 			VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
-	if (ret != 0) {
-		pr_err("unable to send synthhid device info ack - ret %d",
-			   ret);
+	if (ret != 0)
 		goto cleanup;
-	}
 
 	complete(&input_device->wait_event);
 
@@ -397,10 +386,8 @@ static void mousevsc_on_receive_input_report(struct mousevsc_dev *input_device,
 {
 	struct hv_driver *input_drv;
 
-	if (!input_device->init_complete) {
-		pr_info("Initialization incomplete...ignoring input_report msg");
+	if (!input_device->init_complete)
 		return;
-	}
 
 	input_drv = drv_to_hv_drv(input_device->device->device.driver);
 
@@ -418,17 +405,13 @@ static void mousevsc_on_receive(struct hv_device *device,
 	struct mousevsc_dev *input_dev;
 
 	input_dev = must_get_input_device(device);
-	if (!input_dev) {
-		pr_err("unable to get input device...device being destroyed?");
+	if (!input_dev)
 		return;
-	}
 
 	pipe_msg = (struct pipe_prt_msg *)((unsigned long)packet +
 						(packet->offset8 << 3));
 
 	if (pipe_msg->type != PipeMessageData) {
-		pr_err("unknown pipe msg type - type %d len %d",
-			   pipe_msg->type, pipe_msg->size);
 		put_input_device(device);
 		return ;
 	}
@@ -483,10 +466,8 @@ static void mousevsc_on_channel_callback(void *context)
 
 	input_dev = must_get_input_device(device);
 
-	if (!input_dev) {
-		pr_err("unable to get input device...device being destroyed?");
+	if (!input_dev)
 		return;
-	}
 
 	do {
 		ret = vmbus_recvpacket_raw(device->channel, buffer,
@@ -545,8 +526,6 @@ static void mousevsc_on_channel_callback(void *context)
 				bufferlen = packetSize;
 
 				/* Try again next time around */
-				pr_err("unable to allocate buffer of size %d!",
-				       bytes_recvd);
 				break;
 			}
 		}
@@ -567,10 +546,8 @@ static int mousevsc_connect_to_vsp(struct hv_device *device)
 
 	input_dev = get_input_device(device);
 
-	if (!input_dev) {
-		pr_err("unable to get input device...device being destroyed?");
+	if (!input_dev)
 		return -ENODEV;
-	}
 
 
 	request = &input_dev->protocol_req;
@@ -587,7 +564,6 @@ static int mousevsc_connect_to_vsp(struct hv_device *device)
 	request->request.header.size = sizeof(unsigned int);
 	request->request.version_requested.version = SYNTHHID_INPUT_VERSION;
 
-	pr_info("synthhid protocol request...");
 
 	ret = vmbus_sendpacket(device->channel, request,
 				sizeof(struct pipe_prt_msg) -
@@ -596,10 +572,8 @@ static int mousevsc_connect_to_vsp(struct hv_device *device)
 				(unsigned long)request,
 				VM_PKT_DATA_INBAND,
 				VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
-	if (ret != 0) {
-		pr_err("unable to send synthhid protocol request.");
+	if (ret != 0)
 		goto cleanup;
-	}
 
 	t = wait_for_completion_timeout(&input_dev->wait_event, 5*HZ);
 	if (t == 0) {
@@ -626,9 +600,7 @@ static int mousevsc_connect_to_vsp(struct hv_device *device)
 	 * We should have gotten the device attr, hid desc and report
 	 * desc at this point
 	 */
-	if (!input_dev->dev_info_status)
-		pr_info("**** input channel up and running!! ****");
-	else
+	if (input_dev->dev_info_status)
 		ret = -ENOMEM;
 
 cleanup:
@@ -710,18 +682,14 @@ static int mousevsc_on_device_add(struct hv_device *device,
 		);
 
 	if (ret != 0) {
-		pr_err("unable to open channel: %d", ret);
 		free_input_device(input_dev);
 		return ret;
 	}
 
-	pr_info("InputVsc channel open: %d", ret);
 
 	ret = mousevsc_connect_to_vsp(device);
 
 	if (ret != 0) {
-		pr_err("unable to connect channel: %d", ret);
-
 		vmbus_close(device->channel);
 		free_input_device(input_dev);
 		return ret;
@@ -749,8 +717,6 @@ static int mousevsc_on_device_remove(struct hv_device *device)
 	struct mousevsc_dev *input_dev;
 	int ret = 0;
 
-	pr_info("disabling input device (%p)...",
-		    hv_get_drvdata(device));
 
 	input_dev = release_input_device(device);
 
@@ -761,19 +727,11 @@ static int mousevsc_on_device_remove(struct hv_device *device)
 	 *
 	 * so that outstanding requests can be completed.
 	 */
-	while (input_dev->num_outstanding_req) {
-		pr_info("waiting for %d requests to complete...",
-			input_dev->num_outstanding_req);
-
+	while (input_dev->num_outstanding_req)
 		udelay(100);
-	}
-
-	pr_info("removing input device (%p)...", hv_get_drvdata(device));
 
 	input_dev = final_release_input_device(device);
 
-	pr_info("input device (%p) safe to remove", input_dev);
-
 	/* Close the channel */
 	vmbus_close(device->channel);
 
Signature · 1 line
1.7.4.1
#12 lore raw

PATCH 12/24 Staging: hv: mousevsc: Free allocated memory in free_input_device()

In reply to K. Y. Srinivasan

Free all allocated memory in free_input_device().

---
 drivers/staging/hv/hv_mouse.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/staging/hv/hv_mouse.c +2 -0
index 57bc4a3..326d972 100644
@@ -199,6 +199,8 @@ static struct mousevsc_dev *alloc_input_device(struct hv_device *device)
 static void free_input_device(struct mousevsc_dev *device)
 {
 	WARN_ON(atomic_read(&device->ref_count) != 0);
+	kfree(device->hid_desc);
+	kfree(device->report_desc);
 	kfree(device);
 }
 
Signature · 1 line
1.7.4.1
#10 lore raw

PATCH 10/24 Staging: hv: mousevsc: Cleanup error handling

In reply to K. Y. Srinivasan

Cleanup error handling in this driver; use standard Linux error codes.

---
 drivers/staging/hv/hv_mouse.c |   23 +++++++----------------
 1 files changed, 7 insertions(+), 16 deletions(-)
drivers/staging/hv/hv_mouse.c +7 -16
index 8dd902a..fc1f3e6 100644
@@ -569,7 +569,7 @@ static int mousevsc_connect_to_vsp(struct hv_device *device)
 
 	if (!input_dev) {
 		pr_err("unable to get input device...device being destroyed?");
-		return -1;
+		return -ENODEV;
 	}
 
 
@@ -612,7 +612,7 @@ 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);
-		ret = -1;
+		ret = -ENODEV;
 		goto cleanup;
 	}
 
@@ -629,7 +629,7 @@ static int mousevsc_connect_to_vsp(struct hv_device *device)
 	if (!input_dev->dev_info_status)
 		pr_info("**** input channel up and running!! ****");
 	else
-		ret = -1;
+		ret = -ENOMEM;
 
 cleanup:
 	put_input_device(device);
@@ -694,10 +694,8 @@ static int mousevsc_on_device_add(struct hv_device *device,
 
 	input_dev = alloc_input_device(device);
 
-	if (!input_dev) {
-		ret = -1;
-		goto cleanup;
-	}
+	if (!input_dev)
+		return -ENOMEM;
 
 	input_dev->init_complete = false;
 
@@ -714,7 +712,7 @@ static int mousevsc_on_device_add(struct hv_device *device,
 	if (ret != 0) {
 		pr_err("unable to open channel: %d", ret);
 		free_input_device(input_dev);
-		return -1;
+		return ret;
 	}
 
 	pr_info("InputVsc channel open: %d", ret);
@@ -743,7 +741,6 @@ static int mousevsc_on_device_add(struct hv_device *device,
 
 	input_dev->init_complete = true;
 
-cleanup:
 	return ret;
 }
 
@@ -789,16 +786,10 @@ static int mousevsc_on_device_remove(struct hv_device *device)
 static int mousevsc_probe(struct hv_device *dev,
 			const struct hv_vmbus_device_id *dev_id)
 {
-	int ret = 0;
-
 
 	/* Call to the vsc driver to add the device */
-	ret = mousevsc_on_device_add(dev, NULL);
+	return mousevsc_on_device_add(dev, NULL);
 
-	if (ret != 0)
-		return -1;
-
-	return 0;
 }
 
 static int mousevsc_remove(struct hv_device *dev)
Signature · 1 line
1.7.4.1
#0 lore raw

cover Staging: hv: mousevsc cleanup

The mouse driver while being in the tree for several months now, has never been functional. This patch set cleans up this driver and makes the driver functional. Furthermore, this driver is now about 30% smaller.

Regards,

K. Y

#1 lore raw

PATCH 1/24 Staging: hv: mousevsc: Fixup struct hv_input_dev_info

This structure is protocol defined structure and must match the definition on the host side. Make appropriate adjustments.

---
 drivers/staging/hv/hv_mouse.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/staging/hv/hv_mouse.c +3 -3
index fcb023a..44a2b23 100644
@@ -30,10 +30,11 @@
  * Data types
  */
 struct hv_input_dev_info {
+	unsigned int size;
 	unsigned short vendor;
 	unsigned short product;
 	unsigned short version;
-	char name[128];
+	unsigned short reserved[11];
 };
 
 /* The maximum size of a synthetic input message. */
@@ -686,7 +687,7 @@ static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len)
 		hid_dev->dev = dev->device;
 
 		sprintf(hid_dev->name, "%s",
-			input_device_ctx->device_info.name);
+			"Microsoft Vmbus HID-compliant Mouse");
 
 		/*
 		 * HJ Do we want to call it with a 0
@@ -763,7 +764,6 @@ static int mousevsc_on_device_add(struct hv_device *device,
 	dev_info.vendor = input_dev->hid_dev_info.vendor;
 	dev_info.product = input_dev->hid_dev_info.product;
 	dev_info.version = input_dev->hid_dev_info.version;
-	strcpy(dev_info.name, "Microsoft Vmbus HID-compliant Mouse");
 
 	/* Send the device info back up */
 	input_device_ctx = dev_get_drvdata(&device->device);
Signature · 1 line
1.7.4.1
#3 lore raw

PATCH 3/24 Staging: hv: mousevsc: Fixup some bogus WARN_ON() calls

Fix the bogus WARN_ON() calls.

---
 drivers/staging/hv/hv_mouse.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/staging/hv/hv_mouse.c +3 -3
index 69eb00e..016d7e5 100644
@@ -200,7 +200,7 @@ static struct mousevsc_dev *alloc_input_device(struct hv_device *device)
 
 static void free_input_device(struct mousevsc_dev *device)
 {
-	WARN_ON(atomic_read(&device->ref_count) == 0);
+	WARN_ON(atomic_read(&device->ref_count) != 0);
 	kfree(device);
 }
 
@@ -327,7 +327,7 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
 
 	/* Save the hid desc */
 	desc = &device_info->hid_descriptor;
-	WARN_ON(desc->bLength > 0);
+	WARN_ON(desc->bLength == 0);
 
 	input_device->hid_desc = kzalloc(desc->bLength, GFP_KERNEL);
 
@@ -447,7 +447,7 @@ static void mousevsc_on_receive(struct hv_device *device,
 		break;
 
 	case SynthHidInitialDeviceInfo:
-		WARN_ON(pipe_msg->size >= sizeof(struct hv_input_dev_info));
+		WARN_ON(pipe_msg->size < sizeof(struct hv_input_dev_info));
 
 		/*
 		 * Parse out the device info into device attr,
Signature · 1 line
1.7.4.1
#5 lore raw

PATCH 5/24 Staging: hv: mousevsc: Handle the case where we may get bogus report desc size

In reply to K. Y. Srinivasan

Handle the case where we may get bogus report desc size from the host.

---
 drivers/staging/hv/hv_mouse.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/staging/hv/hv_mouse.c +2 -0
index b7cc164..19cfc23 100644
@@ -341,6 +341,8 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
 
 	/* Save the report desc */
 	input_device->report_desc_size = desc->desc[0].wDescriptorLength;
+	if (input_device->report_desc_size == 0)
+		goto cleanup;
 	input_device->report_desc = kzalloc(input_device->report_desc_size,
 					  GFP_ATOMIC);
 
Signature · 1 line
1.7.4.1
#6 lore raw

PATCH 6/24 Staging: hv: mousevsc: Correctly initialize the header size

In reply to K. Y. Srinivasan

Correctly initialize the header size.

---
 drivers/staging/hv/hv_mouse.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/staging/hv/hv_mouse.c +1 -1
index 19cfc23..74faa26 100644
@@ -590,7 +590,7 @@ static int mousevsc_connect_to_vsp(struct hv_device *device)
 	request->size = sizeof(struct synthhid_protocol_request);
 
 	request->request.header.type = SynthHidProtocolRequest;
-	request->request.header.size = sizeof(unsigned long);
+	request->request.header.size = sizeof(unsigned int);
 	request->request.version_requested.version = SYNTHHID_INPUT_VERSION;
 
 	pr_info("synthhid protocol request...");
Signature · 1 line
1.7.4.1
#8 lore raw

PATCH 8/24 Staging: hv: mousevsc: Cleanup and properly implement reportdesc_callback()

In reply to K. Y. Srinivasan

Cleanup and properly implement reportdesc_callback(); properly allocate the hid_device and properly initialize the hid device structure.

---
 drivers/staging/hv/hv_mouse.c |   56 +++++++++++++++++------------------------
 1 files changed, 23 insertions(+), 33 deletions(-)
drivers/staging/hv/hv_mouse.c +23 -33
index ea9e1f3..8d94aef 100644
@@ -646,56 +646,45 @@ static void mousevsc_hid_close(struct hid_device *hid)
 {
 }
 
+static struct hid_ll_driver mousevsc_ll_driver = {
+	.open = mousevsc_hid_open,
+	.close = mousevsc_hid_close,
+};
+
+static struct hid_driver mousevsc_hid_driver;
+
 static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len)
 {
 	struct hid_device *hid_dev;
 	struct mousevsc_dev *input_device = hv_get_drvdata(dev);
 
-	/* hid_debug = -1; */
-	hid_dev = kmalloc(sizeof(struct hid_device), GFP_KERNEL);
+	hid_dev = hid_allocate_device();
+	if (IS_ERR(hid_dev))
+		return;
+
+	hid_dev->ll_driver = &mousevsc_ll_driver;
+	hid_dev->driver = &mousevsc_hid_driver;
 
 	if (hid_parse_report(hid_dev, packet, len)) {
 		DPRINT_INFO(INPUTVSC_DRV, "Unable to call hd_parse_report");
 		return;
 	}
 
-	if (hid_dev) {
-		DPRINT_INFO(INPUTVSC_DRV, "hid_device created");
-
-		hid_dev->ll_driver->open  = mousevsc_hid_open;
-		hid_dev->ll_driver->close = mousevsc_hid_close;
+	hid_dev->bus = BUS_VIRTUAL;
+	hid_dev->vendor = input_device->hid_dev_info.vendor;
+	hid_dev->product = input_device->hid_dev_info.product;
+	hid_dev->version = input_device->hid_dev_info.version;
 
-		hid_dev->bus = BUS_VIRTUAL;
-		hid_dev->vendor = input_device->hid_dev_info.vendor;
-		hid_dev->product = input_device->hid_dev_info.product;
-		hid_dev->version = input_device->hid_dev_info.version;
-		hid_dev->dev = dev->device;
+	sprintf(hid_dev->name, "%s", "Microsoft Vmbus HID-compliant Mouse");
 
-		sprintf(hid_dev->name, "%s",
-			"Microsoft Vmbus HID-compliant Mouse");
+	if (!hidinput_connect(hid_dev, 0)) {
+		hid_dev->claimed |= HID_CLAIMED_INPUT;
 
-		/*
-		 * HJ Do we want to call it with a 0
-		 */
-		if (!hidinput_connect(hid_dev, 0)) {
-			hid_dev->claimed |= HID_CLAIMED_INPUT;
-
-			input_device->connected = 1;
-
-			DPRINT_INFO(INPUTVSC_DRV,
-				     "HID device claimed by input\n");
-		}
-
-		if (!hid_dev->claimed) {
-			DPRINT_ERR(INPUTVSC_DRV,
-				    "HID device not claimed by "
-				    "input or hiddev\n");
-		}
+		input_device->connected = 1;
 
-		input_device->hid_device = hid_dev;
 	}
 
-	kfree(hid_dev);
+	input_device->hid_device = hid_dev;
 }
 
 static int mousevsc_on_device_add(struct hv_device *device,
@@ -825,6 +814,7 @@ static int mousevsc_remove(struct hv_device *dev)
 	if (input_dev->connected) {
 		hidinput_disconnect(input_dev->hid_device);
 		input_dev->connected = 0;
+		hid_destroy_device(input_dev->hid_device);
 	}
 
 	/*
Signature · 1 line
1.7.4.1
#13 lore raw

PATCH 13/24 Staging: hv: mousevsc: Get rid of the unused state: num_outstanding_req

In reply to K. Y. Srinivasan

Get rid of the unused state: num_outstanding_req in struct mousevsc_dev.

---
 drivers/staging/hv/hv_mouse.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)
drivers/staging/hv/hv_mouse.c +0 -3
index 326d972..092c0ff 100644
@@ -157,7 +157,6 @@ struct mousevsc_dev {
 	struct hv_device	*device;
 	/* 0 indicates the device is being destroyed */
 	atomic_t		ref_count;
-	int			num_outstanding_req;
 	unsigned char		init_complete;
 	struct mousevsc_prt_msg	protocol_req;
 	struct mousevsc_prt_msg	protocol_resp;
@@ -729,8 +728,6 @@ static int mousevsc_on_device_remove(struct hv_device *device)
 	 *
 	 * so that outstanding requests can be completed.
 	 */
-	while (input_dev->num_outstanding_req)
-		udelay(100);
 
 	input_dev = final_release_input_device(device);
 
Signature · 1 line
1.7.4.1
#14 lore raw

PATCH 14/24 Staging: hv: mousevsc: Cleanup alloc_input_device()

In reply to K. Y. Srinivasan

Cleanup alloc_input_device(); you can directly set the reference count.

---
 drivers/staging/hv/hv_mouse.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/staging/hv/hv_mouse.c +1 -1
index 092c0ff..38e31ae 100644
@@ -186,7 +186,7 @@ static struct mousevsc_dev *alloc_input_device(struct hv_device *device)
 	 * Set to 2 to allow both inbound and outbound traffics
 	 * (ie get_input_device() and must_get_input_device()) to proceed.
 	 */
-	atomic_cmpxchg(&input_dev->ref_count, 0, 2);
+	atomic_set(&input_dev->ref_count, 2);
 
 	input_dev->device = device;
 	hv_set_drvdata(device, input_dev);
Signature · 1 line
1.7.4.1
#16 lore raw

PATCH 16/24 Staging: hv: mousevsc: Cleanup mousevsc_connect_to_vsp()

In reply to K. Y. Srinivasan

Cleanup mousevsc_connect_to_vsp(). There is no need to take reference on the mousevsc device object when we are setting up the device. As part of this cleanup get rid of get_input_device() as this function is only used here.

---
 drivers/staging/hv/hv_mouse.c |   34 +---------------------------------
 1 files changed, 1 insertions(+), 33 deletions(-)
drivers/staging/hv/hv_mouse.c +1 -33
index fc0ba68..75ea2db 100644
@@ -204,32 +204,6 @@ static void free_input_device(struct mousevsc_dev *device)
 }
 
 /*
- * Get the inputdevice object if exists and its refcount > 1
- */
-static struct mousevsc_dev *get_input_device(struct hv_device *device)
-{
-	struct mousevsc_dev *input_dev;
-
-	input_dev = hv_get_drvdata(device);
-
-/*
- *	FIXME
- *	This sure isn't a valid thing to print for debugging, no matter
- *	what the intention is...
- *
- *	printk(KERN_ERR "-------------------------> REFCOUNT = %d",
- *	       input_dev->ref_count);
- */
-
-	if (input_dev && atomic_read(&input_dev->ref_count) > 1)
-		atomic_inc(&input_dev->ref_count);
-	else
-		input_dev = NULL;
-
-	return input_dev;
-}
-
-/*
  * Get the inputdevice object iff exists and its refcount > 0
  */
 static struct mousevsc_dev *must_get_input_device(struct hv_device *device)
@@ -520,15 +494,10 @@ static int mousevsc_connect_to_vsp(struct hv_device *device)
 {
 	int ret = 0;
 	int t;
-	struct mousevsc_dev *input_dev;
+	struct mousevsc_dev *input_dev = hv_get_drvdata(device);
 	struct mousevsc_prt_msg *request;
 	struct mousevsc_prt_msg *response;
 
-	input_dev = get_input_device(device);
-
-	if (!input_dev)
-		return -ENODEV;
-
 
 	request = &input_dev->protocol_req;
 
@@ -584,7 +553,6 @@ static int mousevsc_connect_to_vsp(struct hv_device *device)
 		ret = -ENOMEM;
 
 cleanup:
-	put_input_device(device);
 
 	return ret;
 }
Signature · 1 line
1.7.4.1
#18 lore raw

PATCH 18/24 Staging: hv: mousevsc: Now cleanup mousevsc_remove()

In reply to K. Y. Srinivasan

Now, cleanup mousevsc_remove(). The mouse driver once initialized only receives data from the host. So, by closing the channel first in the unload path, we can properly deal with inflight packets. So, we don't need the machinery for managing the life-cycle of the mousevsc_dev object. Get rid of the unnecessary code.

---
 drivers/staging/hv/hv_mouse.c |   53 ++--------------------------------------
 1 files changed, 3 insertions(+), 50 deletions(-)
drivers/staging/hv/hv_mouse.c +3 -50
index 5324429..317d2be 100644
@@ -197,9 +197,9 @@ static struct mousevsc_dev *alloc_input_device(struct hv_device *device)
 
 static void free_input_device(struct mousevsc_dev *device)
 {
-	WARN_ON(atomic_read(&device->ref_count) != 0);
 	kfree(device->hid_desc);
 	kfree(device->report_desc);
+	hv_set_drvdata(device->device, NULL);
 	kfree(device);
 }
 
@@ -229,39 +229,6 @@ static void put_input_device(struct hv_device *device)
 	atomic_dec(&input_dev->ref_count);
 }
 
-/*
- * Drop ref count to 1 to effectively disable get_input_device()
- */
-static struct mousevsc_dev *release_input_device(struct hv_device *device)
-{
-	struct mousevsc_dev *input_dev;
-
-	input_dev = hv_get_drvdata(device);
-
-	/* Busy wait until the ref drop to 2, then set it to 1  */
-	while (atomic_cmpxchg(&input_dev->ref_count, 2, 1) != 2)
-		udelay(100);
-
-	return input_dev;
-}
-
-/*
- * Drop ref count to 0. No one can use input_device object.
- */
-static struct mousevsc_dev *final_release_input_device(struct hv_device *device)
-{
-	struct mousevsc_dev *input_dev;
-
-	input_dev = hv_get_drvdata(device);
-
-	/* Busy wait until the ref drop to 1, then set it to 0  */
-	while (atomic_cmpxchg(&input_dev->ref_count, 1, 0) != 1)
-		udelay(100);
-
-	hv_set_drvdata(device, NULL);
-	return input_dev;
-}
-
 
 static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
 				struct synthhid_device_info *device_info)
@@ -673,28 +640,14 @@ static int mousevsc_remove(struct hv_device *dev)
 {
 	struct mousevsc_dev *input_dev = hv_get_drvdata(dev);
 
+	vmbus_close(dev->channel);
+
 	if (input_dev->connected) {
 		hidinput_disconnect(input_dev->hid_device);
 		input_dev->connected = 0;
 		hid_destroy_device(input_dev->hid_device);
 	}
 
-
-	release_input_device(dev);
-
-
-	/*
-	 * At this point, all outbound traffic should be disable. We only
-	 * allow inbound traffic (responses) to proceed
-	 *
-	 * so that outstanding requests can be completed.
-	 */
-
-	input_dev = final_release_input_device(dev);
-
-	/* Close the channel */
-	vmbus_close(dev->channel);
-
 	free_input_device(input_dev);
 
 	return 0;
Signature · 1 line
1.7.4.1
#20 lore raw

PATCH 20/24 Staging: hv: mousevsc: Cleanup camel cased enums

In reply to K. Y. Srinivasan

Cleanup all camel cased names.

---
 drivers/staging/hv/hv_mouse.c |   34 +++++++++++++++++-----------------
 1 files changed, 17 insertions(+), 17 deletions(-)
drivers/staging/hv/hv_mouse.c +17 -17
index e57e0b4..6621326 100644
@@ -58,12 +58,12 @@ struct hv_input_dev_info {
  * Message types in the synthetic input protocol
  */
 enum synthhid_msg_type {
-	SynthHidProtocolRequest,
-	SynthHidProtocolResponse,
-	SynthHidInitialDeviceInfo,
-	SynthHidInitialDeviceInfoAck,
-	SynthHidInputReport,
-	SynthHidMax
+	SYNTH_HID_PROTOCOL_REQUEST,
+	SYNTH_HID_PROTOCOL_RESPONSE,
+	SYNTH_HID_INITIAL_DEVICE_INFO,
+	SYNTH_HID_INITIAL_DEVICE_INFO_ACK,
+	SYNTH_HID_INPUT_REPORT,
+	SYNTH_HID_MAX
 };
 
 /*
@@ -125,9 +125,9 @@ struct synthhid_input_report {
 #define NBITS(x) (((x)/BITS_PER_LONG)+1)
 
 enum pipe_prot_msg_type {
-	PipeMessageInvalid = 0,
-	PipeMessageData,
-	PipeMessageMaximum
+	PIPE_MESSAGE_INVALID,
+	PIPE_MESSAGE_DATA,
+	PIPE_MESSAGE_MAXIMUM
 };
 
 
@@ -238,10 +238,10 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
 	/* Send the ack */
 	memset(&ack, 0, sizeof(struct mousevsc_prt_msg));
 
-	ack.type = PipeMessageData;
+	ack.type = PIPE_MESSAGE_DATA;
 	ack.size = sizeof(struct synthhid_device_info_ack);
 
-	ack.ack.header.type = SynthHidInitialDeviceInfoAck;
+	ack.ack.header.type = SYNTH_HID_INITIAL_DEVICE_INFO_ACK;
 	ack.ack.header.size = 1;
 	ack.ack.reserved = 0;
 
@@ -296,20 +296,20 @@ static void mousevsc_on_receive(struct hv_device *device,
 	pipe_msg = (struct pipe_prt_msg *)((unsigned long)packet +
 						(packet->offset8 << 3));
 
-	if (pipe_msg->type != PipeMessageData)
+	if (pipe_msg->type != PIPE_MESSAGE_DATA)
 		return;
 
 	hid_msg = (struct synthhid_msg *)&pipe_msg->data[0];
 
 	switch (hid_msg->header.type) {
-	case SynthHidProtocolResponse:
+	case SYNTH_HID_PROTOCOL_RESPONSE:
 		memcpy(&input_dev->protocol_resp, pipe_msg,
 		       pipe_msg->size + sizeof(struct pipe_prt_msg) -
 		       sizeof(unsigned char));
 		complete(&input_dev->wait_event);
 		break;
 
-	case SynthHidInitialDeviceInfo:
+	case SYNTH_HID_INITIAL_DEVICE_INFO:
 		WARN_ON(pipe_msg->size < sizeof(struct hv_input_dev_info));
 
 		/*
@@ -319,7 +319,7 @@ static void mousevsc_on_receive(struct hv_device *device,
 		mousevsc_on_receive_device_info(input_dev,
 			(struct synthhid_device_info *)&pipe_msg->data[0]);
 		break;
-	case SynthHidInputReport:
+	case SYNTH_HID_INPUT_REPORT:
 		mousevsc_on_receive_input_report(input_dev,
 			(struct synthhid_input_report *)&pipe_msg->data[0]);
 
@@ -425,10 +425,10 @@ static int mousevsc_connect_to_vsp(struct hv_device *device)
 	 */
 	memset(request, 0, sizeof(struct mousevsc_prt_msg));
 
-	request->type = PipeMessageData;
+	request->type = PIPE_MESSAGE_DATA;
 	request->size = sizeof(struct synthhid_protocol_request);
 
-	request->request.header.type = SynthHidProtocolRequest;
+	request->request.header.type = SYNTH_HID_PROTOCOL_REQUEST;
 	request->request.header.size = sizeof(unsigned int);
 	request->request.version_requested.version = SYNTHHID_INPUT_VERSION;
 
Signature · 1 line
1.7.4.1
#22 lore raw

PATCH 22/24 Staging: hv: mousevsc: Cleanup mousevsc_on_device_add()

In reply to K. Y. Srinivasan

Cleanup mousevsc_on_device_add().

---
 drivers/staging/hv/hv_mouse.c |    9 ++-------
 1 files changed, 2 insertions(+), 7 deletions(-)
drivers/staging/hv/hv_mouse.c +2 -7
index a526ba5..98ae062 100644
@@ -513,12 +513,10 @@ static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len)
 	input_device->hid_device = hid_dev;
 }
 
-static int mousevsc_on_device_add(struct hv_device *device,
-					void *additional_info)
+static int mousevsc_on_device_add(struct hv_device *device)
 {
 	int ret = 0;
 	struct mousevsc_dev *input_dev;
-	struct hv_driver *input_drv;
 
 	input_dev = alloc_input_device(device);
 
@@ -551,9 +549,6 @@ static int mousevsc_on_device_add(struct hv_device *device,
 		return ret;
 	}
 
-	input_drv = drv_to_hv_drv(input_dev->device->device.driver);
-
-
 
 	/* Send the report desc back up */
 	/* workaround SA-167 */
@@ -573,7 +568,7 @@ static int mousevsc_probe(struct hv_device *dev,
 {
 
 	/* Call to the vsc driver to add the device */
-	return mousevsc_on_device_add(dev, NULL);
+	return mousevsc_on_device_add(dev);
 
 }
 
Signature · 1 line
1.7.4.1
#25 lore raw

Re: [PATCH 01/24] Staging: hv: mousevsc: Fixup struct hv_input_dev_info

In reply to K. Y. Srinivasan

On Thu, Sep 29, 2011 at 11:54:41AM -0700, K. Y. Srinivasan wrote:

<snip>

I only got 21 emails in this thread, and they seemed to trickle in in odd bunches. Did they all get sent properly, or do you wish to resend them to ensure they all get here?

thanks,

greg k-h

#26 lore raw

RE: [PATCH 01/24] Staging: hv: mousevsc: Fixup struct hv_input_dev_info

Quoted 12 lines

-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Thursday, September 29, 2011 8:48 PM
To: KY Srinivasan
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Haiyang Zhang
Subject: Re: [PATCH 01/24] Staging: hv: mousevsc: Fixup struct hv_input_dev_info

Quoted 7 lines

On Thu, Sep 29, 2011 at 11:54:41AM -0700, K. Y. Srinivasan wrote:

<snip>

I only got 21 emails in this thread, and they seemed to trickle in in odd bunches. Did they all get sent properly, or do you wish to resend them to ensure they all get here?

I sent them out as I normally send them. I don't know why they are not being delivered as they should be. Given that you have gotten 21 of the 24 patches, if you tell me which patches you have not received, I could resend just those. Or I could resend the whole series again if you prefer. Let me know.

Regards,

K. Y

#27 lore raw

Re: [PATCH 01/24] Staging: hv: mousevsc: Fixup struct hv_input_dev_info

Quoted 11 lines · KY Srinivasan
Quoted 6 lines

From: Greg KH [mailto:[email protected]]
<snip>

I only got 21 emails in this thread, and they seemed to trickle in in odd bunches. Did they all get sent properly, or do you wish to resend them to ensure they all get here?

I sent them out as I normally send them. I don't know why they are not being delivered as they should be. Given that you have gotten 21 of the 24 patches, if you tell me which patches you have not received, I could resend just those. Or I could resend the whole series again if you prefer. Let me know.

It looks like they just now went through. They got stuck on your server, linuxonhyperv.com if you look at the email headers. I suggest you go give that thing a kick to figure out what went wrong.

So don't worry, I got them now...

greg k-h