Skip to contentSkip to conversation

HID: rmi: Make sure the HID device is opened on resume

PATCH In review Lyude 4 participants 9 messages Jul 23, 2017 – Sep 8, 2017

Subsystems (2)
lore
Share & tools
lore

Lyude

author
#0 lore raw

PATCH 1/1 HID: rmi: Make sure the HID device is opened on resume

So it looks like that suspend/resume has actually always been broken on hid-rmi. The fact it worked was a rather silly coincidence that was relying on the HID device to already be opened upon resume. This means that so long as anything was reading the /dev/input/eventX node for for an RMI device, it would suspend and resume correctly. As well, if nothing happened to be keeping the HID device away it would shut off, then the RMI driver would get confused on resume when it stopped responding and explode.

So, call hid_hw_open() in rmi_post_resume() so we make sure that the device is alive before we try talking to it.

This fixes RMI device suspend/resume over HID.

---
 drivers/hid/hid-rmi.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/hid/hid-rmi.c +11 -4
index 5b40c2614599..e7d124f9a27f 100644
@@ -431,22 +431,29 @@ static int rmi_post_resume(struct hid_device *hdev)
 {
 	struct rmi_data *data = hid_get_drvdata(hdev);
 	struct rmi_device *rmi_dev = data->xport.rmi_dev;
-	int ret;
+	int ret = 0;
 
 	if (!(data->device_flags & RMI_DEVICE))
 		return 0;
 
-	ret = rmi_reset_attn_mode(hdev);
+	/* Make sure the HID device is ready to receive events */
+	ret = hid_hw_open(hdev);
 	if (ret)
 		return ret;
 
+	ret = rmi_reset_attn_mode(hdev);
+	if (ret)
+		goto out;
+
 	ret = rmi_driver_resume(rmi_dev, false);
 	if (ret) {
 		hid_warn(hdev, "Failed to resume device: %d\n", ret);
-		return ret;
+		goto out;
 	}
 
-	return 0;
+out:
+	hid_hw_close(hdev);
+	return ret;
 }
 #endif /* CONFIG_PM */
 
Signature · 1 line
2.13.3
#1 lore raw

drivers/hid/hid-rmi.c static int rmi_post_resume(struct hid_device *hdev) · line 434

Quoted 7 lines · Lyude

So, call hid_hw_open() in rmi_post_resume() so we make sure that the device is alive before we try talking to it.

This fixes RMI device suspend/resume over HID.

drivers/hid/hid-rmi.c +1 -1
-       int ret;
+       int ret = 0;

What's the point?

Quoted 9 lines
        if (!(data->device_flags & RMI_DEVICE))
                return 0;
drivers/hid/hid-rmi.c +2 -1
-       ret = rmi_reset_attn_mode(hdev);
+       /* Make sure the HID device is ready to receive events */
+       ret = hid_hw_open(hdev);
        if (ret)
                return ret;
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#2 lore raw
Quoted 11 lines · Andy Shevchenko

drivers/hid/hid-rmi.c static int rmi_post_resume(struct hid_device *hdev) · line 434

Quoted 7 lines · Lyude

So, call hid_hw_open() in rmi_post_resume() so we make sure that the
device is alive before we try talking to it.

This fixes RMI device suspend/resume over HID.

drivers/hid/hid-rmi.c +1 -1
-       int ret;
+       int ret = 0;

What's the point?

So that we can use the same out: label at the end of the function that calls hid_hw_close() to return success. This being said though I just realized that setting ret will initialize it to 0 anyway, so I guess this can be dropped

Quoted 12 lines
Quoted 10 lines

        if (!(data->device_flags & RMI_DEVICE))
                return 0;
drivers/hid/hid-rmi.c +2 -1
-       ret = rmi_reset_attn_mode(hdev);
+       /* Make sure the HID device is ready to receive events */
+       ret = hid_hw_open(hdev);
        if (ret)
                return ret;
maintainer
#3 lore raw
Quoted 8 lines · Lyude Paul
Quoted 8 lines
Quoted 7 lines

So, call hid_hw_open() in rmi_post_resume() so we make sure that the
device is alive before we try talking to it.

This fixes RMI device suspend/resume over HID.

drivers/hid/hid-rmi.c +1 -1
-       int ret;
+       int ret = 0;
Quoted 5 lines
Quoted 1 line

What's the point?

So that we can use the same out: label at the end of the function that calls hid_hw_close() to return success. This being said though I just realized that setting ret will initialize it to 0 anyway, so I guess this can be dropped

Andy's point was that hid_hw_open() is obviously re-initializing the ret before its first use as a return value, so there is no need to initialize it at a declaration time.

Signature · 2 lines
Jiri Kosina
SUSE Labs
author
#4 lore raw

Yeah I noticed that, sorry if my response wasn't very clear! Should probably wait to have my morning coffee before responding to these messages :P

Quoted 27 lines · Jiri Kosina
Quoted 11 lines · Lyude Paul
Quoted 10 lines

drivers/hid/hid-rmi.c static int rmi_post_resume(struct hid_device *hdev) · line 434

Quoted 8 lines

So, call hid_hw_open() in rmi_post_resume() so we make sure that
the
device is alive before we try talking to it.

This fixes RMI device suspend/resume over HID.

drivers/hid/hid-rmi.c +1 -1
-       int ret;
+       int ret = 0;

What's the point?

Quoted 7 lines

So that we can use the same out: label at the end of the function that
calls hid_hw_close() to return success. This being said though I just
realized that setting ret will initialize it to 0 anyway, so I guess
this can be dropped

Andy's point was that hid_hw_open() is obviously re-initializing the ret
before its first use as a return value, so there is no need to initialize
it at a declaration time.

#5 lore raw
In reply to Lyude
Quoted 8 lines · Lyude

So it looks like that suspend/resume has actually always been broken on hid-rmi. The fact it worked was a rather silly coincidence that was relying on the HID device to already be opened upon resume. This means that so long as anything was reading the /dev/input/eventX node for for an RMI device, it would suspend and resume correctly. As well, if nothing happened to be keeping the HID device away it would shut off, then the RMI driver would get confused on resume when it stopped responding and explode.

Oh, good finding. However, given that there are few other drivers not calling hid_hw_open during their .reset_resume() callback and those drivers also are communicating with the device, I wonder if we should not have something more generic, that will call hid_hw_open/close in the transport layer directly.

I do not recall having seen bugs for Wacom devices, so maybe this is something i2c-hid related, but it wouldn't hurt I guess to open/close the device before calling reset_resume.

Cheers,
Benjamin

Quoted 54 lines

So, call hid_hw_open() in rmi_post_resume() so we make sure that the device is alive before we try talking to it.

This fixes RMI device suspend/resume over HID.

---
 drivers/hid/hid-rmi.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/hid/hid-rmi.c +11 -4
index 5b40c2614599..e7d124f9a27f 100644
@@ -431,22 +431,29 @@ static int rmi_post_resume(struct hid_device *hdev)
 {
 	struct rmi_data *data = hid_get_drvdata(hdev);
 	struct rmi_device *rmi_dev = data->xport.rmi_dev;
-	int ret;
+	int ret = 0;
 
 	if (!(data->device_flags & RMI_DEVICE))
 		return 0;
 
-	ret = rmi_reset_attn_mode(hdev);
+	/* Make sure the HID device is ready to receive events */
+	ret = hid_hw_open(hdev);
 	if (ret)
 		return ret;
 
+	ret = rmi_reset_attn_mode(hdev);
+	if (ret)
+		goto out;
+
 	ret = rmi_driver_resume(rmi_dev, false);
 	if (ret) {
 		hid_warn(hdev, "Failed to resume device: %d\n", ret);
-		return ret;
+		goto out;
 	}
 
-	return 0;
+out:
+	hid_hw_close(hdev);
+	return ret;
 }
 #endif /* CONFIG_PM */
 
Signature · 1 line
2.13.3
author
#6 lore raw
Quoted 14 lines · Benjamin Tissoires
Quoted 4 lines · Lyude

So it looks like that suspend/resume has actually always been broken on
hid-rmi. The fact it worked was a rather silly coincidence that was relying on the HID device to already be opened upon resume. This

Quoted 8 lines

means
that so long as anything was reading the /dev/input/eventX node for for
an RMI device, it would suspend and resume correctly. As well, if nothing happened to be keeping the HID device away it would shut off,
then the RMI driver would get confused on resume when it stopped responding and explode.

Quoted 6 lines

Oh, good finding. However, given that there are few other drivers not calling hid_hw_open during their .reset_resume() callback and those drivers also are communicating with the device, I wonder if we should not have something more generic, that will call hid_hw_open/close in the
transport layer directly.

This sounds like a good idea, especially since a call like this is rather easy to miss. I will look into doing that for v2

Quoted 65 lines

I do not recall having seen bugs for Wacom devices, so maybe this is something i2c-hid related, but it wouldn't hurt I guess to open/close the device before calling reset_resume.

Cheers,
Benjamin

Quoted 57 lines

So, call hid_hw_open() in rmi_post_resume() so we make sure that the
device is alive before we try talking to it.

This fixes RMI device suspend/resume over HID.

---
 drivers/hid/hid-rmi.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/hid/hid-rmi.c +11 -4
index 5b40c2614599..e7d124f9a27f 100644
@@ -431,22 +431,29 @@ static int rmi_post_resume(struct hid_device
 *hdev)
 {
 	struct rmi_data *data = hid_get_drvdata(hdev);
 	struct rmi_device *rmi_dev = data->xport.rmi_dev;
-	int ret;
+	int ret = 0;
 
 	if (!(data->device_flags & RMI_DEVICE))
 		return 0;
 
-	ret = rmi_reset_attn_mode(hdev);
+	/* Make sure the HID device is ready to receive events */
+	ret = hid_hw_open(hdev);
 	if (ret)
 		return ret;
 
+	ret = rmi_reset_attn_mode(hdev);
+	if (ret)
+		goto out;
+
 	ret = rmi_driver_resume(rmi_dev, false);
 	if (ret) {
 		hid_warn(hdev, "Failed to resume device: %d\n",
 ret);
-		return ret;
+		goto out;
 	}
 
-	return 0;
+out:
+	hid_hw_close(hdev);
+	return ret;
 }

#endif /* CONFIG_PM */

Signature · 1 line
2.13.3
Reviewed-by
#7 lore raw
Quoted 15 lines · Lyude Paul
Quoted 14 lines · Benjamin Tissoires
Quoted 12 lines · Lyude

So it looks like that suspend/resume has actually always been broken on
hid-rmi. The fact it worked was a rather silly coincidence that was relying on the HID device to already be opened upon resume. This means
that so long as anything was reading the /dev/input/eventX node for for
an RMI device, it would suspend and resume correctly. As well, if nothing happened to be keeping the HID device away it would shut off,
then the RMI driver would get confused on resume when it stopped responding and explode.

Quoted 8 lines
Quoted 6 lines

Oh, good finding. However, given that there are few other drivers not calling hid_hw_open during their .reset_resume() callback and those drivers also are communicating with the device, I wonder if we should not have something more generic, that will call hid_hw_open/close in the
transport layer directly.

This sounds like a good idea, especially since a call like this is rather easy to miss. I will look into doing that for v2

I know I requested a v2, but meanwhile some users are experiencing delays at resume:
https://bugzilla.kernel.org/show_bug.cgi?id=196851

Jiri, could you take this one in v4.14 (maybe with @stable) and we'll figure out a way to fix this properly later (looks like the .resume and .reset_resume are called from the transport drivers, not hid-core, so we might need a little bit of testing).

In its current form (with the nitpick Andy noticed):

Cheers,
Benjamin

Quoted 65 lines
Quoted 65 lines

I do not recall having seen bugs for Wacom devices, so maybe this is something i2c-hid related, but it wouldn't hurt I guess to open/close the device before calling reset_resume.

Cheers,
Benjamin

Quoted 57 lines

So, call hid_hw_open() in rmi_post_resume() so we make sure that the
device is alive before we try talking to it.

This fixes RMI device suspend/resume over HID.

---
 drivers/hid/hid-rmi.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/hid/hid-rmi.c +11 -4
index 5b40c2614599..e7d124f9a27f 100644
@@ -431,22 +431,29 @@ static int rmi_post_resume(struct hid_device
 *hdev)
 {
 	struct rmi_data *data = hid_get_drvdata(hdev);
 	struct rmi_device *rmi_dev = data->xport.rmi_dev;
-	int ret;
+	int ret = 0;
 
 	if (!(data->device_flags & RMI_DEVICE))
 		return 0;
 
-	ret = rmi_reset_attn_mode(hdev);
+	/* Make sure the HID device is ready to receive events */
+	ret = hid_hw_open(hdev);
 	if (ret)
 		return ret;
 
+	ret = rmi_reset_attn_mode(hdev);
+	if (ret)
+		goto out;
+
 	ret = rmi_driver_resume(rmi_dev, false);
 	if (ret) {
 		hid_warn(hdev, "Failed to resume device: %d\n",
 ret);
-		return ret;
+		goto out;
 	}
 
-	return 0;
+out:
+	hid_hw_close(hdev);
+	return ret;
 }

#endif /* CONFIG_PM */

Signature · 1 line
2.13.3
maintainer
#8 lore raw
Quoted 11 lines · Benjamin Tissoires

I know I requested a v2, but meanwhile some users are experiencing delays at resume:
https://bugzilla.kernel.org/show_bug.cgi?id=196851

Jiri, could you take this one in v4.14 (maybe with @stable) and we'll figure out a way to fix this properly later (looks like the .resume and .reset_resume are called from the transport drivers, not hid-core, so we might need a little bit of testing).

In its current form (with the nitpick Andy noticed):

Ok, makes sense. Now applied to for-4.14/upstream-fixes. Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs