linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/8] HID: Consolidate serializing ope/close in transport drivers
@ 2017-06-07  6:59 Dmitry Torokhov
  2017-06-07  6:59 ` [PATCH v2 1/8] HID: hiddev: use hid_hw_open/close instead of usbhid_open/close Dmitry Torokhov
                   ` (10 more replies)
  0 siblings, 11 replies; 15+ messages in thread
From: Dmitry Torokhov @ 2017-06-07  6:59 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires
  Cc: linux-input, linux-kernel, Greg Kroah-Hartman

This originally came about as report of uhid sending duplicate open and
premature close when hidraw was used alongside of input. After looking at
the drivers I think we should consolidate user tracking inside of the HID
core. While implementing this, there were a few cleanups as well.

V2:

- added greybus hid changes
- added error handling in hiddev around hid_hw_open which is __much_check

Dmitry Torokhov (8):
  HID: hiddev: use hid_hw_open/close instead of usbhid_open/close
  HID: hiddev: use hid_hw_power instead of usbhid_get/put_power
  HID: usbhid: do not rely on hid->open when deciding to do IO
  HID: serialize hid_hw_open and hid_hw_close
  HID: i2c-hid: remove custom locking from i2c_hid_open/close
  HID: usbhid: remove custom locking from usbhid_open/close
  greybus: hid: remove custom locking from gb_hid_open/close
  HID: remove no longer used hid->open field

 drivers/hid/hid-core.c        |  89 +++++++++++++++++++++++++
 drivers/hid/i2c-hid/i2c-hid.c |  32 +++------
 drivers/hid/usbhid/hid-core.c | 150 ++++++++++++++++++++----------------------
 drivers/hid/usbhid/hiddev.c   |  24 +++----
 drivers/hid/usbhid/usbhid.h   |  15 +++--
 drivers/staging/greybus/hid.c |  43 ++++--------
 include/linux/hid.h           |  73 +++-----------------
 7 files changed, 214 insertions(+), 212 deletions(-)

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v2 1/8] HID: hiddev: use hid_hw_open/close instead of usbhid_open/close
  2017-06-07  6:59 [PATCH v2 0/8] HID: Consolidate serializing ope/close in transport drivers Dmitry Torokhov
@ 2017-06-07  6:59 ` Dmitry Torokhov
  2017-06-07  6:59 ` [PATCH v2 2/8] HID: hiddev: use hid_hw_power instead of usbhid_get/put_power Dmitry Torokhov
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Dmitry Torokhov @ 2017-06-07  6:59 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires
  Cc: linux-input, linux-kernel, Greg Kroah-Hartman

Instead of calling into usbhid code directly, let's use the standard
accessors for the transport HID drivers, and stop clobbering their errors
with -EIO.

This also allows us make usbhid_open and close static.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/hid/usbhid/hid-core.c |  4 ++--
 drivers/hid/usbhid/hiddev.c   | 16 +++++++++-------
 drivers/hid/usbhid/usbhid.h   |  2 --
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index 83772fa7d92a..fb0cf5d70504 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -677,7 +677,7 @@ static int hid_get_class_descriptor(struct usb_device *dev, int ifnum,
 	return result;
 }
 
-int usbhid_open(struct hid_device *hid)
+static int usbhid_open(struct hid_device *hid)
 {
 	struct usbhid_device *usbhid = hid->driver_data;
 	int res = 0;
@@ -722,7 +722,7 @@ int usbhid_open(struct hid_device *hid)
 	return res;
 }
 
-void usbhid_close(struct hid_device *hid)
+static void usbhid_close(struct hid_device *hid)
 {
 	struct usbhid_device *usbhid = hid->driver_data;
 
diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
index 0e06368d1fbb..b4f714752245 100644
--- a/drivers/hid/usbhid/hiddev.c
+++ b/drivers/hid/usbhid/hiddev.c
@@ -237,7 +237,7 @@ static int hiddev_release(struct inode * inode, struct file * file)
 	mutex_lock(&list->hiddev->existancelock);
 	if (!--list->hiddev->open) {
 		if (list->hiddev->exist) {
-			usbhid_close(list->hiddev->hid);
+			hid_hw_close(list->hiddev->hid);
 			usbhid_put_power(list->hiddev->hid);
 		} else {
 			mutex_unlock(&list->hiddev->existancelock);
@@ -282,11 +282,9 @@ static int hiddev_open(struct inode *inode, struct file *file)
 	 */
 	if (list->hiddev->exist) {
 		if (!list->hiddev->open++) {
-			res = usbhid_open(hiddev->hid);
-			if (res < 0) {
-				res = -EIO;
+			res = hid_hw_open(hiddev->hid);
+			if (res < 0)
 				goto bail;
-			}
 		}
 	} else {
 		res = -ENODEV;
@@ -306,10 +304,14 @@ static int hiddev_open(struct inode *inode, struct file *file)
 				res = -EIO;
 				goto bail_unlock;
 			}
-			usbhid_open(hid);
+			res = hid_hw_open(hid);
+			if (res < 0)
+				goto bail_put_power;
 		}
 	mutex_unlock(&hiddev->existancelock);
 	return 0;
+bail_put_power:
+	usbhid_put_power(hid);
 bail_unlock:
 	mutex_unlock(&hiddev->existancelock);
 bail:
@@ -935,7 +937,7 @@ void hiddev_disconnect(struct hid_device *hid)
 
 	if (hiddev->open) {
 		mutex_unlock(&hiddev->existancelock);
-		usbhid_close(hiddev->hid);
+		hid_hw_close(hiddev->hid);
 		wake_up_interruptible(&hiddev->wait);
 	} else {
 		mutex_unlock(&hiddev->existancelock);
diff --git a/drivers/hid/usbhid/usbhid.h b/drivers/hid/usbhid/usbhid.h
index fa47d666cfcf..83ef5c14aa92 100644
--- a/drivers/hid/usbhid/usbhid.h
+++ b/drivers/hid/usbhid/usbhid.h
@@ -34,8 +34,6 @@
 #include <linux/input.h>
 
 /*  API provided by hid-core.c for USB HID drivers */
-void usbhid_close(struct hid_device *hid);
-int usbhid_open(struct hid_device *hid);
 void usbhid_init_reports(struct hid_device *hid);
 int usbhid_get_power(struct hid_device *hid);
 void usbhid_put_power(struct hid_device *hid);
-- 
2.13.0.506.g27d5fe0cd-goog

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v2 2/8] HID: hiddev: use hid_hw_power instead of usbhid_get/put_power
  2017-06-07  6:59 [PATCH v2 0/8] HID: Consolidate serializing ope/close in transport drivers Dmitry Torokhov
  2017-06-07  6:59 ` [PATCH v2 1/8] HID: hiddev: use hid_hw_open/close instead of usbhid_open/close Dmitry Torokhov
@ 2017-06-07  6:59 ` Dmitry Torokhov
  2017-06-07  8:40   ` Andy Shevchenko
  2017-06-07  6:59 ` [PATCH v2 3/8] HID: usbhid: do not rely on hid->open when deciding to do IO Dmitry Torokhov
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 15+ messages in thread
From: Dmitry Torokhov @ 2017-06-07  6:59 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires
  Cc: linux-input, linux-kernel, Greg Kroah-Hartman

Instead of calling into usbhid code directly, let's use the standard
accessors for the transport HID drivers, and stop clobbering their error
codes with -EIO.

This also allows us to remove usbhid_get/put_power(), leaving only
usbhid_power().

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/hid/usbhid/hid-core.c | 22 +++++-----------------
 drivers/hid/usbhid/hiddev.c   | 14 ++++++--------
 drivers/hid/usbhid/usbhid.h   |  2 --
 3 files changed, 11 insertions(+), 27 deletions(-)

diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index fb0cf5d70504..62b660622265 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -1203,16 +1203,19 @@ static void usbhid_stop(struct hid_device *hid)
 
 static int usbhid_power(struct hid_device *hid, int lvl)
 {
+	struct usbhid_device *usbhid = hid->driver_data;
 	int r = 0;
 
 	switch (lvl) {
 	case PM_HINT_FULLON:
-		r = usbhid_get_power(hid);
+		r = usb_autopm_get_interface(usbhid->intf);
 		break;
+
 	case PM_HINT_NORMAL:
-		usbhid_put_power(hid);
+		usb_autopm_put_interface(usbhid->intf);
 		break;
 	}
+
 	return r;
 }
 
@@ -1492,21 +1495,6 @@ static int hid_post_reset(struct usb_interface *intf)
 	return 0;
 }
 
-int usbhid_get_power(struct hid_device *hid)
-{
-	struct usbhid_device *usbhid = hid->driver_data;
-
-	return usb_autopm_get_interface(usbhid->intf);
-}
-
-void usbhid_put_power(struct hid_device *hid)
-{
-	struct usbhid_device *usbhid = hid->driver_data;
-
-	usb_autopm_put_interface(usbhid->intf);
-}
-
-
 #ifdef CONFIG_PM
 static int hid_resume_common(struct hid_device *hid, bool driver_suspended)
 {
diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
index b4f714752245..7d749b19c27c 100644
--- a/drivers/hid/usbhid/hiddev.c
+++ b/drivers/hid/usbhid/hiddev.c
@@ -238,7 +238,7 @@ static int hiddev_release(struct inode * inode, struct file * file)
 	if (!--list->hiddev->open) {
 		if (list->hiddev->exist) {
 			hid_hw_close(list->hiddev->hid);
-			usbhid_put_power(list->hiddev->hid);
+			hid_hw_power(list->hiddev->hid, PM_HINT_NORMAL);
 		} else {
 			mutex_unlock(&list->hiddev->existancelock);
 			kfree(list->hiddev);
@@ -299,19 +299,17 @@ static int hiddev_open(struct inode *inode, struct file *file)
 	if (!list->hiddev->open++)
 		if (list->hiddev->exist) {
 			struct hid_device *hid = hiddev->hid;
-			res = usbhid_get_power(hid);
-			if (res < 0) {
-				res = -EIO;
+			res = hid_hw_power(hid, PM_HINT_FULLON);
+			if (res < 0)
 				goto bail_unlock;
-			}
 			res = hid_hw_open(hid);
 			if (res < 0)
-				goto bail_put_power;
+				goto bail_normal_power;
 		}
 	mutex_unlock(&hiddev->existancelock);
 	return 0;
-bail_put_power:
-	usbhid_put_power(hid);
+bail_normal_power:
+	hid_hw_power(hid, PM_HINT_NORMAL);
 bail_unlock:
 	mutex_unlock(&hiddev->existancelock);
 bail:
diff --git a/drivers/hid/usbhid/usbhid.h b/drivers/hid/usbhid/usbhid.h
index 83ef5c14aa92..ffcd329b3c3b 100644
--- a/drivers/hid/usbhid/usbhid.h
+++ b/drivers/hid/usbhid/usbhid.h
@@ -35,8 +35,6 @@
 
 /*  API provided by hid-core.c for USB HID drivers */
 void usbhid_init_reports(struct hid_device *hid);
-int usbhid_get_power(struct hid_device *hid);
-void usbhid_put_power(struct hid_device *hid);
 struct usb_interface *usbhid_find_interface(int minor);
 
 /* iofl flags */
-- 
2.13.0.506.g27d5fe0cd-goog

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v2 3/8] HID: usbhid: do not rely on hid->open when deciding to do IO
  2017-06-07  6:59 [PATCH v2 0/8] HID: Consolidate serializing ope/close in transport drivers Dmitry Torokhov
  2017-06-07  6:59 ` [PATCH v2 1/8] HID: hiddev: use hid_hw_open/close instead of usbhid_open/close Dmitry Torokhov
  2017-06-07  6:59 ` [PATCH v2 2/8] HID: hiddev: use hid_hw_power instead of usbhid_get/put_power Dmitry Torokhov
@ 2017-06-07  6:59 ` Dmitry Torokhov
  2017-06-07  6:59 ` [PATCH v2 4/8] HID: serialize hid_hw_open and hid_hw_close Dmitry Torokhov
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Dmitry Torokhov @ 2017-06-07  6:59 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires
  Cc: linux-input, linux-kernel, Greg Kroah-Hartman

Instead of checking hid->open (that we plan on having HID core manage) in
hid_start_in(), let's allocate a couple of new flags: HID_IN_POLLING and
HID_OPENED, and use them to decide whether we should be submitting URBs or
not.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/hid/usbhid/hid-core.c | 25 ++++++++++++++++++-------
 drivers/hid/usbhid/usbhid.h   | 11 +++++++++++
 2 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index 62b660622265..d927fe4ba592 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -85,10 +85,10 @@ static int hid_start_in(struct hid_device *hid)
 	struct usbhid_device *usbhid = hid->driver_data;
 
 	spin_lock_irqsave(&usbhid->lock, flags);
-	if ((hid->open > 0 || hid->quirks & HID_QUIRK_ALWAYS_POLL) &&
-			!test_bit(HID_DISCONNECTED, &usbhid->iofl) &&
-			!test_bit(HID_SUSPENDED, &usbhid->iofl) &&
-			!test_and_set_bit(HID_IN_RUNNING, &usbhid->iofl)) {
+	if (test_bit(HID_IN_POLLING, &usbhid->iofl) &&
+	    !test_bit(HID_DISCONNECTED, &usbhid->iofl) &&
+	    !test_bit(HID_SUSPENDED, &usbhid->iofl) &&
+	    !test_and_set_bit(HID_IN_RUNNING, &usbhid->iofl)) {
 		rc = usb_submit_urb(usbhid->urbin, GFP_ATOMIC);
 		if (rc != 0) {
 			clear_bit(HID_IN_RUNNING, &usbhid->iofl);
@@ -272,13 +272,13 @@ static int usbhid_restart_ctrl_queue(struct usbhid_device *usbhid)
 static void hid_irq_in(struct urb *urb)
 {
 	struct hid_device	*hid = urb->context;
-	struct usbhid_device 	*usbhid = hid->driver_data;
+	struct usbhid_device	*usbhid = hid->driver_data;
 	int			status;
 
 	switch (urb->status) {
 	case 0:			/* success */
 		usbhid->retry_delay = 0;
-		if ((hid->quirks & HID_QUIRK_ALWAYS_POLL) && !hid->open)
+		if (!test_bit(HID_OPENED, &usbhid->iofl))
 			break;
 		usbhid_mark_busy(usbhid);
 		if (!test_bit(HID_RESUME_RUNNING, &usbhid->iofl)) {
@@ -692,6 +692,8 @@ static int usbhid_open(struct hid_device *hid)
 			goto done;
 		}
 		usbhid->intf->needs_remote_wakeup = 1;
+		set_bit(HID_OPENED, &usbhid->iofl);
+		set_bit(HID_IN_POLLING, &usbhid->iofl);
 		set_bit(HID_RESUME_RUNNING, &usbhid->iofl);
 		res = hid_start_in(hid);
 		if (res) {
@@ -701,6 +703,9 @@ static int usbhid_open(struct hid_device *hid)
 			} else {
 				/* no use opening if resources are insufficient */
 				hid->open--;
+				clear_bit(HID_OPENED, &usbhid->iofl);
+				if (!(hid->quirks & HID_QUIRK_ALWAYS_POLL))
+					clear_bit(HID_IN_POLLING, &usbhid->iofl);
 				res = -EBUSY;
 				usbhid->intf->needs_remote_wakeup = 0;
 			}
@@ -734,6 +739,9 @@ static void usbhid_close(struct hid_device *hid)
 	 */
 	spin_lock_irq(&usbhid->lock);
 	if (!--hid->open) {
+		if (!(hid->quirks & HID_QUIRK_ALWAYS_POLL))
+			clear_bit(HID_IN_POLLING, &usbhid->iofl);
+		clear_bit(HID_OPENED, &usbhid->iofl);
 		spin_unlock_irq(&usbhid->lock);
 		hid_cancel_delayed_stuff(usbhid);
 		if (!(hid->quirks & HID_QUIRK_ALWAYS_POLL)) {
@@ -1135,6 +1143,7 @@ static int usbhid_start(struct hid_device *hid)
 		ret = usb_autopm_get_interface(usbhid->intf);
 		if (ret)
 			goto fail;
+		set_bit(HID_IN_POLLING, &usbhid->iofl);
 		usbhid->intf->needs_remote_wakeup = 1;
 		ret = hid_start_in(hid);
 		if (ret) {
@@ -1176,8 +1185,10 @@ static void usbhid_stop(struct hid_device *hid)
 	if (WARN_ON(!usbhid))
 		return;
 
-	if (hid->quirks & HID_QUIRK_ALWAYS_POLL)
+	if (hid->quirks & HID_QUIRK_ALWAYS_POLL) {
+		clear_bit(HID_IN_POLLING, &usbhid->iofl);
 		usbhid->intf->needs_remote_wakeup = 0;
+	}
 
 	clear_bit(HID_STARTED, &usbhid->iofl);
 	spin_lock_irq(&usbhid->lock);	/* Sync with error and led handlers */
diff --git a/drivers/hid/usbhid/usbhid.h b/drivers/hid/usbhid/usbhid.h
index ffcd329b3c3b..da9c61d54be6 100644
--- a/drivers/hid/usbhid/usbhid.h
+++ b/drivers/hid/usbhid/usbhid.h
@@ -49,6 +49,17 @@ struct usb_interface *usbhid_find_interface(int minor);
 #define HID_KEYS_PRESSED	10
 #define HID_NO_BANDWIDTH	11
 #define HID_RESUME_RUNNING	12
+/*
+ * The device is opened, meaning there is a client that is interested
+ * in data coming from the device.
+ */
+#define HID_OPENED		13
+/*
+ * We are polling input endpoint by [re]submitting IN URB, because
+ * either HID device is opened or ALWAYS POLL quirk is set for the
+ * device.
+ */
+#define HID_IN_POLLING		14
 
 /*
  * USB-specific HID struct, to be pointed to
-- 
2.13.0.506.g27d5fe0cd-goog

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v2 4/8] HID: serialize hid_hw_open and hid_hw_close
  2017-06-07  6:59 [PATCH v2 0/8] HID: Consolidate serializing ope/close in transport drivers Dmitry Torokhov
                   ` (2 preceding siblings ...)
  2017-06-07  6:59 ` [PATCH v2 3/8] HID: usbhid: do not rely on hid->open when deciding to do IO Dmitry Torokhov
@ 2017-06-07  6:59 ` Dmitry Torokhov
  2017-06-07  6:59 ` [PATCH v2 5/8] HID: i2c-hid: remove custom locking from i2c_hid_open/close Dmitry Torokhov
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Dmitry Torokhov @ 2017-06-07  6:59 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires
  Cc: linux-input, linux-kernel, Greg Kroah-Hartman

The HID transport drivers either re-implement exactly the same logic
(usbhid, i2c-hid) or forget to implement it (usbhid) which causes issues
when the same device is accessed via multiple interfaces (for example input
device through evdev and also hidraw). Let's muve the locking logic into
HID core to make sure the serialized behavior is always enforced.

Also let's uninline and move hid_hw_start() and hid_hw_stop() into hid-core
as hid_hw_start() is somewhat large and do not believe we get any benefit
from these two being inline.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/hid/hid-core.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/hid.h    | 72 +++++-----------------------------------
 2 files changed, 98 insertions(+), 63 deletions(-)

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index ca173801d2be..f2a2cd522e46 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1750,6 +1750,94 @@ void hid_disconnect(struct hid_device *hdev)
 }
 EXPORT_SYMBOL_GPL(hid_disconnect);
 
+/**
+ * hid_hw_start - start underlying HW
+ * @hdev: hid device
+ * @connect_mask: which outputs to connect, see HID_CONNECT_*
+ *
+ * Call this in probe function *after* hid_parse. This will setup HW
+ * buffers and start the device (if not defeirred to device open).
+ * hid_hw_stop must be called if this was successful.
+ */
+int hid_hw_start(struct hid_device *hdev, unsigned int connect_mask)
+{
+	int error;
+
+	error = hdev->ll_driver->start(hdev);
+	if (error)
+		return error;
+
+	if (connect_mask) {
+		error = hid_connect(hdev, connect_mask);
+		if (error) {
+			hdev->ll_driver->stop(hdev);
+			return error;
+		}
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(hid_hw_start);
+
+/**
+ * hid_hw_stop - stop underlying HW
+ * @hdev: hid device
+ *
+ * This is usually called from remove function or from probe when something
+ * failed and hid_hw_start was called already.
+ */
+void hid_hw_stop(struct hid_device *hdev)
+{
+	hid_disconnect(hdev);
+	hdev->ll_driver->stop(hdev);
+}
+EXPORT_SYMBOL_GPL(hid_hw_stop);
+
+/**
+ * hid_hw_open - signal underlying HW to start delivering events
+ * @hdev: hid device
+ *
+ * Tell underlying HW to start delivering events from the device.
+ * This function should be called sometime after successful call
+ * to hid_hiw_start().
+ */
+int hid_hw_open(struct hid_device *hdev)
+{
+	int ret;
+
+	ret = mutex_lock_killable(&hdev->ll_open_lock);
+	if (ret)
+		return ret;
+
+	if (!hdev->ll_open_count++) {
+		ret = hdev->ll_driver->open(hdev);
+		if (ret)
+			hdev->ll_open_count--;
+	}
+
+	mutex_unlock(&hdev->ll_open_lock);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(hid_hw_open);
+
+/**
+ * hid_hw_close - signal underlaying HW to stop delivering events
+ *
+ * @hdev: hid device
+ *
+ * This function indicates that we are not interested in the events
+ * from this device anymore. Delivery of events may or may not stop,
+ * depending on the number of users still outstanding.
+ */
+void hid_hw_close(struct hid_device *hdev)
+{
+	mutex_lock(&hdev->ll_open_lock);
+	if (!--hdev->ll_open_count)
+		hdev->ll_driver->close(hdev);
+	mutex_unlock(&hdev->ll_open_lock);
+}
+EXPORT_SYMBOL_GPL(hid_hw_close);
+
 /*
  * A list of devices for which there is a specialized driver on HID bus.
  *
@@ -2748,6 +2836,7 @@ struct hid_device *hid_allocate_device(void)
 	spin_lock_init(&hdev->debug_list_lock);
 	sema_init(&hdev->driver_lock, 1);
 	sema_init(&hdev->driver_input_lock, 1);
+	mutex_init(&hdev->ll_open_lock);
 
 	return hdev;
 }
diff --git a/include/linux/hid.h b/include/linux/hid.h
index 5be325d890d9..5501eb64dbc4 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -34,6 +34,7 @@
 #include <linux/workqueue.h>
 #include <linux/input.h>
 #include <linux/semaphore.h>
+#include <linux/mutex.h>
 #include <linux/power_supply.h>
 #include <uapi/linux/hid.h>
 
@@ -520,7 +521,10 @@ struct hid_device {							/* device report descriptor */
 	struct semaphore driver_input_lock;				/* protects the current driver */
 	struct device dev;						/* device */
 	struct hid_driver *driver;
+
 	struct hid_ll_driver *ll_driver;
+	struct mutex ll_open_lock;
+	unsigned int ll_open_count;
 
 #ifdef CONFIG_HID_BATTERY_STRENGTH
 	/*
@@ -937,69 +941,11 @@ static inline int __must_check hid_parse(struct hid_device *hdev)
 	return hid_open_report(hdev);
 }
 
-/**
- * hid_hw_start - start underlaying HW
- *
- * @hdev: hid device
- * @connect_mask: which outputs to connect, see HID_CONNECT_*
- *
- * Call this in probe function *after* hid_parse. This will setup HW buffers
- * and start the device (if not deffered to device open). hid_hw_stop must be
- * called if this was successful.
- */
-static inline int __must_check hid_hw_start(struct hid_device *hdev,
-		unsigned int connect_mask)
-{
-	int ret = hdev->ll_driver->start(hdev);
-	if (ret || !connect_mask)
-		return ret;
-	ret = hid_connect(hdev, connect_mask);
-	if (ret)
-		hdev->ll_driver->stop(hdev);
-	return ret;
-}
-
-/**
- * hid_hw_stop - stop underlaying HW
- *
- * @hdev: hid device
- *
- * This is usually called from remove function or from probe when something
- * failed and hid_hw_start was called already.
- */
-static inline void hid_hw_stop(struct hid_device *hdev)
-{
-	hid_disconnect(hdev);
-	hdev->ll_driver->stop(hdev);
-}
-
-/**
- * hid_hw_open - signal underlaying HW to start delivering events
- *
- * @hdev: hid device
- *
- * Tell underlying HW to start delivering events from the device.
- * This function should be called sometime after successful call
- * to hid_hiw_start().
- */
-static inline int __must_check hid_hw_open(struct hid_device *hdev)
-{
-	return hdev->ll_driver->open(hdev);
-}
-
-/**
- * hid_hw_close - signal underlaying HW to stop delivering events
- *
- * @hdev: hid device
- *
- * This function indicates that we are not interested in the events
- * from this device anymore. Delivery of events may or may not stop,
- * depending on the number of users still outstanding.
- */
-static inline void hid_hw_close(struct hid_device *hdev)
-{
-	hdev->ll_driver->close(hdev);
-}
+int __must_check hid_hw_start(struct hid_device *hdev,
+			      unsigned int connect_mask);
+void hid_hw_stop(struct hid_device *hdev);
+int __must_check hid_hw_open(struct hid_device *hdev);
+void hid_hw_close(struct hid_device *hdev);
 
 /**
  * hid_hw_power - requests underlying HW to go into given power mode
-- 
2.13.0.506.g27d5fe0cd-goog

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v2 5/8] HID: i2c-hid: remove custom locking from i2c_hid_open/close
  2017-06-07  6:59 [PATCH v2 0/8] HID: Consolidate serializing ope/close in transport drivers Dmitry Torokhov
                   ` (3 preceding siblings ...)
  2017-06-07  6:59 ` [PATCH v2 4/8] HID: serialize hid_hw_open and hid_hw_close Dmitry Torokhov
@ 2017-06-07  6:59 ` Dmitry Torokhov
  2017-06-07  6:59 ` [PATCH v2 6/8] HID: usbhid: remove custom locking from usbhid_open/close Dmitry Torokhov
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Dmitry Torokhov @ 2017-06-07  6:59 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires
  Cc: linux-input, linux-kernel, Greg Kroah-Hartman

Now that HID core enforces serialization of transport driver open/close
calls we can remove custom locking from i2c-hid driver.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/hid/i2c-hid/i2c-hid.c | 32 +++++++++-----------------------
 1 file changed, 9 insertions(+), 23 deletions(-)

diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c
index fb55fb4c39fc..6355015ed249 100644
--- a/drivers/hid/i2c-hid/i2c-hid.c
+++ b/drivers/hid/i2c-hid/i2c-hid.c
@@ -743,18 +743,12 @@ static int i2c_hid_open(struct hid_device *hid)
 	struct i2c_hid *ihid = i2c_get_clientdata(client);
 	int ret = 0;
 
-	mutex_lock(&i2c_hid_open_mut);
-	if (!hid->open++) {
-		ret = pm_runtime_get_sync(&client->dev);
-		if (ret < 0) {
-			hid->open--;
-			goto done;
-		}
-		set_bit(I2C_HID_STARTED, &ihid->flags);
-	}
-done:
-	mutex_unlock(&i2c_hid_open_mut);
-	return ret < 0 ? ret : 0;
+	ret = pm_runtime_get_sync(&client->dev);
+	if (ret < 0)
+		return ret;
+
+	set_bit(I2C_HID_STARTED, &ihid->flags);
+	return 0;
 }
 
 static void i2c_hid_close(struct hid_device *hid)
@@ -762,18 +756,10 @@ static void i2c_hid_close(struct hid_device *hid)
 	struct i2c_client *client = hid->driver_data;
 	struct i2c_hid *ihid = i2c_get_clientdata(client);
 
-	/* protecting hid->open to make sure we don't restart
-	 * data acquistion due to a resumption we no longer
-	 * care about
-	 */
-	mutex_lock(&i2c_hid_open_mut);
-	if (!--hid->open) {
-		clear_bit(I2C_HID_STARTED, &ihid->flags);
+	clear_bit(I2C_HID_STARTED, &ihid->flags);
 
-		/* Save some power */
-		pm_runtime_put(&client->dev);
-	}
-	mutex_unlock(&i2c_hid_open_mut);
+	/* Save some power */
+	pm_runtime_put(&client->dev);
 }
 
 static int i2c_hid_power(struct hid_device *hid, int lvl)
-- 
2.13.0.506.g27d5fe0cd-goog

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v2 6/8] HID: usbhid: remove custom locking from usbhid_open/close
  2017-06-07  6:59 [PATCH v2 0/8] HID: Consolidate serializing ope/close in transport drivers Dmitry Torokhov
                   ` (4 preceding siblings ...)
  2017-06-07  6:59 ` [PATCH v2 5/8] HID: i2c-hid: remove custom locking from i2c_hid_open/close Dmitry Torokhov
@ 2017-06-07  6:59 ` Dmitry Torokhov
  2017-06-07  6:59 ` [PATCH v2 7/8] greybus: hid: remove custom locking from gb_hid_open/close Dmitry Torokhov
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Dmitry Torokhov @ 2017-06-07  6:59 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires
  Cc: linux-input, linux-kernel, Greg Kroah-Hartman

Now that HID core enforces serialization of transport driver open/close
calls we can remove custom locking from usbhid driver.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/hid/usbhid/hid-core.c | 115 +++++++++++++++++++-----------------------
 1 file changed, 53 insertions(+), 62 deletions(-)

diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index d927fe4ba592..76013eb5cb7f 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -70,8 +70,6 @@ MODULE_PARM_DESC(quirks, "Add/modify USB HID quirks by specifying "
 /*
  * Input submission and I/O error handler.
  */
-static DEFINE_MUTEX(hid_open_mut);
-
 static void hid_io_error(struct hid_device *hid);
 static int hid_submit_out(struct hid_device *hid);
 static int hid_submit_ctrl(struct hid_device *hid);
@@ -680,50 +678,48 @@ static int hid_get_class_descriptor(struct usb_device *dev, int ifnum,
 static int usbhid_open(struct hid_device *hid)
 {
 	struct usbhid_device *usbhid = hid->driver_data;
-	int res = 0;
-
-	mutex_lock(&hid_open_mut);
-	if (!hid->open++) {
-		res = usb_autopm_get_interface(usbhid->intf);
-		/* the device must be awake to reliably request remote wakeup */
-		if (res < 0) {
-			hid->open--;
-			res = -EIO;
-			goto done;
-		}
-		usbhid->intf->needs_remote_wakeup = 1;
-		set_bit(HID_OPENED, &usbhid->iofl);
-		set_bit(HID_IN_POLLING, &usbhid->iofl);
-		set_bit(HID_RESUME_RUNNING, &usbhid->iofl);
-		res = hid_start_in(hid);
-		if (res) {
-			if (res != -ENOSPC) {
-				hid_io_error(hid);
-				res = 0;
-			} else {
-				/* no use opening if resources are insufficient */
-				hid->open--;
-				clear_bit(HID_OPENED, &usbhid->iofl);
-				if (!(hid->quirks & HID_QUIRK_ALWAYS_POLL))
-					clear_bit(HID_IN_POLLING, &usbhid->iofl);
-				res = -EBUSY;
-				usbhid->intf->needs_remote_wakeup = 0;
-			}
-		}
-		usb_autopm_put_interface(usbhid->intf);
+	int res;
 
-		/*
-		 * In case events are generated while nobody was listening,
-		 * some are released when the device is re-opened.
-		 * Wait 50 msec for the queue to empty before allowing events
-		 * to go through hid.
-		 */
-		if (res == 0 && !(hid->quirks & HID_QUIRK_ALWAYS_POLL))
-			msleep(50);
-		clear_bit(HID_RESUME_RUNNING, &usbhid->iofl);
+	if (hid->quirks & HID_QUIRK_ALWAYS_POLL)
+		return 0;
+
+	res = usb_autopm_get_interface(usbhid->intf);
+	/* the device must be awake to reliably request remote wakeup */
+	if (res < 0)
+		return -EIO;
+
+	usbhid->intf->needs_remote_wakeup = 1;
+
+	set_bit(HID_RESUME_RUNNING, &usbhid->iofl);
+	set_bit(HID_OPENED, &usbhid->iofl);
+	set_bit(HID_IN_POLLING, &usbhid->iofl);
+
+	res = hid_start_in(hid);
+	if (res) {
+		if (res != -ENOSPC) {
+			hid_io_error(hid);
+			res = 0;
+		} else {
+			/* no use opening if resources are insufficient */
+			res = -EBUSY;
+			clear_bit(HID_OPENED, &usbhid->iofl);
+			clear_bit(HID_IN_POLLING, &usbhid->iofl);
+			usbhid->intf->needs_remote_wakeup = 0;
+		}
 	}
-done:
-	mutex_unlock(&hid_open_mut);
+
+	usb_autopm_put_interface(usbhid->intf);
+
+	/*
+	 * In case events are generated while nobody was listening,
+	 * some are released when the device is re-opened.
+	 * Wait 50 msec for the queue to empty before allowing events
+	 * to go through hid.
+	 */
+	if (res == 0)
+		msleep(50);
+
+	clear_bit(HID_RESUME_RUNNING, &usbhid->iofl);
 	return res;
 }
 
@@ -731,27 +727,22 @@ static void usbhid_close(struct hid_device *hid)
 {
 	struct usbhid_device *usbhid = hid->driver_data;
 
-	mutex_lock(&hid_open_mut);
+	if (hid->quirks & HID_QUIRK_ALWAYS_POLL)
+		return;
 
-	/* protecting hid->open to make sure we don't restart
-	 * data acquistion due to a resumption we no longer
-	 * care about
+	/*
+	 * Make sure we don't restart data acquisition due to
+	 * a resumption we no longer care about by avoiding racing
+	 * with hid_start_in().
 	 */
 	spin_lock_irq(&usbhid->lock);
-	if (!--hid->open) {
-		if (!(hid->quirks & HID_QUIRK_ALWAYS_POLL))
-			clear_bit(HID_IN_POLLING, &usbhid->iofl);
-		clear_bit(HID_OPENED, &usbhid->iofl);
-		spin_unlock_irq(&usbhid->lock);
-		hid_cancel_delayed_stuff(usbhid);
-		if (!(hid->quirks & HID_QUIRK_ALWAYS_POLL)) {
-			usb_kill_urb(usbhid->urbin);
-			usbhid->intf->needs_remote_wakeup = 0;
-		}
-	} else {
-		spin_unlock_irq(&usbhid->lock);
-	}
-	mutex_unlock(&hid_open_mut);
+	clear_bit(HID_IN_POLLING, &usbhid->iofl);
+	clear_bit(HID_OPENED, &usbhid->iofl);
+	spin_unlock_irq(&usbhid->lock);
+
+	hid_cancel_delayed_stuff(usbhid);
+	usb_kill_urb(usbhid->urbin);
+	usbhid->intf->needs_remote_wakeup = 0;
 }
 
 /*
-- 
2.13.0.506.g27d5fe0cd-goog

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v2 7/8] greybus: hid: remove custom locking from gb_hid_open/close
  2017-06-07  6:59 [PATCH v2 0/8] HID: Consolidate serializing ope/close in transport drivers Dmitry Torokhov
                   ` (5 preceding siblings ...)
  2017-06-07  6:59 ` [PATCH v2 6/8] HID: usbhid: remove custom locking from usbhid_open/close Dmitry Torokhov
@ 2017-06-07  6:59 ` Dmitry Torokhov
  2017-06-07  7:56   ` Greg Kroah-Hartman
  2017-06-07 10:02   ` Viresh Kumar
  2017-06-07  6:59 ` [PATCH v2 8/8] HID: remove no longer used hid->open field Dmitry Torokhov
                   ` (3 subsequent siblings)
  10 siblings, 2 replies; 15+ messages in thread
From: Dmitry Torokhov @ 2017-06-07  6:59 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires
  Cc: linux-input, linux-kernel, Greg Kroah-Hartman

Now that HID core enforces serialization of transport driver open/close
calls we can remove custom locking from greybus hid driver.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/staging/greybus/hid.c | 43 ++++++++++++++-----------------------------
 1 file changed, 14 insertions(+), 29 deletions(-)

diff --git a/drivers/staging/greybus/hid.c b/drivers/staging/greybus/hid.c
index 730d746fc4c2..465101bbab69 100644
--- a/drivers/staging/greybus/hid.c
+++ b/drivers/staging/greybus/hid.c
@@ -32,8 +32,6 @@ struct gb_hid {
 	char				*inbuf;
 };
 
-static DEFINE_MUTEX(gb_hid_open_mutex);
-
 /* Routines to get controller's information over greybus */
 
 /* Operations performed on greybus */
@@ -346,19 +344,14 @@ static void gb_hid_stop(struct hid_device *hid)
 static int gb_hid_open(struct hid_device *hid)
 {
 	struct gb_hid *ghid = hid->driver_data;
-	int ret = 0;
-
-	mutex_lock(&gb_hid_open_mutex);
-	if (!hid->open++) {
-		ret = gb_hid_set_power(ghid, GB_HID_TYPE_PWR_ON);
-		if (ret < 0)
-			hid->open--;
-		else
-			set_bit(GB_HID_STARTED, &ghid->flags);
-	}
-	mutex_unlock(&gb_hid_open_mutex);
+	int ret;
 
-	return ret;
+	ret = gb_hid_set_power(ghid, GB_HID_TYPE_PWR_ON);
+	if (ret < 0)
+		return ret;
+
+	set_bit(GB_HID_STARTED, &ghid->flags);
+	return 0;
 }
 
 static void gb_hid_close(struct hid_device *hid)
@@ -366,21 +359,13 @@ static void gb_hid_close(struct hid_device *hid)
 	struct gb_hid *ghid = hid->driver_data;
 	int ret;
 
-	/*
-	 * Protecting hid->open to make sure we don't restart data acquistion
-	 * due to a resumption we no longer care about..
-	 */
-	mutex_lock(&gb_hid_open_mutex);
-	if (!--hid->open) {
-		clear_bit(GB_HID_STARTED, &ghid->flags);
-
-		/* Save some power */
-		ret = gb_hid_set_power(ghid, GB_HID_TYPE_PWR_OFF);
-		if (ret)
-			dev_err(&ghid->connection->bundle->dev,
-				"failed to power off (%d)\n", ret);
-	}
-	mutex_unlock(&gb_hid_open_mutex);
+	clear_bit(GB_HID_STARTED, &ghid->flags);
+
+	/* Save some power */
+	ret = gb_hid_set_power(ghid, GB_HID_TYPE_PWR_OFF);
+	if (ret)
+		dev_err(&ghid->connection->bundle->dev,
+			"failed to power off (%d)\n", ret);
 }
 
 static int gb_hid_power(struct hid_device *hid, int lvl)
-- 
2.13.0.506.g27d5fe0cd-goog

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v2 8/8] HID: remove no longer used hid->open field
  2017-06-07  6:59 [PATCH v2 0/8] HID: Consolidate serializing ope/close in transport drivers Dmitry Torokhov
                   ` (6 preceding siblings ...)
  2017-06-07  6:59 ` [PATCH v2 7/8] greybus: hid: remove custom locking from gb_hid_open/close Dmitry Torokhov
@ 2017-06-07  6:59 ` Dmitry Torokhov
  2017-06-07  8:45 ` [PATCH v2 0/8] HID: Consolidate serializing ope/close in transport drivers Andy Shevchenko
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Dmitry Torokhov @ 2017-06-07  6:59 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires
  Cc: linux-input, linux-kernel, Greg Kroah-Hartman

Now that all users have migrated to use hid->ll_open_count, we can remove
hid->open field.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 include/linux/hid.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/linux/hid.h b/include/linux/hid.h
index 5501eb64dbc4..72e8ac667771 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -548,7 +548,6 @@ struct hid_device {							/* device report descriptor */
 	void *hiddev;							/* The hiddev structure */
 	void *hidraw;
 
-	int open;							/* is the device open by anyone? */
 	char name[128];							/* Device name */
 	char phys[64];							/* Device physical location */
 	char uniq[64];							/* Device unique identifier (serial #) */
-- 
2.13.0.506.g27d5fe0cd-goog

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 7/8] greybus: hid: remove custom locking from gb_hid_open/close
  2017-06-07  6:59 ` [PATCH v2 7/8] greybus: hid: remove custom locking from gb_hid_open/close Dmitry Torokhov
@ 2017-06-07  7:56   ` Greg Kroah-Hartman
  2017-06-07 10:02   ` Viresh Kumar
  1 sibling, 0 replies; 15+ messages in thread
From: Greg Kroah-Hartman @ 2017-06-07  7:56 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Jiri Kosina, Benjamin Tissoires, linux-input, linux-kernel

On Tue, Jun 06, 2017 at 11:59:37PM -0700, Dmitry Torokhov wrote:
> Now that HID core enforces serialization of transport driver open/close
> calls we can remove custom locking from greybus hid driver.
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>  drivers/staging/greybus/hid.c | 43 ++++++++++++++-----------------------------
>  1 file changed, 14 insertions(+), 29 deletions(-)

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 2/8] HID: hiddev: use hid_hw_power instead of usbhid_get/put_power
  2017-06-07  6:59 ` [PATCH v2 2/8] HID: hiddev: use hid_hw_power instead of usbhid_get/put_power Dmitry Torokhov
@ 2017-06-07  8:40   ` Andy Shevchenko
  0 siblings, 0 replies; 15+ messages in thread
From: Andy Shevchenko @ 2017-06-07  8:40 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Jiri Kosina, Benjamin Tissoires, linux-input, linux-kernel,
	Greg Kroah-Hartman

On Wed, Jun 7, 2017 at 9:59 AM, Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> Instead of calling into usbhid code directly, let's use the standard
> accessors for the transport HID drivers, and stop clobbering their error
> codes with -EIO.
>
> This also allows us to remove usbhid_get/put_power(), leaving only
> usbhid_power().

>                 break;
> +
>         case PM_HINT_NORMAL:

>         }
> +
>         return r;

I think you can drop above changes.

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 0/8] HID: Consolidate serializing ope/close in transport drivers
  2017-06-07  6:59 [PATCH v2 0/8] HID: Consolidate serializing ope/close in transport drivers Dmitry Torokhov
                   ` (7 preceding siblings ...)
  2017-06-07  6:59 ` [PATCH v2 8/8] HID: remove no longer used hid->open field Dmitry Torokhov
@ 2017-06-07  8:45 ` Andy Shevchenko
  2017-06-07 13:43 ` Benjamin Tissoires
  2017-06-08 11:56 ` Jiri Kosina
  10 siblings, 0 replies; 15+ messages in thread
From: Andy Shevchenko @ 2017-06-07  8:45 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Jiri Kosina, Benjamin Tissoires, linux-input, linux-kernel,
	Greg Kroah-Hartman

On Wed, Jun 7, 2017 at 9:59 AM, Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> This originally came about as report of uhid sending duplicate open and
> premature close when hidraw was used alongside of input. After looking at
> the drivers I think we should consolidate user tracking inside of the HID
> core. While implementing this, there were a few cleanups as well.
>
> V2:
>
> - added greybus hid changes
> - added error handling in hiddev around hid_hw_open which is __much_check

FWIW,
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

>
> Dmitry Torokhov (8):
>   HID: hiddev: use hid_hw_open/close instead of usbhid_open/close
>   HID: hiddev: use hid_hw_power instead of usbhid_get/put_power
>   HID: usbhid: do not rely on hid->open when deciding to do IO
>   HID: serialize hid_hw_open and hid_hw_close
>   HID: i2c-hid: remove custom locking from i2c_hid_open/close
>   HID: usbhid: remove custom locking from usbhid_open/close
>   greybus: hid: remove custom locking from gb_hid_open/close
>   HID: remove no longer used hid->open field
>
>  drivers/hid/hid-core.c        |  89 +++++++++++++++++++++++++
>  drivers/hid/i2c-hid/i2c-hid.c |  32 +++------
>  drivers/hid/usbhid/hid-core.c | 150 ++++++++++++++++++++----------------------
>  drivers/hid/usbhid/hiddev.c   |  24 +++----
>  drivers/hid/usbhid/usbhid.h   |  15 +++--
>  drivers/staging/greybus/hid.c |  43 ++++--------
>  include/linux/hid.h           |  73 +++-----------------
>  7 files changed, 214 insertions(+), 212 deletions(-)
>
> Thanks.
>
> --
> Dmitry
>



-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 7/8] greybus: hid: remove custom locking from gb_hid_open/close
  2017-06-07  6:59 ` [PATCH v2 7/8] greybus: hid: remove custom locking from gb_hid_open/close Dmitry Torokhov
  2017-06-07  7:56   ` Greg Kroah-Hartman
@ 2017-06-07 10:02   ` Viresh Kumar
  1 sibling, 0 replies; 15+ messages in thread
From: Viresh Kumar @ 2017-06-07 10:02 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Jiri Kosina, Benjamin Tissoires, linux-input, linux-kernel,
	Greg Kroah-Hartman

On Wed, Jun 7, 2017 at 12:29 PM, Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> Now that HID core enforces serialization of transport driver open/close
> calls we can remove custom locking from greybus hid driver.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>  drivers/staging/greybus/hid.c | 43 ++++++++++++++-----------------------------
>  1 file changed, 14 insertions(+), 29 deletions(-)

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 0/8] HID: Consolidate serializing ope/close in transport drivers
  2017-06-07  6:59 [PATCH v2 0/8] HID: Consolidate serializing ope/close in transport drivers Dmitry Torokhov
                   ` (8 preceding siblings ...)
  2017-06-07  8:45 ` [PATCH v2 0/8] HID: Consolidate serializing ope/close in transport drivers Andy Shevchenko
@ 2017-06-07 13:43 ` Benjamin Tissoires
  2017-06-08 11:56 ` Jiri Kosina
  10 siblings, 0 replies; 15+ messages in thread
From: Benjamin Tissoires @ 2017-06-07 13:43 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Jiri Kosina, linux-input, linux-kernel, Greg Kroah-Hartman

On Jun 06 2017 or thereabouts, Dmitry Torokhov wrote:
> This originally came about as report of uhid sending duplicate open and
> premature close when hidraw was used alongside of input. After looking at
> the drivers I think we should consolidate user tracking inside of the HID
> core. While implementing this, there were a few cleanups as well.
> 
> V2:
> 
> - added greybus hid changes
> - added error handling in hiddev around hid_hw_open which is __much_check
> 

Looks good to me:
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>

> Dmitry Torokhov (8):
>   HID: hiddev: use hid_hw_open/close instead of usbhid_open/close
>   HID: hiddev: use hid_hw_power instead of usbhid_get/put_power
>   HID: usbhid: do not rely on hid->open when deciding to do IO
>   HID: serialize hid_hw_open and hid_hw_close
>   HID: i2c-hid: remove custom locking from i2c_hid_open/close
>   HID: usbhid: remove custom locking from usbhid_open/close
>   greybus: hid: remove custom locking from gb_hid_open/close
>   HID: remove no longer used hid->open field
> 
>  drivers/hid/hid-core.c        |  89 +++++++++++++++++++++++++
>  drivers/hid/i2c-hid/i2c-hid.c |  32 +++------
>  drivers/hid/usbhid/hid-core.c | 150 ++++++++++++++++++++----------------------
>  drivers/hid/usbhid/hiddev.c   |  24 +++----
>  drivers/hid/usbhid/usbhid.h   |  15 +++--
>  drivers/staging/greybus/hid.c |  43 ++++--------
>  include/linux/hid.h           |  73 +++-----------------
>  7 files changed, 214 insertions(+), 212 deletions(-)
> 
> Thanks.
> 
> -- 
> Dmitry
> 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 0/8] HID: Consolidate serializing ope/close in transport drivers
  2017-06-07  6:59 [PATCH v2 0/8] HID: Consolidate serializing ope/close in transport drivers Dmitry Torokhov
                   ` (9 preceding siblings ...)
  2017-06-07 13:43 ` Benjamin Tissoires
@ 2017-06-08 11:56 ` Jiri Kosina
  10 siblings, 0 replies; 15+ messages in thread
From: Jiri Kosina @ 2017-06-08 11:56 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Benjamin Tissoires, linux-input, linux-kernel, Greg Kroah-Hartman

On Tue, 6 Jun 2017, Dmitry Torokhov wrote:

> This originally came about as report of uhid sending duplicate open and
> premature close when hidraw was used alongside of input. After looking at
> the drivers I think we should consolidate user tracking inside of the HID
> core. While implementing this, there were a few cleanups as well.
> 
> V2:
> 
> - added greybus hid changes
> - added error handling in hiddev around hid_hw_open which is __much_check

I've applied the series, thanks Dmitry.

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2017-06-08 11:56 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-07  6:59 [PATCH v2 0/8] HID: Consolidate serializing ope/close in transport drivers Dmitry Torokhov
2017-06-07  6:59 ` [PATCH v2 1/8] HID: hiddev: use hid_hw_open/close instead of usbhid_open/close Dmitry Torokhov
2017-06-07  6:59 ` [PATCH v2 2/8] HID: hiddev: use hid_hw_power instead of usbhid_get/put_power Dmitry Torokhov
2017-06-07  8:40   ` Andy Shevchenko
2017-06-07  6:59 ` [PATCH v2 3/8] HID: usbhid: do not rely on hid->open when deciding to do IO Dmitry Torokhov
2017-06-07  6:59 ` [PATCH v2 4/8] HID: serialize hid_hw_open and hid_hw_close Dmitry Torokhov
2017-06-07  6:59 ` [PATCH v2 5/8] HID: i2c-hid: remove custom locking from i2c_hid_open/close Dmitry Torokhov
2017-06-07  6:59 ` [PATCH v2 6/8] HID: usbhid: remove custom locking from usbhid_open/close Dmitry Torokhov
2017-06-07  6:59 ` [PATCH v2 7/8] greybus: hid: remove custom locking from gb_hid_open/close Dmitry Torokhov
2017-06-07  7:56   ` Greg Kroah-Hartman
2017-06-07 10:02   ` Viresh Kumar
2017-06-07  6:59 ` [PATCH v2 8/8] HID: remove no longer used hid->open field Dmitry Torokhov
2017-06-07  8:45 ` [PATCH v2 0/8] HID: Consolidate serializing ope/close in transport drivers Andy Shevchenko
2017-06-07 13:43 ` Benjamin Tissoires
2017-06-08 11:56 ` Jiri Kosina

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).