Skip to contentSkip to conversation

HID: rmi: Check that a device is a RMI device before calling RMI functions

PATCH In review Andrew Duggan 4 participants 7 messages Oct 18, 2017 – Oct 19, 2017 HID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: rmi: Check that a device is a RMI device before calling RMI functions

The hid-rmi driver may handle non rmi devices on composite USB devices. Callbacks need to make sure that the current device is a RMI device before calling RMI specific functions. Most callbacks already have this check, but this patch adds checks to the remaining callbacks.

---
This is the patch which hopefully will address the X1 tablet dock freeze:
http://www.spinics.net/lists/linux-input/msg53582.html

I was not able to test on a composite USB device so I have not tested confirmed this will fix the reported issues. But, based on the description I think it will. I also added a check for rmi_raw_event() since it could be possible that another hid device using one of the same report IDs as an RMI device could result in calling into unitialized RMI functions. It was also the only callbacl left not checking the RMI_DEVICE flag. I wonder if this explains the attach crash.

Anyway, I would appriciate it if Hendrik or someone else with the device could test this patch to confirm it fixes the reported behavior.

Thanks,
Andrew

 drivers/hid/hid-rmi.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/hid/hid-rmi.c +10 -3
index 5b40c26..d987e02 100644
@@ -368,6 +368,11 @@ static int rmi_check_sanity(struct hid_device *hdev, u8 *data, int size)
 static int rmi_raw_event(struct hid_device *hdev,
 		struct hid_report *report, u8 *data, int size)
 {
+	struct rmi_data *hdata = hid_get_drvdata(hdev);
+
+	if (!(hdata->device_flags & RMI_DEVICE))
+		return 0;
+
 	size = rmi_check_sanity(hdev, data, size);
 	if (size < 2)
 		return 0;
@@ -706,9 +711,11 @@ static void rmi_remove(struct hid_device *hdev)
 {
 	struct rmi_data *hdata = hid_get_drvdata(hdev);
 
-	clear_bit(RMI_STARTED, &hdata->flags);
-	cancel_work_sync(&hdata->reset_work);
-	rmi_unregister_transport_device(&hdata->xport);
+	if (hdata->device_flags & RMI_DEVICE) {
+		clear_bit(RMI_STARTED, &hdata->flags);
+		cancel_work_sync(&hdata->reset_work);
+		rmi_unregister_transport_device(&hdata->xport);
+	}
 
 	hid_hw_stop(hdev);
 }
Signature · 1 line
2.7.4
#1 lore raw
Quoted 17 lines · Andrew Duggan

The hid-rmi driver may handle non rmi devices on composite USB devices. Callbacks need to make sure that the current device is a RMI device before calling RMI specific functions. Most callbacks already have this check, but this patch adds checks to the remaining callbacks.

---
This is the patch which hopefully will address the X1 tablet dock freeze:
http://www.spinics.net/lists/linux-input/msg53582.html

I was not able to test on a composite USB device so I have not tested confirmed this will fix the reported issues. But, based on the description I think it will. I also added a check for rmi_raw_event() since it could be possible that another hid device using one of the same report IDs as an RMI device could result in calling into unitialized RMI functions. It was also the only callbacl left not checking the RMI_DEVICE flag. I wonder if this explains the attach crash.

Quoted 2 lines

Anyway, I would appriciate it if Hendrik or someone else with the device could test this patch to confirm it fixes the reported behavior.

Shouldn't rmi_hid_reset() also get the same check?

Quoted 1 line

From what I can see, even if the patch doesn't fix the immediate issue,

such a patch should definitively go in as those checks are clearly missing.

Cheers,
Benjamin

Quoted 41 lines

Thanks,
Andrew

 drivers/hid/hid-rmi.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/hid/hid-rmi.c +10 -3
index 5b40c26..d987e02 100644
@@ -368,6 +368,11 @@ static int rmi_check_sanity(struct hid_device *hdev, u8 *data, int size)
 static int rmi_raw_event(struct hid_device *hdev,
 		struct hid_report *report, u8 *data, int size)
 {
+	struct rmi_data *hdata = hid_get_drvdata(hdev);
+
+	if (!(hdata->device_flags & RMI_DEVICE))
+		return 0;
+
 	size = rmi_check_sanity(hdev, data, size);
 	if (size < 2)
 		return 0;
@@ -706,9 +711,11 @@ static void rmi_remove(struct hid_device *hdev)
 {
 	struct rmi_data *hdata = hid_get_drvdata(hdev);
 
-	clear_bit(RMI_STARTED, &hdata->flags);
-	cancel_work_sync(&hdata->reset_work);
-	rmi_unregister_transport_device(&hdata->xport);
+	if (hdata->device_flags & RMI_DEVICE) {
+		clear_bit(RMI_STARTED, &hdata->flags);
+		cancel_work_sync(&hdata->reset_work);
+		rmi_unregister_transport_device(&hdata->xport);
+	}
 
 	hid_hw_stop(hdev);
 }
Signature · 1 line
2.7.4
maintainer
#2 lore raw
Quoted 17 lines · Benjamin Tissoires
Quoted 17 lines

The hid-rmi driver may handle non rmi devices on composite USB devices. Callbacks need to make sure that the current device is a RMI device before calling RMI specific functions. Most callbacks already have this check, but this patch adds checks to the remaining callbacks.

---
This is the patch which hopefully will address the X1 tablet dock freeze:
http://www.spinics.net/lists/linux-input/msg53582.html

I was not able to test on a composite USB device so I have not tested confirmed this will fix the reported issues. But, based on the description I think it will. I also added a check for rmi_raw_event() since it could be possible that another hid device using one of the same report IDs as an RMI device could result in calling into unitialized RMI functions. It was also the only callbacl left not checking the RMI_DEVICE flag. I wonder if this explains the attach crash.

Quoted 4 lines
Quoted 2 lines

Anyway, I would appriciate it if Hendrik or someone else with the device could test this patch to confirm it fixes the reported behavior.

Shouldn't rmi_hid_reset() also get the same check?

I think so as well.

Quoted 4 lines

From what I can see, even if the patch doesn't fix the immediate issue, such a patch should definitively go in as those checks are clearly missing.

Agreed; however I'd like to get Hendrik's Tested-by: if possible in case this really fixes the issue, so I am not merging it right away.

Hendrik, are you by any chance able to test this patch in a reasonable timeframe please?

Thanks!

Signature · 2 lines
Jiri Kosina
SUSE Labs
#3 lore raw
Quoted 19 lines · Jiri Kosina
Quoted 17 lines · Benjamin Tissoires
Quoted 17 lines

The hid-rmi driver may handle non rmi devices on composite USB devices. Callbacks need to make sure that the current device is a RMI device before calling RMI specific functions. Most callbacks already have this check, but this patch adds checks to the remaining callbacks.

---
This is the patch which hopefully will address the X1 tablet dock freeze:
http://www.spinics.net/lists/linux-input/msg53582.html

I was not able to test on a composite USB device so I have not tested confirmed this will fix the reported issues. But, based on the description I think it will. I also added a check for rmi_raw_event() since it could be possible that another hid device using one of the same report IDs as an RMI device could result in calling into unitialized RMI functions. It was also the only callbacl left not checking the RMI_DEVICE flag. I wonder if this explains the attach crash.

Quoted 4 lines
Quoted 3 lines
Quoted 2 lines

Anyway, I would appriciate it if Hendrik or someone else with the device could test this patch to confirm it fixes the reported behavior.

Shouldn't rmi_hid_reset() also get the same check?

I think so as well.

Since rmi_hid_reset() is only called from with in the RMI4 driver I didn't think that it needed a check. All of the functions set in struct hid_driver should  now check the RMI_DEVICE flag before calling into the RMI4 driver. But, if I am missing something we can add additional checks.

Thanks,
Andrew

Quoted 11 lines
Quoted 3 lines

From what I can see, even if the patch doesn't fix the immediate issue,
such a patch should definitively go in as those checks are clearly missing.

Agreed; however I'd like to get Hendrik's Tested-by: if possible in case this really fixes the issue, so I am not merging it right away.

Hendrik, are you by any chance able to test this patch in a reasonable timeframe please?

Thanks!

Tested-by
#5 lore raw
In reply to Jiri Kosina
Quoted 31 lines · Jiri Kosina
Quoted 17 lines · Benjamin Tissoires
Quoted 17 lines

The hid-rmi driver may handle non rmi devices on composite USB devices. Callbacks need to make sure that the current device is a RMI device before calling RMI specific functions. Most callbacks already have this check, but this patch adds checks to the remaining callbacks.

---
This is the patch which hopefully will address the X1 tablet dock freeze:
http://www.spinics.net/lists/linux-input/msg53582.html

I was not able to test on a composite USB device so I have not tested confirmed this will fix the reported issues. But, based on the description I think it will. I also added a check for rmi_raw_event() since it could be possible that another hid device using one of the same report IDs as an RMI device could result in calling into unitialized RMI functions. It was also the only callbacl left not checking the RMI_DEVICE flag. I wonder if this explains the attach crash.

Quoted 4 lines
Quoted 2 lines

Anyway, I would appriciate it if Hendrik or someone else with the device could test this patch to confirm it fixes the reported behavior.

Shouldn't rmi_hid_reset() also get the same check?

I think so as well.

Quoted 4 lines

From what I can see, even if the patch doesn't fix the immediate issue, such a patch should definitively go in as those checks are clearly missing.

Quoted 8 lines

Agreed; however I'd like to get Hendrik's Tested-by: if possible in case this really fixes the issue, so I am not merging it right away.

Hendrik, are you by any chance able to test this patch in a reasonable timeframe please?

Thanks!

Confirmed, the patch fixes the probem for me.
All freezes/Oops and rmi or input related error messages are gone. Even keyboard and touchpad are working now!

Tested 4.13 and 4.14.0-rc3 (Debian) with the patch, repeated (un)docking and booting with/without keyboard dock attached.

Thank you very much!
Hendrik

Reviewed-by
#4 lore raw
In reply to Andrew Duggan
Quoted 24 lines · Andrew Duggan
Quoted 21 lines · Jiri Kosina
Quoted 19 lines · Benjamin Tissoires
Quoted 19 lines

The hid-rmi driver may handle non rmi devices on composite USB devices. Callbacks need to make sure that the current device is a RMI device before calling RMI specific functions. Most callbacks already have this check, but this patch adds checks to the remaining callbacks.

---
This is the patch which hopefully will address the X1 tablet dock freeze:
http://www.spinics.net/lists/linux-input/msg53582.html

I was not able to test on a composite USB device so I have not tested confirmed this will fix the reported issues. But, based on the description I think it will. I also added a check for rmi_raw_event() since it could be possible that another hid device using one of the same report IDs as an RMI device could result in calling into unitialized RMI functions. It was also the only callbacl left not checking the RMI_DEVICE flag. I wonder if this explains the attach crash.

Anyway, I would appriciate it if Hendrik or someone else with the device could test this patch to confirm it fixes the reported behavior.

Quoted 7 lines
Quoted 2 lines
Quoted 1 line

Shouldn't rmi_hid_reset() also get the same check?

I think so as well.

Since rmi_hid_reset() is only called from with in the RMI4 driver I didn't think that it needed a check. All of the functions set in struct hid_driver should  now check the RMI_DEVICE flag before calling into the RMI4 driver. But, if I am missing something we can add additional checks.

Oh, right, you are correct. I didn't paid enough attention and overlooked the fact that this function was set in struct rmi_transport_ops only.

Given Hendrick's Tested-by came in as well (thanks for the quick tests!), this is:

Cheers,
Benjamin

Quoted 16 lines

Thanks,
Andrew

Quoted 11 lines
Quoted 3 lines

From what I can see, even if the patch doesn't fix the immediate issue,
such a patch should definitively go in as those checks are clearly missing.

Agreed; however I'd like to get Hendrik's Tested-by: if possible in case this really fixes the issue, so I am not merging it right away.

Hendrik, are you by any chance able to test this patch in a reasonable timeframe please?

Thanks!

maintainer
#6 lore raw
In reply to Hendrik Langer
Quoted 5 lines · Hendrik Langer

Confirmed, the patch fixes the probem for me.
All freezes/Oops and rmi or input related error messages are gone. Even keyboard and touchpad are working now!

Thanks a lot for confirmation.

Now queued in for-4.14/upstream-fixes.

Signature · 2 lines
Jiri Kosina
SUSE Labs