f2c60e
From ef14a4bf0910d06c7e202552914028d4956809cb Mon Sep 17 00:00:00 2001
f2c60e
From: Andrew Duggan <aduggan@synaptics.com>
f2c60e
Date: Tue, 17 Oct 2017 18:37:36 -0700
f2c60e
Subject: [PATCH] HID: rmi: Check that a device is a RMI device before calling
f2c60e
 RMI functions
f2c60e
f2c60e
The hid-rmi driver may handle non rmi devices on composite USB devices.
f2c60e
Callbacks need to make sure that the current device is a RMI device before
f2c60e
calling RMI specific functions. Most callbacks already have this check, but
f2c60e
this patch adds checks to the remaining callbacks.
f2c60e
f2c60e
Reported-by: Hendrik Langer <hendrik.langer@gmx.de>
f2c60e
Tested-by: Hendrik Langer <hendrik.langer@gmx.de>
f2c60e
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
f2c60e
Signed-off-by: Andrew Duggan <aduggan@synaptics.com>
f2c60e
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
f2c60e
---
f2c60e
 drivers/hid/hid-rmi.c | 13 ++++++++++---
f2c60e
 1 file changed, 10 insertions(+), 3 deletions(-)
f2c60e
f2c60e
diff --git a/drivers/hid/hid-rmi.c b/drivers/hid/hid-rmi.c
f2c60e
index ef241d66562e..0f43c4292685 100644
f2c60e
--- a/drivers/hid/hid-rmi.c
f2c60e
+++ b/drivers/hid/hid-rmi.c
f2c60e
@@ -368,6 +368,11 @@ static int rmi_check_sanity(struct hid_device *hdev, u8 *data, int size)
f2c60e
 static int rmi_raw_event(struct hid_device *hdev,
f2c60e
 		struct hid_report *report, u8 *data, int size)
f2c60e
 {
f2c60e
+	struct rmi_data *hdata = hid_get_drvdata(hdev);
f2c60e
+
f2c60e
+	if (!(hdata->device_flags & RMI_DEVICE))
f2c60e
+		return 0;
f2c60e
+
f2c60e
 	size = rmi_check_sanity(hdev, data, size);
f2c60e
 	if (size < 2)
f2c60e
 		return 0;
f2c60e
@@ -713,9 +718,11 @@ static void rmi_remove(struct hid_device *hdev)
f2c60e
 {
f2c60e
 	struct rmi_data *hdata = hid_get_drvdata(hdev);
f2c60e
 
f2c60e
-	clear_bit(RMI_STARTED, &hdata->flags);
f2c60e
-	cancel_work_sync(&hdata->reset_work);
f2c60e
-	rmi_unregister_transport_device(&hdata->xport);
f2c60e
+	if (hdata->device_flags & RMI_DEVICE) {
f2c60e
+		clear_bit(RMI_STARTED, &hdata->flags);
f2c60e
+		cancel_work_sync(&hdata->reset_work);
f2c60e
+		rmi_unregister_transport_device(&hdata->xport);
f2c60e
+	}
f2c60e
 
f2c60e
 	hid_hw_stop(hdev);
f2c60e
 }
f2c60e
-- 
f2c60e
2.14.3
f2c60e