linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] HID: usbhid: get/put around clearing needs_remote_wakeup
@ 2014-11-13 20:16 Benson Leung
  2014-11-13 20:41 ` Alan Stern
                   ` (2 more replies)
  0 siblings, 3 replies; 25+ messages in thread
From: Benson Leung @ 2014-11-13 20:16 UTC (permalink / raw)
  To: johan, jkosina, linux-usb, linux-input, linux-kernel; +Cc: snanda, Benson Leung

usbhid->intf->needs_remote_wakeup is set when a device is
opened, and is cleared when a device is closed.

When a usbhid device that does not support remote wake
( i.e. !device_can_wakeup() ) is closed, we fail out of
autosuspend_check() because the autosuspend check is called
before the flag is cleared as a result of usb_kill_urb(usbhid->urbin);

The result is that a device that may otherwise autosuspend will
fail to enter suspend again after all handles to it are closed.

In usbhid_open, usb_autopm_get_interface is called
before setting the needs_remote_wakeup flag, and
usb_autopm_put_interface is called after hid_start_in.

However, when the device is closed in usbhid_close, the same
protection isn't there when clearing needs_remote_wakeup. This will
add that to usbhid_close as well as usbhid_stop.

Signed-off-by: Benson Leung <bleung@chromium.org>
---
 drivers/hid/usbhid/hid-core.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index 04e34b9..2a0b91d 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -734,8 +734,15 @@ void usbhid_close(struct hid_device *hid)
 		spin_unlock_irq(&usbhid->lock);
 		hid_cancel_delayed_stuff(usbhid);
 		if (!(hid->quirks & HID_QUIRK_ALWAYS_POLL)) {
+			int autopm_error;
+
+			autopm_error = usb_autopm_get_interface(usbhid->intf);
+
 			usb_kill_urb(usbhid->urbin);
 			usbhid->intf->needs_remote_wakeup = 0;
+
+			if (!autopm_error)
+				usb_autopm_put_interface(usbhid->intf);
 		}
 	} else {
 		spin_unlock_irq(&usbhid->lock);
@@ -1179,9 +1186,17 @@ 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) {
+		int autopm_error;
+
+		autopm_error = usb_autopm_get_interface(usbhid->intf);
+
 		usbhid->intf->needs_remote_wakeup = 0;
 
+		if (!autopm_error)
+			usb_autopm_put_interface(usbhid->intf);
+	}
+
 	clear_bit(HID_STARTED, &usbhid->iofl);
 	spin_lock_irq(&usbhid->lock);	/* Sync with error and led handlers */
 	set_bit(HID_DISCONNECTED, &usbhid->iofl);
-- 
2.1.0.rc2.206.gedb03e5


^ permalink raw reply related	[flat|nested] 25+ messages in thread
* [PATCH] HID: usbhid: get/put around clearing needs_remote_wakeup
@ 2017-09-08 17:43 Dmitry Torokhov
  2017-09-09  7:35 ` Oliver Neukum
  0 siblings, 1 reply; 25+ messages in thread
From: Dmitry Torokhov @ 2017-09-08 17:43 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: Benjamin Tissoires, Guenter Roeck, Benson Leung, linux-usb,
	linux-input, linux-kernel

From: Benson Leung <bleung@chromium.org>

usbhid->intf->needs_remote_wakeup is set when a device is opened, and is
cleared when a device is closed.

In usbhid_open, usb_autopm_get_interface is called before setting the
needs_remote_wakeup flag, and usb_autopm_put_interface is called after
hid_start_in. However, when the device is closed in usbhid_close, we
simply reset the flag and the device stays awake even though it could be
suspended.

This patch adds calls to usb_autopm_get_interface and
usb_autopm_put_interface when we reset usbhid->intf->needs_remote_wakeup
flag, giving the system chance to put the device to sleep.

Signed-off-by: Benson Leung <bleung@chromium.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/hid/usbhid/hid-core.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index 089bad8a9a21..174d87f0e3e6 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -729,6 +729,7 @@ static int usbhid_open(struct hid_device *hid)
 static void usbhid_close(struct hid_device *hid)
 {
 	struct usbhid_device *usbhid = hid->driver_data;
+	int autopm_error;
 
 	/*
 	 * Make sure we don't restart data acquisition due to
@@ -745,8 +746,14 @@ static void usbhid_close(struct hid_device *hid)
 		return;
 
 	hid_cancel_delayed_stuff(usbhid);
+
+	autopm_error = usb_autopm_get_interface(usbhid->intf);
+
 	usb_kill_urb(usbhid->urbin);
 	usbhid->intf->needs_remote_wakeup = 0;
+
+	if (!autopm_error)
+		usb_autopm_put_interface(usbhid->intf);
 }
 
 /*
@@ -1176,13 +1183,18 @@ static int usbhid_start(struct hid_device *hid)
 static void usbhid_stop(struct hid_device *hid)
 {
 	struct usbhid_device *usbhid = hid->driver_data;
+	int autopm_error;
 
 	if (WARN_ON(!usbhid))
 		return;
 
 	if (hid->quirks & HID_QUIRK_ALWAYS_POLL) {
 		clear_bit(HID_IN_POLLING, &usbhid->iofl);
+
+		autopm_error = usb_autopm_get_interface(usbhid->intf);
 		usbhid->intf->needs_remote_wakeup = 0;
+		if (!autopm_error)
+			usb_autopm_put_interface(usbhid->intf);
 	}
 
 	clear_bit(HID_STARTED, &usbhid->iofl);
-- 
2.14.1.581.gf28d330327-goog


-- 
Dmitry

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

end of thread, other threads:[~2017-09-20  1:39 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-13 20:16 [PATCH] HID: usbhid: get/put around clearing needs_remote_wakeup Benson Leung
2014-11-13 20:41 ` Alan Stern
2014-11-13 20:44   ` Benson Leung
     [not found]     ` <CANLzEksGg0KyWOS+WYv_U8GzSJ4C_H0LTpdXvz8Ae-8mH6K41w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-11-13 21:18       ` Alan Stern
2014-11-13 21:41         ` Benson Leung
2014-11-13 22:11           ` Alan Stern
2014-11-13 22:15             ` Benson Leung
     [not found]               ` <CANLzEksHgo_tQiwJoUtXd0iV7tDXq0ieNrAXgtXwPtxxPBWrgw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-11-14 15:17                 ` Alan Stern
2014-11-22  0:44                   ` Benson Leung
2014-11-22 15:55                     ` Alan Stern
2014-11-22 16:02                       ` Alan Stern
2014-11-25  1:29                       ` Benson Leung
2014-11-25 15:24                         ` Alan Stern
2014-11-25 15:29                           ` Benson Leung
2014-11-13 21:25 ` [PATCH v2] HID: usbhid: clear needs_remote_wakeup before usb_kill_urb Benson Leung
2014-11-14  9:08 ` [PATCH] HID: usbhid: get/put around clearing needs_remote_wakeup Oliver Neukum
2014-11-22  1:00   ` Benson Leung
2014-11-24  9:13     ` Oliver Neukum
     [not found]       ` <1416820395.19925.4.camel-AfvqVibwNMkMNNZnWhT/Jw@public.gmane.org>
2014-11-25  0:56         ` Benson Leung
2014-11-25  9:53           ` Oliver Neukum
  -- strict thread matches above, loose matches on Subject: below --
2017-09-08 17:43 Dmitry Torokhov
2017-09-09  7:35 ` Oliver Neukum
     [not found]   ` <1504942552.10395.2.camel-IBi9RG/b67k@public.gmane.org>
2017-09-11 20:02     ` Benson Leung
2017-09-11 23:29       ` Benson Leung
2017-09-20  1:39         ` Dmitry Torokhov

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